apiclient

package
v1.9.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 30, 2023 License: Apache-2.0, BSD-2-Clause, BSD-3-Clause, + 8 more Imports: 41 Imported by: 2

Documentation

Index

Constants

View Source
const (
	// APICallRetryInterval defines how long should wait before retrying a failed API operation
	APICallRetryInterval = 500 * time.Millisecond
	// PatchNodeTimeout specifies how long should wait for applying the label and taint on the master before timing out
	PatchNodeTimeout = 2 * time.Minute
	// UpdateNodeTimeout specifies how long should wait for updating node with the initial remote configuration of kubelet before timing out
	UpdateNodeTimeout = 2 * time.Minute
	// LabelHostname specifies the label in node.
	LabelHostname = "kubernetes.io/hostname"
	// LabelTopologyZone represents a logical failure domain. It is common for Kubernetes clusters to span multiple zones for increased availability.
	LabelTopologyZone = "topology.kubernetes.io/zone"
	// LabelMachineIPV4 specifies the label in node.
	LabelMachineIPV4 PlatformLabel = "platform.tkestack.io/machine-ip"
	// LabelMachineIPV6Head specifies the label in node.
	LabelMachineIPV6Head PlatformLabel = "platform.tkestack.io/machine-ipv6-head"
	// LabelMachineIPV6Tail specifies the label in node.
	LabelMachineIPV6Tail PlatformLabel = "platform.tkestack.io/machine-ipv6-tail"
	// LabelASNForCilium specifies the label in node when enable Cilium.
	LabelASNCilium PlatformLabel = "infra.tce.io/as"
	// LabelSwitchIPForCilium specifies the label in node when enable Cilium.
	LabelSwitchIPCilium PlatformLabel = "infra.tce.io/switch-ip"
)

Variables

This section is empty.

Functions

func CheckAPIHealthz

func CheckAPIHealthz(ctx context.Context, client rest.Interface) bool

CheckAPIHealthz check healthz

func CheckClusterVersion added in v1.3.1

func CheckClusterVersion(client kubernetes.Interface, versionConstraint string) (bool, error)

func CheckDaemonset

func CheckDaemonset(ctx context.Context, client kubernetes.Interface, namespace string, name string) (bool, error)

CheckDaemonset check daemonset current replicas is equal to desired and all pods are running

func CheckDeployment

func CheckDeployment(ctx context.Context, client kubernetes.Interface, namespace string, name string) (bool, error)

CheckDeployment check Deployment current replicas is equal to desired and all pods are running

func CheckPodReady added in v1.3.1

func CheckPodReady(ctx context.Context, client kubernetes.Interface, namespace string, option metav1.ListOptions) (bool, error)

CheckPodReady checks if the pod is ready.

func CheckPodReadyWithLabel added in v1.3.1

func CheckPodReadyWithLabel(ctx context.Context, client kubernetes.Interface, namespace string, labelSelector string) (bool, error)

CheckPodReadyWithLabel checks if the pod is ready with label.

func CheckPodWithPredicate added in v1.3.1

func CheckPodWithPredicate(ctx context.Context, client kubernetes.Interface, namespace string, option metav1.ListOptions, predicate func(*corev1.Pod) bool) (bool, error)

CheckPodWithPredicate check pod with specify predicate.

func CheckStatefulSet

func CheckStatefulSet(ctx context.Context, client kubernetes.Interface, namespace string, name string) (bool, error)

CheckStatefulSet check StatefulSet current replicas is equal to desired and all pods are running

func CheckVersion added in v1.3.1

func CheckVersion(version string, versionConstraint string) (bool, error)

func CheckVersionOrDie added in v1.3.1

func CheckVersionOrDie(version string, versionConstraint string) bool

func ClusterVersionIsAfter122 added in v1.9.1

func ClusterVersionIsAfter122(client kubernetes.Interface) bool

func ClusterVersionIsBefore116 added in v1.3.1

func ClusterVersionIsBefore116(client kubernetes.Interface) bool

func ClusterVersionIsBefore118 added in v1.6.0

func ClusterVersionIsBefore118(client kubernetes.Interface) bool

func ClusterVersionIsBefore19 added in v1.3.1

func ClusterVersionIsBefore19(client kubernetes.Interface) bool

func CreateAsResourceWithFile added in v1.9.0

