Documentation ¶
Overview ¶
Package apiclient contains wrapping logic for Kubernetes API clients.
Index ¶
- func CreateOrMutateConfigMap(client clientset.Interface, cm *v1.ConfigMap, mutator ConfigMapMutator) error
- func CreateOrRetainConfigMap(client clientset.Interface, cm *v1.ConfigMap, configMapName string) error
- func CreateOrRetainDeployment(client clientset.Interface, deploy *apps.Deployment, deployName string) error
- func CreateOrUpdateClusterRole(client clientset.Interface, clusterRole *rbac.ClusterRole) error
- func CreateOrUpdateClusterRoleBinding(client clientset.Interface, clusterRoleBinding *rbac.ClusterRoleBinding) error
- func CreateOrUpdateConfigMap(client clientset.Interface, cm *v1.ConfigMap) error
- func CreateOrUpdateDaemonSet(client clientset.Interface, ds *apps.DaemonSet) error
- func CreateOrUpdateDeployment(client clientset.Interface, deploy *apps.Deployment) error
- func CreateOrUpdateRole(client clientset.Interface, role *rbac.Role) error
- func CreateOrUpdateRoleBinding(client clientset.Interface, roleBinding *rbac.RoleBinding) error
- func CreateOrUpdateSecret(client clientset.Interface, secret *v1.Secret) error
- func CreateOrUpdateServiceAccount(client clientset.Interface, sa *v1.ServiceAccount) 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), ...) func(context.Context) (bool, error)
- type ConfigMapMutator
- type 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(cfg *kubeadmapi.ClusterConfiguration, 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
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateOrMutateConfigMap ¶ added in v1.15.0
func CreateOrMutateConfigMap(client clientset.Interface, cm *v1.ConfigMap, mutator ConfigMapMutator) error
CreateOrMutateConfigMap tries to create the ConfigMap provided as cm. 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 ConfigMap will be performed. This function is resilient to conflicts, and a retry will be issued if the ConfigMap was modified on the server between the refresh and the update (while the mutation was taking place)
func CreateOrRetainConfigMap ¶ added in v1.11.0
func CreateOrRetainConfigMap(client clientset.Interface, cm *v1.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 CreateOrRetainDeployment ¶ added in v1.16.4
func CreateOrRetainDeployment(client clientset.Interface, deploy *apps.Deployment, deployName string) error
CreateOrRetainDeployment creates a Deployment if the target resource doesn't exist. If the resource exists already, this function will retain the resource instead.
func CreateOrUpdateClusterRole ¶
func CreateOrUpdateClusterRole(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(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 ¶
CreateOrUpdateConfigMap creates a ConfigMap if the target resource doesn't exist. If the resource exists already, this function will update the resource instead.
func CreateOrUpdateDaemonSet ¶
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(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 CreateOrUpdateRole ¶
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(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 ¶
CreateOrUpdateSecret creates a Secret if the target resource doesn't exist. If the resource exists already, this function will update the resource instead.
func CreateOrUpdateServiceAccount ¶
func CreateOrUpdateServiceAccount(client clientset.Interface, sa *v1.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 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.
Types ¶
type ConfigMapMutator ¶ added in v1.15.0
ConfigMapMutator is a function that mutates the given ConfigMap and optionally returns an error
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) 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
DynamicClient returns the dynamic client for this DryRun.
func (*DryRun) FakeClient ¶ added in v1.32.0
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
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
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
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
WithRestConfig takes a rest Config and creates real clientset and dynamic clients.
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(cfg *kubeadmapi.ClusterConfiguration, 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(cfg *kubeadmapi.ClusterConfiguration, 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