package apiclient
import "k8s.io/kubernetes/cmd/kubeadm/app/util/apiclient"
Package apiclient contains wrapping logic for Kubernetes API clients.
Index ¶
- func CreateOrMutate[T kubernetesObject](client kubernetesInterface[T], obj T, mutator objectMutator[T]) error
- func CreateOrRetain[T kubernetesObject](client kubernetesInterface[T], obj T, name string) error
- func CreateOrUpdate[T kubernetesObject](client kubernetesInterface[T], obj T) error
- func GetConfigMapWithShortRetry(client clientset.Interface, namespace, name string) (*v1.ConfigMap, error)
- func PatchNode(client clientset.Interface, nodeName string, patchFn func(*v1.Node)) error
- func PatchNodeOnce(client clientset.Interface, nodeName string, patchFn func(*v1.Node), lastError *error) func(context.Context) (bool, error)
- func PrintControlPlaneErrorHelpScreen(outputWriter io.Writer, criSocket string)
- func PrintKubeletErrorHelpScreen(outputWriter io.Writer)
- type DryRun
- func NewDryRun() *DryRun
- func (d *DryRun) AppendReactor(r *testing.SimpleReactor) *DryRun
- func (d *DryRun) Client() clientset.Interface
- func (d *DryRun) DeleteBootstrapTokenReactor() *testing.SimpleReactor
- func (d *DryRun) DynamicClient() dynamic.Interface
- func (d *DryRun) FakeClient() clientset.Interface
- func (d *DryRun) GetClusterInfoReactor() *testing.SimpleReactor
- func (d *DryRun) GetCoreDNSConfigReactor() *testing.SimpleReactor
- func (d *DryRun) GetKubeProxyConfigReactor() *testing.SimpleReactor
- func (d *DryRun) GetKubeadmCertsReactor() *testing.SimpleReactor
- func (d *DryRun) GetKubeadmConfigReactor() *testing.SimpleReactor
- func (d *DryRun) GetKubeletConfigReactor() *testing.SimpleReactor
- func (d *DryRun) GetNodeReactor() *testing.SimpleReactor
- func (d *DryRun) HealthCheckJobReactor() *testing.SimpleReactor
- func (d *DryRun) ListDeploymentsReactor() *testing.SimpleReactor
- func (d *DryRun) ListPodsReactor(nodeName string) *testing.SimpleReactor
- func (d *DryRun) LogAction(action testing.Action)
- func (d *DryRun) LogObject(obj runtime.Object, gv schema.GroupVersion)
- func (d *DryRun) PatchNodeReactor() *testing.SimpleReactor
- func (d *DryRun) PrependReactor(r *testing.SimpleReactor) *DryRun
- func (d *DryRun) WithDefaultMarshalFunction() *DryRun
- func (d *DryRun) WithKubeConfig(config *clientcmdapi.Config) error
- func (d *DryRun) WithKubeConfigFile(file string) error
- func (d *DryRun) WithMarshalFunction(f func(runtime.Object, schema.GroupVersion) ([]byte, error)) *DryRun
- func (d *DryRun) WithRestConfig(config *rest.Config) error
- func (d *DryRun) WithWriter(w io.Writer) *DryRun
- type KubeWaiter
- func (w *KubeWaiter) SetTimeout(timeout time.Duration)
- func (w *KubeWaiter) WaitForAPI() error
- func (w *KubeWaiter) WaitForControlPlaneComponents(podMap map[string]*v1.Pod, apiSeverAddress string) error
- func (w *KubeWaiter) WaitForKubelet(healthzAddress string, healthzPort int32) error
- func (w *KubeWaiter) WaitForPodsWithLabel(kvLabel string) error
- func (w *KubeWaiter) WaitForStaticPodControlPlaneHashes(nodeName string) (map[string]string, error)
- func (w *KubeWaiter) WaitForStaticPodHashChange(nodeName, component, previousHash string) error
- func (w *KubeWaiter) WaitForStaticPodSingleHash(nodeName string, component string) (string, error)
- type Waiter
Functions ¶
func CreateOrMutate ¶
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 ¶
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 ¶
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 ¶
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 ¶
PatchNode tries to patch a node using patchFn for the actual mutating logic. Retries are provided by the wait package.
func PatchNodeOnce ¶
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 ¶
PrintControlPlaneErrorHelpScreen prints help text on wait ControlPlane components errors.
func PrintKubeletErrorHelpScreen ¶
PrintKubeletErrorHelpScreen prints help text on kubelet errors.
Types ¶
type DryRun ¶
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 ¶
func NewDryRun() *DryRun
NewDryRun creates a new DryRun object that only has a fake client.
func (*DryRun) AppendReactor ¶
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 ¶
Client returns the clientset for this DryRun.
func (*DryRun) DeleteBootstrapTokenReactor ¶
func (d *DryRun) DeleteBootstrapTokenReactor() *testing.SimpleReactor
DeleteBootstrapTokenReactor returns a reactor that handles the DELETE action of bootstrap token Secret.
func (*DryRun) DynamicClient ¶
DynamicClient returns the dynamic client for this DryRun.
func (*DryRun) FakeClient ¶
FakeClient returns the fake client for this DryRun.
func (*DryRun) GetClusterInfoReactor ¶
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 ¶
func (d *DryRun) GetCoreDNSConfigReactor() *testing.SimpleReactor
GetCoreDNSConfigReactor returns a reactor that handles the GET action of the "coredns" ConfigMap.
func (*DryRun) GetKubeProxyConfigReactor ¶
func (d *DryRun) GetKubeProxyConfigReactor() *testing.SimpleReactor
GetKubeProxyConfigReactor returns a reactor that handles the GET action of the "kube-proxy" ConfigMap.
func (*DryRun) GetKubeadmCertsReactor ¶
func (d *DryRun) GetKubeadmCertsReactor() *testing.SimpleReactor
GetKubeadmCertsReactor returns a reactor that handles the GET action of the "kubeadm-certs" Secret.
func (*DryRun) GetKubeadmConfigReactor ¶
func (d *DryRun) GetKubeadmConfigReactor() *testing.SimpleReactor
GetKubeadmConfigReactor returns a reactor that handles the GET action of the "kubeadm-config" ConfigMap.
func (*DryRun) GetKubeletConfigReactor ¶
func (d *DryRun) GetKubeletConfigReactor() *testing.SimpleReactor
GetKubeletConfigReactor returns a reactor that handles the GET action of the "kubelet-config" ConfigMap.
func (*DryRun) GetNodeReactor ¶
func (d *DryRun) GetNodeReactor() *testing.SimpleReactor
GetNodeReactor returns a reactor that handles the generic GET action of Node objects.
func (*DryRun) HealthCheckJobReactor ¶
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 ¶
func (d *DryRun) ListDeploymentsReactor() *testing.SimpleReactor
ListDeploymentsReactor returns a reactor that handles the LIST action on deployments.
func (*DryRun) ListPodsReactor ¶
func (d *DryRun) ListPodsReactor(nodeName string) *testing.SimpleReactor
ListPodsReactor returns a reactor that handles the LIST action on pods.
func (*DryRun) LogAction ¶
LogAction logs details about an action, such as name, object and resource.
func (*DryRun) LogObject ¶
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 ¶
func (d *DryRun) PatchNodeReactor() *testing.SimpleReactor
PatchNodeReactor returns a reactor that handles the generic PATCH action on Node objects.
func (*DryRun) PrependReactor ¶
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 ¶
WithDefaultMarshalFunction sets the DryRun marshal function to the default one.
func (*DryRun) WithKubeConfig ¶
func (d *DryRun) WithKubeConfig(config *clientcmdapi.Config) error
WithKubeConfig takes a Config (kubeconfig) and creates real clientset and dynamic client.
func (*DryRun) WithKubeConfigFile ¶
WithKubeConfigFile takes a file path and creates real clientset and dynamic clients.
func (*DryRun) WithMarshalFunction ¶
func (d *DryRun) WithMarshalFunction(f func(runtime.Object, schema.GroupVersion) ([]byte, error)) *DryRun
WithMarshalFunction sets the DryRun marshal function.
func (*DryRun) WithRestConfig ¶
WithRestConfig takes a rest Config and creates real clientset and dynamic clients.
func (*DryRun) WithWriter ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
NewKubeWaiter returns a new Waiter object that talks to the given Kubernetes cluster
Source Files ¶
dryrun.go idempotency.go wait.go
- Version
- v1.33.0 (latest)
- Published
- Apr 23, 2025
- Platform
- linux/amd64
- Imports
- 36 packages
- Last checked
- 3 hours ago –
Tools for package owners.