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) GetKubeProxyConfigReactor() *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) 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) error
- func (w *KubeWaiter) WaitForKubelet(healthzAddress string, healthzPort int32) error
- func (w *KubeWaiter) WaitForPodToDisappear(podName string) 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 ¶
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) 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) GetKubeProxyConfigReactor ¶
func (d *DryRun) GetKubeProxyConfigReactor() *testing.SimpleReactor
GetKubeProxyConfigReactor returns a reactor that handles the GET action of the "kube-proxy" ConfigMap.
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) 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.
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) error
WaitForControlPlaneComponents waits for all control plane components to report "ok" on /healthz
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) WaitForPodToDisappear ¶
func (w *KubeWaiter) WaitForPodToDisappear(podName string) error
WaitForPodToDisappear blocks until it timeouts or gets a "NotFound" response from the API Server when getting the Static Pod in question
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 report "ok" on /healthz WaitForControlPlaneComponents(cfg *kubeadmapi.ClusterConfiguration) 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 // WaitForPodToDisappear waits for the given Pod in the kube-system namespace to be deleted WaitForPodToDisappear(staticPodName 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