func CreateAsResourceWithFile(ctx context.Context, client kubernetes.Interface, aaClient aaclientset.Interface, filename string, option interface{}) error

CreateAsResourceWithFile create k8s and apiextensions-apiserver resource with file

func CreateKAResourceWithFile added in v1.3.1

func CreateKAResourceWithFile(ctx context.Context, client kubernetes.Interface, kaClient kubeaggregator.Interface, filename string, option interface{}) error

CreateKAResourceWithFile create k8s and kube-aggregator resource with file

func CreateOrRetainConfigMap

func CreateOrRetainConfigMap(ctx context.Context, client clientset.Interface, cm *corev1.ConfigMap, configMapName string) error

CreateOrRetainConfigMap creates a ConfigMap if the target resource doesn't exist. If the resource exists already, this function will retain the resource instead.

func CreateOrUpdateAPIService added in v1.3.1

func CreateOrUpdateAPIService(ctx context.Context, client kubeaggregatorclientset.Interface, as *apiregistrationv1.APIService) error

CreateOrUpdateAPIService creates a APIService if the target resource doesn't exist. If the resource exists already, this function will update the resource instead.

func CreateOrUpdateClusterRole

func CreateOrUpdateClusterRole(ctx context.Context, client clientset.Interface, clusterRole *rbac.ClusterRole) error

CreateOrUpdateClusterRole creates a ClusterRole if the target resource doesn't exist. If the resource exists already, this function will update the resource instead.

func CreateOrUpdateClusterRoleBinding

func CreateOrUpdateClusterRoleBinding(ctx context.Context, client clientset.Interface, clusterRoleBinding *rbac.ClusterRoleBinding) error

CreateOrUpdateClusterRoleBinding creates a ClusterRoleBinding if the target resource doesn't exist. If the resource exists already, this function will update the resource instead.

func CreateOrUpdateConfigMap

func CreateOrUpdateConfigMap(ctx context.Context, client clientset.Interface, cm *corev1.ConfigMap) error

CreateOrUpdateConfigMap creates a ConfigMap if the target resource doesn't exist. If the resource exists already, this function will update the resource instead.

func CreateOrUpdateConfigMapFromFile

func CreateOrUpdateConfigMapFromFile(ctx context.Context, client clientset.Interface, cm *corev1.ConfigMap, pattern string) error

CreateOrUpdateConfigMapFromFile like kubectl apply configmap --from-file

func CreateOrUpdateCronJob

func CreateOrUpdateCronJob(ctx context.Context, client clientset.Interface, cronjob *batchv1beta1.CronJob) error

CreateOrUpdateCronJob creates a Job if the target resource doesn't exist. If the resource exists already, this function will update

func CreateOrUpdateCustomResourceDefinition added in v1.9.0

func CreateOrUpdateCustomResourceDefinition(ctx context.Context, client aaclientset.Interface, crd *apiextensionsv1.CustomResourceDefinition) error

CreateOrUpdateCustomResourceDefinition creates a CustomResourceDefinition if the target resource doesn't exist. If the resource exists already, this function will update the resource instead.

func CreateOrUpdateDaemonSet

func CreateOrUpdateDaemonSet(ctx context.Context, client clientset.Interface, ds *apps.DaemonSet) error

CreateOrUpdateDaemonSet creates a DaemonSet if the target resource doesn't exist. If the resource exists already, this function will update the resource instead.

func CreateOrUpdateDeployment

func CreateOrUpdateDeployment(ctx context.Context, client clientset.Interface, deploy *apps.Deployment) error

CreateOrUpdateDeployment creates a Deployment if the target resource doesn't exist. If the resource exists already, this function will update the resource instead.

func CreateOrUpdateDeploymentExtensionsV1beta1

func CreateOrUpdateDeploymentExtensionsV1beta1(ctx context.Context, client clientset.Interface, deploy *extensionsv1beta1.Deployment) error

CreateOrUpdateDeploymentExtensionsV1beta1 creates a ExtensionsV1beta1 Deployment if the target resource doesn't exist. If the resource exists already, this function will update the resource instead.

func CreateOrUpdateEndpoints

func CreateOrUpdateEndpoints(ctx context.Context, client clientset.Interface, ep *corev1.Endpoints) error

CreateOrUpdateEndpoints creates a Endpoints if the target resource doesn't exist. If the resource exists already, this function will update the resource instead.

