apiclient

package
v1.33.0 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2025 License: Apache-2.0 Imports: 36 Imported by: 403

Documentation

Overview

Package apiclient contains wrapping logic for Kubernetes API clients.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateOrMutate added in v1.33.0

func CreateOrMutate[T kubernetesObject](client kubernetesInterface[T], obj T, mutator objectMutator[T]) error

CreateOrMutate tries to create the provided object. If the resource exists already, the latest version will be fetched from the cluster and mutator callback will be called on it, then an Update of the mutated object will be performed. This function is resilient to conflicts, and a retry will be issued if the object was modified on the server between the refresh and the update (while the mutation was taking place).

func CreateOrRetain added in v1.33.0

func CreateOrRetain[T kubernetesObject](client kubernetesInterface[T], obj T, name string) error

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

func CreateOrUpdate added in v1.33.0

func CreateOrUpdate[T kubernetesObject](client kubernetesInterface[T], obj T) error

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

func GetConfigMapWithShortRetry added in v1.30.0

func GetConfigMapWithShortRetry(client clientset.Interface, namespace, name string) (*v1.ConfigMap, error)

GetConfigMapWithShortRetry tries to retrieve a ConfigMap using the given client, retrying for a short time if it gets an unexpected error. The main usage of this function is in areas of the code that fallback to a default ConfigMap value in case the one from the API cannot be quickly obtained.

func PatchNode added in v1.11.0

func PatchNode(client clientset.Interface, nodeName string, patchFn func(*v1.Node)) error

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

func PatchNodeOnce added in v1.13.0

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

PatchNodeOnce executes patchFn on the node object found by the node name.

func PrintControlPlaneErrorHelpScreen added in v1.33.0

func PrintControlPlaneErrorHelpScreen(outputWriter io.Writer, criSocket string)

PrintControlPlaneErrorHelpScreen prints help text on wait ControlPlane components errors.

func PrintKubeletErrorHelpScreen added in v1.33.0

func PrintKubeletErrorHelpScreen(outputWriter io.Writer)

PrintKubeletErrorHelpScreen prints help text on kubelet errors.

Types

type DryRun added in v1.32.0

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

DryRun is responsible for performing verbose dry-run operations with a set of different API clients. Any REST action that reaches the FakeClient() of a DryRun will be processed as follows by the fake client reactor chain:

  • Log the action.
  • If the action is not GET or LIST just use the fake client store to write it, unless a user reactor was added with PrependReactor() or AppendReactor().
  • Attempt to GET or LIST using the real dynamic client.
  • If the above fails try to GET or LIST the object from the fake client store, unless a user reactor was added with PrependReactor() or AppendReactor().

func NewDryRun added in v1.32.0

func NewDryRun() *DryRun

NewDryRun creates a new DryRun object that only has a fake client.

func (*DryRun) AppendReactor added in v1.32.0

func (d *DryRun) AppendReactor(r *testing.SimpleReactor) *DryRun

AppendReactor appends a new reactor in the fake client ReactorChain at position len-2. Keeps position len-1 for the default fake client reactor. [ log, rest of the chain... , r, default fake client reactor ]

func (*DryRun) Client added in v1.32.0

func (d *DryRun) Client() clientset.Interface

Client returns the clientset for this DryRun.

func (*DryRun) DeleteBootstrapTokenReactor added in v1.32.0

func (d *DryRun) DeleteBootstrapTokenReactor() *testing.SimpleReactor

DeleteBootstrapTokenReactor returns a reactor that handles the DELETE action of bootstrap token Secret.

func (*DryRun) DynamicClient added in v1.32.0

func (d *DryRun) DynamicClient() dynamic.Interface

DynamicClient returns the dynamic client for this DryRun.

func (*DryRun) FakeClient added in v1.32.0

func (d *DryRun) FakeClient() clientset.Interface

FakeClient returns the fake client for this DryRun.

func (*DryRun) GetClusterInfoReactor added in v1.32.0

func (d *DryRun) GetClusterInfoReactor() *testing.SimpleReactor

GetClusterInfoReactor returns a reactor that handles the GET action of the "cluster-info" ConfigMap used during node bootstrap.

