apiclient

package
v1.12.2 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2025 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// APICallRetryInterval defines how long kubeadm should wait before retrying a failed API operation
	APICallRetryInterval = 500 * time.Millisecond
)

Variables

This section is empty.

Functions

func CreateCustomResourceDefinitionIfNeed

func CreateCustomResourceDefinitionIfNeed(client *crdsclient.Clientset, obj *apiextensionsv1.CustomResourceDefinition) error

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

func CreateNamespace

func CreateNamespace(client clientset.Interface, ns *corev1.Namespace) error

CreateNamespace creates given namespace when the namespace is not existing.

func CreateOrUpdateAPIService

func CreateOrUpdateAPIService(apiRegistrationClient aggregator.Interface, apiservice *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 added in v1.7.0

func CreateOrUpdateClusterRole(client clientset.Interface, clusterrole *rbacv1.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 added in v1.12.0

func CreateOrUpdateClusterRoleBinding(client clientset.Interface, clusterrolebinding *rbacv1.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 CreateOrUpdateDeployment

func CreateOrUpdateDeployment(client clientset.Interface, deployment *appsv1.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 CreateOrUpdateMutatingWebhookConfiguration

func CreateOrUpdateMutatingWebhookConfiguration(client clientset.Interface, mwc *admissionregistrationv1.MutatingWebhookConfiguration) error

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

func CreateOrUpdateSecret

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

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

func CreateOrUpdateService

func CreateOrUpdateService(client clientset.Interface, service *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 CreateOrUpdateStatefulSet

func CreateOrUpdateStatefulSet(client clientset.Interface, statefulSet *appsv1.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

func CreateOrUpdateValidatingWebhookConfiguration(client clientset.Interface, vwc *admissionregistrationv1.ValidatingWebhookConfiguration) error

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

func CreatePods added in v1.12.0

func CreatePods(client clientset.Interface, namespace string, componentName string, replicaCount int32, labels map[string]string, markRunningState bool) ([]*corev1.Pod, error)

CreatePods creates a specified number of pods in the given namespace with the provided component name and optional labels. It uses a Kubernetes client to interact with the API and can mark the pods as running if the `markRunningState` flag is set.

Parameters:

  • client: Kubernetes client interface for API requests.
  • namespace: Namespace for pod creation.
  • componentName: Base name for the pods and their containers.
  • replicaCount: Number of pods to create.
  • labels: Labels to apply to the pods.
  • markRunningState: If true, updates the pods' status to running.

Returns:

  • A slice of pointers to corev1.Pod representing the created pods.
  • An error if pod creation fails.

func DeleteDeploymentIfHasLabels

func DeleteDeploymentIfHasLabels(client clientset.Interface, name, namespace string, ls labels.Set) error

DeleteDeploymentIfHasLabels deletes a Deployment that exists the given labels.

func DeleteSecretIfHasLabels

func DeleteSecretIfHasLabels(client clientset.Interface, name, namespace string, ls labels.Set) error

DeleteSecretIfHasLabels deletes a secret that exists the given labels.

func DeleteServiceIfHasLabels

func DeleteServiceIfHasLabels(client clientset.Interface, name, namespace string, ls labels.Set) error

DeleteServiceIfHasLabels deletes a service that exists the given labels.

func DeleteStatefulSetIfHasLabels

func DeleteStatefulSetIfHasLabels(client clientset.Interface, name, namespace string, ls labels.Set) error

DeleteStatefulSetIfHasLabels deletes a StatefulSet that exists the given labels.

func GetService

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

GetService returns service resource with specified name and namespace.

func NewAPIRegistrationClient

func NewAPIRegistrationClient(c *rest.Config) (aggregator.Interface, error)

NewAPIRegistrationClient is to create an apiregistration ClientSet

func NewCRDsClient

func NewCRDsClient(c *rest.Config) (*crdsclient.Clientset, error)

NewCRDsClient is to create a Clientset

func PatchCustomResourceDefinition

func PatchCustomResourceDefinition(client *crdsclient.Clientset, name string, data []byte) error

PatchCustomResourceDefinition patches a crd resource.

func TryRunCommand

func TryRunCommand(f func() error, failureThreshold int) error

TryRunCommand runs a function a maximum of failureThreshold times, and retries on error. If failureThreshold is hit; the last error is returned.

func UpdatePodStatus added in v1.12.0

func UpdatePodStatus(client clientset.Interface, pod *corev1.Pod) error

UpdatePodStatus updates the status of a pod to PodRunning and sets the PodReady condition.

Types

type KarmadaWaiter

type KarmadaWaiter struct {
	// contains filtered or unexported fields
}

KarmadaWaiter is an implementation of Waiter that is backed by a Kubernetes client

func (*KarmadaWaiter) SetTimeout

func (w *KarmadaWaiter) SetTimeout(timeout time.Duration)

SetTimeout adjusts the timeout to the specified duration

func (*KarmadaWaiter) WaitForAPI

func (w *KarmadaWaiter) WaitForAPI() error

WaitForAPI waits for the API Server's /healthz endpoint to report "ok"

func (*KarmadaWaiter) WaitForAPIService

func (w *KarmadaWaiter) WaitForAPIService(name string) error

WaitForAPIService waits for the APIService condition to become "true"

func (*KarmadaWaiter) WaitForPods

func (w *KarmadaWaiter) WaitForPods(label, namespace string) error

WaitForPods will lookup pods with the given label and wait until they are all reporting status as running.

func (*KarmadaWaiter) WaitForSomePods

func (w *KarmadaWaiter) WaitForSomePods(label, namespace string, podNum int32) error

WaitForSomePods lookup pods with the given label and wait until desired number of pods reporting status as running.

type MockDiscovery added in v1.12.0

type MockDiscovery struct {
	discovery.DiscoveryInterface
	RESTClientConnector rest.Interface
}

MockDiscovery is a mock implementation of DiscoveryInterface.

func (*MockDiscovery) RESTClient added in v1.12.0

func (m *MockDiscovery) RESTClient() rest.Interface

RESTClient returns a restClientConnector that is used to communicate with API server by this client implementation.

type MockK8SRESTClient added in v1.12.0

type MockK8SRESTClient struct {
	clientset.Interface
	RESTClientConnector rest.Interface
}

MockK8SRESTClient is a struct that implements clientset.Interface.

func (*MockK8SRESTClient) Discovery added in v1.12.0

Discovery returns a mocked discovery interface.

type Waiter

type Waiter interface {
	// WaitForAPI waits for the API Server's /healthz endpoint to become "ok"
	WaitForAPI() error
	// WaitForAPIService waits for the APIService condition to become "true"
	WaitForAPIService(name string) error
	// WaitForPods waits for Pods in the namespace to become Ready
	WaitForPods(label, namespace string) error
	// WaitForSomePods waits for the specified number of Pods in the namespace to become Ready
	WaitForSomePods(label, namespace string, podNum int32) error
	// SetTimeout adjusts the timeout to the specified duration
	SetTimeout(timeout time.Duration)
}

Waiter is an interface for waiting for criteria in Karmada to happen

func NewKarmadaWaiter

func NewKarmadaWaiter(config *rest.Config, client clientset.Interface, timeout time.Duration) Waiter

NewKarmadaWaiter returns a karmada waiter, the rest config is to create crd client or aggregate client.

Jump to

Keyboard shortcuts

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