func CreateOrUpdateIngress

func CreateOrUpdateIngress(ctx context.Context, client clientset.Interface, ing *extensionsv1beta1.Ingress) error

CreateOrUpdateIngress creates a Ingress if the target resource doesn't exist. If the resource exists already, this function will update the resource instead.

func CreateOrUpdateJob

func CreateOrUpdateJob(ctx context.Context, client clientset.Interface, job *batchv1.Job) error

CreateOrUpdateJob creates a Job if the target resource doesn't exist. If the resource exists already, this function will update

func CreateOrUpdateMutatingWebhookConfiguration added in v1.2.5

func CreateOrUpdateMutatingWebhookConfiguration(ctx context.Context, client clientset.Interface, obj *admissionv1beta1.MutatingWebhookConfiguration) error

CreateOrUpdateMutatingWebhookConfiguration creates a MutatingWebhookConfigurations if the target resource doesn't exist. If the resource exists already, this function will update the resource instead.

func CreateOrUpdateNamespace

func CreateOrUpdateNamespace(ctx context.Context, client clientset.Interface, ns *corev1.Namespace) error

CreateOrUpdateNamespace creates a namespace if the target resource doesn't exist. If the resource exists already, this function will update the resource instead.

func CreateOrUpdatePod added in v1.3.1

func CreateOrUpdatePod(ctx context.Context, client clientset.Interface, pod *corev1.Pod) error

CreateOrUpdateService creates a service if the target resource doesn't exist. If the resource exists already, this function will update the resource instead.

func CreateOrUpdateRole

func CreateOrUpdateRole(ctx context.Context, client clientset.Interface, role *rbac.Role) error

CreateOrUpdateRole creates a Role if the target resource doesn't exist. If the resource exists already, this function will update the resource instead.

func CreateOrUpdateRoleBinding

func CreateOrUpdateRoleBinding(ctx context.Context, client clientset.Interface, roleBinding *rbac.RoleBinding) error

CreateOrUpdateRoleBinding creates a RoleBinding if the target resource doesn't exist. If the resource exists already, this function will update the resource instead.

func CreateOrUpdateSecret

func CreateOrUpdateSecret(ctx context.Context, client clientset.Interface, secret *corev1.Secret) error

CreateOrUpdateSecret creates a Secret if the target resource doesn't exist. If the resource exists already, this function will update the resource instead.

func CreateOrUpdateService

func CreateOrUpdateService(ctx context.Context, client clientset.Interface, svc *corev1.Service) error

CreateOrUpdateService creates a service if the target resource doesn't exist. If the resource exists already, this function will update the resource instead.

func CreateOrUpdateServiceAccount

func CreateOrUpdateServiceAccount(ctx context.Context, client clientset.Interface, sa *corev1.ServiceAccount) error

CreateOrUpdateServiceAccount creates a ServiceAccount if the target resource doesn't exist. If the resource exists already, this function will update the resource instead.

func CreateOrUpdateStatefulSet

func CreateOrUpdateStatefulSet(ctx context.Context, client clientset.Interface, sts *apps.StatefulSet) error

CreateOrUpdateStatefulSet creates a statefulSet if the target resource doesn't exist. If the resource exists already, this function will update the resource instead.

func CreateOrUpdateValidatingWebhookConfiguration added in v1.2.5

func CreateOrUpdateValidatingWebhookConfiguration(ctx context.Context, client clientset.Interface, obj *admissionv1beta1.ValidatingWebhookConfiguration) error

CreateOrUpdateValidatingWebhookConfiguration creates a ValidatingWebhookConfigurations if the target resource doesn't exist. If the resource exists already, this function will update the resource instead.

func CreateResourceWiteContent added in v1.4.0

func CreateResourceWiteContent(ctx context.Context, client kubernetes.Interface, content string,
	option interface{}) error

func CreateResourceWithDir

func CreateResourceWithDir(ctx context.Context, client kubernetes.Interface, pattern string, option interface{}) error

CreateResourceWithDir create k8s resource with dir

func CreateResourceWithFile

func CreateResourceWithFile(ctx context.Context, client kubernetes.Interface, filename string, option interface{}) error

CreateResourceWithFile create k8s resource with file

func DeleteClusterRoleBinding

