Documentation ¶
Overview ¶
Package client implements Kubernetes client utilities.
Index ¶
- Constants
- func CheckPodLogs(lg *zap.Logger, logWriter io.Writer, stopc chan struct{}, ...) (logs string, err error)
- func CreateNamespace(lg *zap.Logger, c k8s_client.Interface, namespace string) error
- func DefaultKubectlDownloadURL() string
- func DefaultKubectlPath() string
- func DeleteConfigmap(lg *zap.Logger, c k8s_client.Interface, namespace string, name string) error
- func DeleteCronJob(lg *zap.Logger, c k8s_client.Interface, namespace string, name string) error
- func DeleteDaemonSet(lg *zap.Logger, c k8s_client.Interface, namespace string, name string) error
- func DeleteDeployment(lg *zap.Logger, c k8s_client.Interface, namespace string, ...) error
- func DeleteJob(lg *zap.Logger, c k8s_client.Interface, namespace string, name string) error
- func DeleteNamespaceAndWait(lg *zap.Logger, c k8s_client.Interface, namespace string, ...) error
- func DeletePod(lg *zap.Logger, c k8s_client.Interface, namespace string, Name string) error
- func DeleteRBACClusterRole(lg *zap.Logger, c k8s_client.Interface, name string) error
- func DeleteRBACClusterRoleBinding(lg *zap.Logger, c k8s_client.Interface, name string) error
- func DeleteRBACRole(lg *zap.Logger, c k8s_client.Interface, namespace string, name string) error
- func DeleteRBACRoleBinding(lg *zap.Logger, c k8s_client.Interface, namespace string, name string) error
- func DeleteService(lg *zap.Logger, c k8s_client.Interface, namespace string, svcName string) error
- func DeleteServiceAccount(lg *zap.Logger, c k8s_client.Interface, namespace string, name string) error
- func FindServiceIngressHostname(lg *zap.Logger, c k8s_client.Interface, namespace string, svcName string, ...) (hostName string, elbARN string, elbName string, exists bool, err error)
- func GetInternalIP(node *core_v1.Node) (string, error)
- func GetRandomReadySchedulableNode(cli k8s_client.Interface) (*core_v1.Node, error)
- func IsRetryableAPIError(err error) bool
- func IsRetryableNetError(err error) bool
- func ListDaemonSets(lg *zap.Logger, c k8s_client.Interface, namespace string, batchLimit int64, ...) (daemonsets []apps_v1.DaemonSet, err error)
- func ListNamespaces(c k8s_client.Interface) ([]core_v1.Namespace, error)
- func ListNodes(cli k8s_client.Interface) ([]core_v1.Node, error)
- func ListNodesWithOptions(cli k8s_client.Interface, listOpts meta_v1.ListOptions) ([]core_v1.Node, error)
- func ListPods(lg *zap.Logger, c k8s_client.Interface, namespace string, batchLimit int64, ...) (pods []core_v1.Pod, err error)
- func ListSecrets(lg *zap.Logger, cli k8s_client.Interface, namespace string, batchLimit int64, ...) (ss []core_v1.Secret, err error)
- func ListStorageClass(lg *zap.Logger, c k8s_client.Interface, batchLimit int64, ...) (storageclass []storage_v1.StorageClass, err error)
- func NewBusyBoxPod(name, command string) *v1.Pod
- func PodRunning(c k8s_client.Interface, podName, namespace string) wait.ConditionFunc
- func RetryFunction(f func() error, options ...*ApiCallOptions) wait.ConditionFunc
- func RetryWithExponentialBackOff(fn wait.ConditionFunc) error
- func WaitForCronJobCompletes(ctx context.Context, lg *zap.Logger, logWriter io.Writer, stopc chan struct{}, ...) (cronJob *batch_v1beta1.CronJob, pods []core_v1.Pod, err error)
- func WaitForDaemonSetCompletes(ctx context.Context, lg *zap.Logger, logWriter io.Writer, stopc chan struct{}, ...) (dp *apps_v1.DaemonSet, err error)
- func WaitForDeploymentAvailables(ctx context.Context, lg *zap.Logger, logWriter io.Writer, stopc chan struct{}, ...) (dp *apps_v1.Deployment, err error)
- func WaitForJobCompletes(ctx context.Context, lg *zap.Logger, logWriter io.Writer, stopc chan struct{}, ...) (job *batch_v1.Job, pods []core_v1.Pod, err error)
- func WaitForPodCondition(lg *zap.Logger, c k8s_client.Interface, ns, podName, desc string, ...) error
- func WaitForPodRunningInNamespace(c k8s_client.Interface, pod *v1.Pod) error
- func WaitForPodSuccessInNamespaceTimeout(lg *zap.Logger, c k8s_client.Interface, podName, namespace string, ...) error
- func WaitForServiceIngressHostname(lg *zap.Logger, c k8s_client.Interface, namespace string, svcName string, ...) (hostName string, elbARN string, elbName string, err error)
- func WaitTimeoutForPodRunningInNamespace(c k8s_client.Interface, podName, namespace string, timeout time.Duration) error
- type ApiCallOptions
- type Client
- type Config
- type EKS
- type Op
- type OpOption
- type Spinner
Constants ¶
const ( // DefaultNamespacePollInterval is the default namespace poll interval. DefaultNamespacePollInterval = 15 * time.Second // DefaultNamespaceDeletionInterval is the default namespace deletion interval. DefaultNamespaceDeletionInterval = 15 * time.Second // DefaultNamespaceDeletionTimeout is the default namespace deletion timeout. DefaultNamespaceDeletionTimeout = 30 * time.Minute )
Variables ¶
This section is empty.
Functions ¶
func CheckPodLogs ¶
func CheckPodLogs( lg *zap.Logger, logWriter io.Writer, stopc chan struct{}, c k8s_client.Interface, namespace string, podName string, opts ...OpOption) (logs string, err error)
Checks the last 100 lines of logs from a pod
func CreateNamespace ¶
CreateNamespace creates a single namespace with given name.
func DefaultKubectlDownloadURL ¶
func DefaultKubectlDownloadURL() string
func DefaultKubectlPath ¶
func DefaultKubectlPath() string
func DeleteConfigmap ¶
DeleteService deletes namespace with given name.
func DeleteCronJob ¶
DeleteCronJob deletes CronJob with given name.
func DeleteDaemonSet ¶
DeleteDaemonSet deletes namespace with given name.
func DeleteDeployment ¶
func DeleteDeployment(lg *zap.Logger, c k8s_client.Interface, namespace string, deploymentName string) error
DeleteDeployment deletes namespace with given name.
func DeleteNamespaceAndWait ¶
func DeleteNamespaceAndWait( lg *zap.Logger, c k8s_client.Interface, namespace string, pollInterval time.Duration, timeout time.Duration, opts ...OpOption) error
DeleteNamespaceAndWait deletes namespace with given name and waits for its deletion. Default interval is 5-second and default timeout is 10-min.
func DeleteRBACClusterRole ¶
DeleteRBACClusterRole deletes ClusterRole with given name. ref. https://github.com/kubernetes/client-go/tree/master/examples/in-cluster-client-configuration ref. https://kubernetes.io/docs/reference/access-authn-authz/rbac/
func DeleteRBACClusterRoleBinding ¶
DeleteRBACClusterRole deletes ClusterRole with given name. ref. https://github.com/kubernetes/client-go/tree/master/examples/in-cluster-client-configuration ref. https://kubernetes.io/docs/reference/access-authn-authz/rbac/
func DeleteRBACRole ¶
DeleteRBACRole deletes Role with given name. ref. https://github.com/kubernetes/client-go/tree/master/examples/in-cluster-client-configuration ref. https://kubernetes.io/docs/reference/access-authn-authz/rbac/
func DeleteRBACRoleBinding ¶
func DeleteRBACRoleBinding(lg *zap.Logger, c k8s_client.Interface, namespace string, name string) error
DeleteRBACRoleBinding deletes RoleBinding with given name.
func DeleteService ¶
DeleteService deletes namespace with given name.
func DeleteServiceAccount ¶
func DeleteServiceAccount(lg *zap.Logger, c k8s_client.Interface, namespace string, name string) error
DeleteService deletes namespace with given name.
func FindServiceIngressHostname ¶
func FindServiceIngressHostname( lg *zap.Logger, c k8s_client.Interface, namespace string, svcName string, stopc chan struct{}, waitDur time.Duration, accountID string, region string, opts ...OpOption) (hostName string, elbARN string, elbName string, exists bool, err error)
FindServiceIngressHostname finds Service's Ingress Hostname to be updated and returns the ELB ARN.
func GetInternalIP ¶
GetInternalIP returns node internal IP
func GetRandomReadySchedulableNode ¶
func GetRandomReadySchedulableNode(cli k8s_client.Interface) (*core_v1.Node, error)
GetRandomReadySchedulableNode gets a single randomly-selected node which is available for running pods on. If there are no available nodes it will return an error.
func IsRetryableAPIError ¶
IsRetryableAPIError verifies whether the error is retryable.
func IsRetryableNetError ¶
IsRetryableNetError determines whether the error is a retryable net error.
func ListDaemonSets ¶
func ListNamespaces ¶
func ListNamespaces(c k8s_client.Interface) ([]core_v1.Namespace, error)
ListNamespaces returns list of existing namespace names.
func ListNodes ¶
func ListNodes(cli k8s_client.Interface) ([]core_v1.Node, error)
ListNodes returns list of cluster nodes.
func ListNodesWithOptions ¶
func ListNodesWithOptions(cli k8s_client.Interface, listOpts meta_v1.ListOptions) ([]core_v1.Node, error)
ListNodesWithOptions lists the cluster nodes using the provided options.
func ListSecrets ¶
func ListSecrets(lg *zap.Logger, cli k8s_client.Interface, namespace string, batchLimit int64, batchInterval time.Duration) (ss []core_v1.Secret, err error)
ListSecrets returns list of cluster nodes.
func ListStorageClass ¶
func ListStorageClass( lg *zap.Logger, c k8s_client.Interface, batchLimit int64, batchInterval time.Duration, opts ...OpOption) (storageclass []storage_v1.StorageClass, err error)
func NewBusyBoxPod ¶
func PodRunning ¶
func PodRunning(c k8s_client.Interface, podName, namespace string) wait.ConditionFunc
3
func RetryFunction ¶
func RetryFunction(f func() error, options ...*ApiCallOptions) wait.ConditionFunc
RetryFunction opaques given function into retryable function.
func RetryWithExponentialBackOff ¶
func RetryWithExponentialBackOff(fn wait.ConditionFunc) error
RetryWithExponentialBackOff a utility for retrying the given function with exponential backoff.
func WaitForCronJobCompletes ¶
func WaitForCronJobCompletes( ctx context.Context, lg *zap.Logger, logWriter io.Writer, stopc chan struct{}, c k8s_client.Interface, initialWait time.Duration, pollInterval time.Duration, namespace string, jobName string, targetCompletes int, opts ...OpOption) (cronJob *batch_v1beta1.CronJob, pods []core_v1.Pod, err error)
WaitForCronJobCompletes waits for all CronJob completion, by counting the number of pods in the namespace.
func WaitForDaemonSetCompletes ¶
func WaitForDaemonSetCompletes( ctx context.Context, lg *zap.Logger, logWriter io.Writer, stopc chan struct{}, c k8s_client.Interface, initialWait time.Duration, pollInterval time.Duration, namespace string, daemonsetName string, opts ...OpOption) (dp *apps_v1.DaemonSet, err error)
WaitForDaemonSetCompletes waits till target replicas are ready in the Deployment.
func WaitForDeploymentAvailables ¶
func WaitForDeploymentAvailables( ctx context.Context, lg *zap.Logger, logWriter io.Writer, stopc chan struct{}, c k8s_client.Interface, initialWait time.Duration, pollInterval time.Duration, namespace string, deploymentName string, targetAvailableReplicas int32, opts ...OpOption) (dp *apps_v1.Deployment, err error)
WaitForDeploymentAvailables waits till target replicas are ready in the Deployment.
func WaitForJobCompletes ¶
func WaitForJobCompletes( ctx context.Context, lg *zap.Logger, logWriter io.Writer, stopc chan struct{}, c k8s_client.Interface, initialWait time.Duration, pollInterval time.Duration, namespace string, jobName string, targetCompletes int, opts ...OpOption) (job *batch_v1.Job, pods []core_v1.Pod, err error)
WaitForJobCompletes waits for all Job completion, by counting the number of pods in the namespace.
func WaitForPodCondition ¶
func WaitForPodCondition(lg *zap.Logger, c k8s_client.Interface, ns, podName, desc string, timeout time.Duration, condition podCondition) error
WaitForPodCondition waits a pods to be matched to the given condition.
func WaitForPodRunningInNamespace ¶
func WaitForPodRunningInNamespace(c k8s_client.Interface, pod *v1.Pod) error
1 WaitForPodRunningInNamespace waits default amount of time (podStartTimeout) for the specified pod to become running. Returns an error if timeout occurs first, or pod goes in to failed state.
func WaitForPodSuccessInNamespaceTimeout ¶
func WaitForPodSuccessInNamespaceTimeout(lg *zap.Logger, c k8s_client.Interface, podName, namespace string, timeout time.Duration) error
WaitForPodSuccessInNamespaceTimeout returns nil if the pod reached state success, or an error if it reached failure or ran too long.
func WaitForServiceIngressHostname ¶
func WaitForServiceIngressHostname( lg *zap.Logger, c k8s_client.Interface, namespace string, svcName string, stopc chan struct{}, waitDur time.Duration, accountID string, region string, opts ...OpOption) (hostName string, elbARN string, elbName string, err error)
WaitForServiceIngressHostname waits for Service's Ingress Hostname to be updated and returns the ELB ARN.
func WaitTimeoutForPodRunningInNamespace ¶
func WaitTimeoutForPodRunningInNamespace(c k8s_client.Interface, podName, namespace string, timeout time.Duration) error
2 WaitTimeoutForPodRunningInNamespace waits the given timeout duration for the specified pod to become running.
Types ¶
type ApiCallOptions ¶
type ApiCallOptions struct {
// contains filtered or unexported fields
}
ApiCallOptions describes how api call errors should be treated, i.e. which errors should be allowed (ignored) and which should be retried.
func Allow ¶
func Allow(allowErrorPredicate func(error) bool) *ApiCallOptions
Allow creates an ApiCallOptions that allows (ignores) errors matching the given predicate.
func Retry ¶
func Retry(retryErrorPredicate func(error) bool) *ApiCallOptions
Retry creates an ApiCallOptions that retries errors matching the given predicate.
type Client ¶
type Client interface { // KubernetesClient returns a new kubernetes client set. KubernetesClient() k8s_client.Interface // APIExtensionsClient returns a new apiextensions client set. APIExtensionsClient() apiextensions_apiserver_client.Interface Config() Config }
Client defines Kubernetes client interface.
type Config ¶
type Config struct { Logger *zap.Logger // KubectlDownloadURL is the URL for downloading kubectl. KubectlDownloadURL string // KubectlPath is the kubectl path. KubectlPath string // KubeconfigPath is the kubeconfig path to load. KubeconfigPath string // KubeconfigContext is the kubeconfig context. KubeconfigContext string // EKS defines EKS-specific configuration. EKS *EKS // Clients is the number of kubernetes clients to create. // Default is 1. Clients int // ClientQPS is the QPS for kubernetes client. // To use while talking with kubernetes apiserver. // // Kubernetes client DefaultQPS is 5. // Kubernetes client DefaultBurst is 10. // ref. https://github.com/kubernetes/kubernetes/blob/4d0e86f0b8d1eae00a202009858c8739e4c9402e/staging/src/k8s.io/client-go/rest/config.go#L43-L46 // // kube-apiserver default inflight requests limits are: // FLAG: --max-mutating-requests-inflight="200" // FLAG: --max-requests-inflight="400" // ref. https://github.com/kubernetes/kubernetes/blob/4d0e86f0b8d1eae00a202009858c8739e4c9402e/staging/src/k8s.io/apiserver/pkg/server/config.go#L300-L301 // ClientQPS float32 // ClientBurst is the burst for kubernetes client. // To use while talking with kubernetes apiserver // // Kubernetes client DefaultQPS is 5. // Kubernetes client DefaultBurst is 10. // ref. https://github.com/kubernetes/kubernetes/blob/4d0e86f0b8d1eae00a202009858c8739e4c9402e/staging/src/k8s.io/client-go/rest/config.go#L43-L46 // // kube-apiserver default inflight requests limits are: // FLAG: --max-mutating-requests-inflight="200" // FLAG: --max-requests-inflight="400" // ref. https://github.com/kubernetes/kubernetes/blob/4d0e86f0b8d1eae00a202009858c8739e4c9402e/staging/src/k8s.io/apiserver/pkg/server/config.go#L300-L301 // ClientBurst int // ClientTimeout is the client timeout. ClientTimeout time.Duration }
Config defines Kubernetes configuration.
type EKS ¶
type EKS struct { // Region is used for EKS auth provider configuration. Region string // ClusterName is the EKS cluster name. // Used for EKS auth provider configuration. ClusterName string // ClusterAPIServerEndpoint is the EKS kube-apiserver endpoint. // Use for kubeconfig. ClusterAPIServerEndpoint string // ClusterCADecoded is the cluster CA base64-decoded. // Use for kubeconfig. ClusterCADecoded string }
EKS defines EKS-specific client configuration and its states.
type Op ¶
type Op struct {
// contains filtered or unexported fields
}
Op represents a Kubernetes client operation.
type OpOption ¶
type OpOption func(*Op)
OpOption configures Kubernetes client operations.
func WithFieldSelector ¶
WithFieldSelector configures field selector for list operations.
func WithForceDelete ¶
WithForceDelete configures force delete. Useful for namespace deletion. ref. https://github.com/kubernetes/kubernetes/issues/60807
func WithForceDeleteFunc ¶
func WithForceDeleteFunc(forceDeleteFunc func()) OpOption
WithForceDeleteFunc configures force delete. Useful for namespace deletion. ref. https://github.com/kubernetes/kubernetes/issues/60807
func WithLabelSelector ¶
WithLabelSelector configures label selector for list operations.
func WithPodFunc ¶
WithPodFunc configures function to be called for pod.
func WithQueryFunc ¶
func WithQueryFunc(f func()) OpOption
WithQueryFunc configures query function to be called in retry func.