func (*DryRun) GetCoreDNSConfigReactor added in v1.32.0

func (d *DryRun) GetCoreDNSConfigReactor() *testing.SimpleReactor

GetCoreDNSConfigReactor returns a reactor that handles the GET action of the "coredns" ConfigMap.

func (*DryRun) GetKubeProxyConfigReactor added in v1.32.0

func (d *DryRun) GetKubeProxyConfigReactor() *testing.SimpleReactor

GetKubeProxyConfigReactor returns a reactor that handles the GET action of the "kube-proxy" ConfigMap.

func (*DryRun) GetKubeadmCertsReactor added in v1.32.0

func (d *DryRun) GetKubeadmCertsReactor() *testing.SimpleReactor

GetKubeadmCertsReactor returns a reactor that handles the GET action of the "kubeadm-certs" Secret.

func (*DryRun) GetKubeadmConfigReactor added in v1.32.0

func (d *DryRun) GetKubeadmConfigReactor() *testing.SimpleReactor

GetKubeadmConfigReactor returns a reactor that handles the GET action of the "kubeadm-config" ConfigMap.

func (*DryRun) GetKubeletConfigReactor added in v1.32.0

func (d *DryRun) GetKubeletConfigReactor() *testing.SimpleReactor

GetKubeletConfigReactor returns a reactor that handles the GET action of the "kubelet-config" ConfigMap.

func (*DryRun) GetNodeReactor added in v1.32.0

func (d *DryRun) GetNodeReactor() *testing.SimpleReactor

GetNodeReactor returns a reactor that handles the generic GET action of Node objects.

func (*DryRun) HealthCheckJobReactor added in v1.32.0

func (d *DryRun) HealthCheckJobReactor() *testing.SimpleReactor

HealthCheckJobReactor returns a reactor that handles the GET action for the Job object used for the "CreateJob" upgrade preflight check.

func (*DryRun) ListDeploymentsReactor added in v1.32.0

func (d *DryRun) ListDeploymentsReactor() *testing.SimpleReactor

ListDeploymentsReactor returns a reactor that handles the LIST action on deployments.

func (*DryRun) ListPodsReactor added in v1.32.0

func (d *DryRun) ListPodsReactor(nodeName string) *testing.SimpleReactor

ListPodsReactor returns a reactor that handles the LIST action on pods.

func (*DryRun) LogAction added in v1.32.0

func (d *DryRun) LogAction(action testing.Action)

LogAction logs details about an action, such as name, object and resource.

func (*DryRun) LogObject added in v1.32.0

func (d *DryRun) LogObject(obj runtime.Object, gv schema.GroupVersion)

LogObject marshals the object and then prints it to the io.Writer of this DryRun.

func (*DryRun) PatchNodeReactor added in v1.32.0

func (d *DryRun) PatchNodeReactor() *testing.SimpleReactor

PatchNodeReactor returns a reactor that handles the generic PATCH action on Node objects.

func (*DryRun) PrependReactor added in v1.32.0

func (d *DryRun) PrependReactor(r *testing.SimpleReactor) *DryRun

PrependReactor prepends a new reactor in the fake client ReactorChain at position 1. Keeps position 0 for the log reactor: [ log, r, ... rest of the chain, default fake client reactor ]

func (*DryRun) WithDefaultMarshalFunction added in v1.32.0

func (d *DryRun) WithDefaultMarshalFunction() *DryRun

WithDefaultMarshalFunction sets the DryRun marshal function to the default one.

func (*DryRun) WithKubeConfig added in v1.32.0

func (d *DryRun) WithKubeConfig(config *clientcmdapi.Config) error

WithKubeConfig takes a Config (kubeconfig) and creates real clientset and dynamic client.

func (*DryRun) WithKubeConfigFile added in v1.32.0

func (d *DryRun) WithKubeConfigFile(file string) error

WithKubeConfigFile takes a file path and creates real clientset and dynamic clients.

func (*DryRun) WithMarshalFunction added in v1.32.0

func (d *DryRun) WithMarshalFunction(f func(runtime.Object, schema.GroupVersion) ([]byte, error)) *DryRun

WithMarshalFunction sets the DryRun marshal function.

func (*DryRun) WithRestConfig added in v1.32.0

func (d *DryRun) WithRestConfig(config *rest.Config) error

WithRestConfig takes a rest Config and creates real clientset and dynamic clients.

func (*DryRun) WithWriter added in v1.32.0

func (d *DryRun) WithWriter(w io.Writer) *DryRun

WithWriter sets the io.Writer used for printing by the DryRun.

type KubeWaiter

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

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

func (*KubeWaiter) SetTimeout

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

SetTimeout adjusts the timeout to the specified duration

func (*KubeWaiter) WaitForAPI

func (w *KubeWaiter) WaitForAPI() error

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

func (*KubeWaiter) WaitForControlPlaneComponents added in v1.30.0

func (w *KubeWaiter) WaitForControlPlaneComponents(podMap map[string]*v1.Pod, apiSeverAddress string) error

WaitForControlPlaneComponents waits for all control plane components to report "ok".

func (*KubeWaiter) WaitForKubelet added in v1.30.0

func (w *KubeWaiter) WaitForKubelet(healthzAddress string, healthzPort int32) error

WaitForKubelet blocks until the kubelet /healthz endpoint returns 'ok'.

func (*KubeWaiter) WaitForPodsWithLabel

func (w *KubeWaiter) WaitForPodsWithLabel(kvLabel string) error

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

func (*KubeWaiter) WaitForStaticPodControlPlaneHashes

func (w *KubeWaiter) WaitForStaticPodControlPlaneHashes(nodeName string) (map[string]string, error)

WaitForStaticPodControlPlaneHashes blocks until it timeouts or gets a hash map for all components and their Static Pods

func (*KubeWaiter) WaitForStaticPodHashChange added in v1.10.2

func (w *KubeWaiter) WaitForStaticPodHashChange(nodeName, component, previousHash string) error

WaitForStaticPodHashChange blocks until it timeouts or notices that the Mirror Pod (for the Static Pod, respectively) has changed This implicitly means this function blocks until the kubelet has restarted the Static Pod in question

func (*KubeWaiter) WaitForStaticPodSingleHash added in v1.9.0

func (w *KubeWaiter) WaitForStaticPodSingleHash(nodeName string, component string) (string, error)

WaitForStaticPodSingleHash blocks until it timeouts or gets a hash for a single component and its Static Pod

type Waiter

type Waiter interface {
	// WaitForControlPlaneComponents waits for all control plane components to be ready.
	WaitForControlPlaneComponents(podMap map[string]*v1.Pod, apiServerAddress string) error
	// WaitForAPI waits for the API Server's /healthz endpoint to become "ok"
	// TODO: remove WaitForAPI once WaitForAllControlPlaneComponents goes GA:
	// https://github.com/kubernetes/kubeadm/issues/2907
	WaitForAPI() error
	// WaitForPodsWithLabel waits for Pods in the kube-system namespace to become Ready
	WaitForPodsWithLabel(kvLabel string) error
	// WaitForStaticPodSingleHash fetches sha256 hash for the control plane static pod
	WaitForStaticPodSingleHash(nodeName string, component string) (string, error)
	// WaitForStaticPodHashChange waits for the given static pod component's static pod hash to get updated.
	// By doing that we can be sure that the kubelet has restarted the given Static Pod
	WaitForStaticPodHashChange(nodeName, component, previousHash string) error
	// WaitForStaticPodControlPlaneHashes fetches sha256 hashes for the control plane static pods
	WaitForStaticPodControlPlaneHashes(nodeName string) (map[string]string, error)
	// WaitForKubelet blocks until the kubelet /healthz endpoint returns 'ok'
	WaitForKubelet(healthzAddress string, healthzPort int32) error
	// SetTimeout adjusts the timeout to the specified duration
	SetTimeout(timeout time.Duration)
}

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

func NewKubeWaiter

func NewKubeWaiter(client clientset.Interface, timeout time.Duration, writer io.Writer) Waiter

NewKubeWaiter returns a new Waiter object that talks to the given Kubernetes cluster

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