func DeleteClusterRoleBinding(ctx context.Context, client clientset.Interface, crbName string) error

DeleteClusterRoleBinding delete a clusterrolebinding

func DeleteDaemonSetForeground

func DeleteDaemonSetForeground(ctx context.Context, client clientset.Interface, namespace, name string) error

DeleteDaemonSetForeground deletes the specified DaemonSet in foreground mode; i.e. it blocks until/makes sure all the managed Pods are deleted

func DeleteDeployment

func DeleteDeployment(ctx context.Context, client clientset.Interface, namespace string, deployName string, isExtensions bool, labelSelector metav1.LabelSelector) error

func DeleteDeploymentForeground

func DeleteDeploymentForeground(ctx context.Context, client clientset.Interface, namespace, name string) error

DeleteDeploymentForeground deletes the specified Deployment in foreground mode; i.e. it blocks until/makes sure all the managed Pods are deleted

func DeleteReplicaSetApp

func DeleteReplicaSetApp(ctx context.Context, client clientset.Interface, options metav1.ListOptions) error

DeleteReplicaSetApp delete the replicaset and pod additionally for deployment app with extension group

func DeleteService

func DeleteService(ctx context.Context, client clientset.Interface, namespace string, svcName string) error

DeleteService delete a service

func DeleteServiceAccounts

func DeleteServiceAccounts(ctx context.Context, client clientset.Interface, namespace string, svcAccountName string) error

DeleteServiceAccounts delete a serviceAccount

func GetClientset

func GetClientset(masterEndpoint string, token string, caCert []byte) (*kubernetes.Clientset, error)

GetClientset return clientset

func GetClusterRoleBinding

func GetClusterRoleBinding(ctx context.Context, client clientset.Interface, name string) (*rbac.ClusterRoleBinding, error)

GetClusterRoleBinding get a cluster role binding.

func GetClusterVersion added in v1.3.1

func GetClusterVersion(client kubernetes.Interface) (string, error)

func GetNodeByMachineIP added in v1.4.0

func GetNodeByMachineIP(ctx context.Context, client clientset.Interface, ip string) (*corev1.Node, error)

GetNodeByMachineIP get node by machine ip.

func GetNodeIPV6Label added in v1.6.0

func GetNodeIPV6Label(ip string) string

GetNodeIPV6Label split ip v6 address to head and tail ensure lable value less than 63 character, since k8s lable doesn't support ":" so that replace to "a", then return the consolidated label string Todo: add more check and corner case handle here later

func GetService

func GetService(ctx context.Context, client clientset.Interface, namespace string, name string) (*corev1.Service, error)

GetService get a service.

func GetServiceAccount

func GetServiceAccount(ctx context.Context, client clientset.Interface, namespace string, name string) (*corev1.ServiceAccount, error)

GetServiceAccount get a service.

func IsPodReady

func IsPodReady(pod *corev1.Pod) bool

IsPodReady returns true if a pod is ready; false otherwise.

func MarkNode added in v1.2.5

func MarkNode(ctx context.Context, client clientset.Interface, nodeName string, labels map[string]string, taints []corev1.Taint) error

MarkNode mark node by adding labels and taints

func PatchNode

func PatchNode(ctx context.Context, client clientset.Interface, nodeName string, patchFn func(*corev1.Node)) error

PatchNode tries to patch a node using patchFn for the actual mutating logic. Retries are provided by the wait package.

func PatchNodeOnce

func PatchNodeOnce(ctx context.Context, client clientset.Interface, nodeName string, patchFn func(*corev1.Node)) func() (bool, error)

PatchNodeOnce executes patchFn on the node object found by the node name. This is a condition function meant to be used with wait.Poll. false, nil implies it is safe to try again, an error indicates no more tries should be made and true indicates success.

func PullImageWithPod added in v1.3.1

func PullImageWithPod(ctx context.Context, clientset kubernetes.Interface, pod *corev1.Pod) error

PullImageWithPod pull image for pod

func RemoveNodeTaints added in v1.3.1

func RemoveNodeTaints(ctx context.Context, client clientset.Interface, nodeName string, taints []corev1.Taint) error

RemoveNodeTaints remove taints from existed node taints

Types

type PlatformLabel added in v1.4.0

type PlatformLabel string

PlatformLabel represents the type of platform.tkestack.io related label.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL