Documentation ¶
Overview ¶
Package k8sclient implements various k8s and EKS client utils.
Index ¶
- Constants
- func CreateNamespace(lg *zap.Logger, c clientset.Interface, namespace string) error
- func CreateObject(dynamicClient dynamic.Interface, namespace string, name string, ...) error
- func DeleteNamespace(lg *zap.Logger, c clientset.Interface, namespace string) error
- func DeleteNamespaceAndWait(lg *zap.Logger, c clientset.Interface, namespace string, ...) error
- func IsRetryableAPIError(err error) bool
- func IsRetryableNetError(err error) bool
- func ListEvents(c clientset.Interface, namespace string, name string, ...) (obj *apiv1.EventList, err error)
- func ListNamespaces(c clientset.Interface) ([]apiv1.Namespace, error)
- func ListNodes(c clientset.Interface) ([]apiv1.Node, error)
- func ListNodesWithOptions(c clientset.Interface, listOpts metav1.ListOptions) ([]apiv1.Node, error)
- func ListPodsWithOptions(c clientset.Interface, namespace string, listOpts metav1.ListOptions) ([]apiv1.Pod, error)
- func RetryFunction(f func() error, options ...*ApiCallOptions) wait.ConditionFunc
- func RetryWithExponentialBackOff(fn wait.ConditionFunc) error
- func WaitForDeleteNamespace(lg *zap.Logger, c clientset.Interface, namespace string) error
- type ApiCallOptions
- type EKS
- type EKSConfig
- type Object
- type ServerVersionInfo
Constants ¶
const ( // DefaultNamespaceDeletionInterval is the default namespace deletion interval. DefaultNamespaceDeletionInterval = 15 * time.Second // DefaultNamespaceDeletionTimeout is the default namespace deletion timeout. DefaultNamespaceDeletionTimeout = 10 * time.Minute )
Variables ¶
This section is empty.
Functions ¶
func CreateNamespace ¶
CreateNamespace creates a single namespace with given name.
func CreateObject ¶
func CreateObject(dynamicClient dynamic.Interface, namespace string, name string, obj *unstructured.Unstructured, options ...*ApiCallOptions) error
CreateObject creates object based on given object description.
func DeleteNamespace ¶
DeleteNamespace deletes namespace with given name.
func DeleteNamespaceAndWait ¶
func DeleteNamespaceAndWait(lg *zap.Logger, c clientset.Interface, namespace string, interval time.Duration, timeout time.Duration) error
DeleteNamespaceAndWait deletes namespace with given name and waits for its deletion. Default interval is 5-second and default timeout is 10-min.
func IsRetryableAPIError ¶
IsRetryableAPIError verifies whether the error is retryable.
func IsRetryableNetError ¶
IsRetryableNetError determines whether the error is a retryable net error.
func ListEvents ¶
func ListEvents(c clientset.Interface, namespace string, name string, options ...*ApiCallOptions) (obj *apiv1.EventList, err error)
ListEvents retrieves events for the object with the given name.
func ListNamespaces ¶
ListNamespaces returns list of existing namespace names.
func ListNodesWithOptions ¶
ListNodesWithOptions lists the cluster nodes using the provided options.
func ListPodsWithOptions ¶
func ListPodsWithOptions(c clientset.Interface, namespace string, listOpts metav1.ListOptions) ([]apiv1.Pod, error)
ListPodsWithOptions lists the pods using the provided options.
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.
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 EKS ¶ added in v1.0.2
type EKS interface { // KubernetesClientSet returns a new kubernetes client set. KubernetesClientSet() *kubernetes.Clientset // CheckEKSHealth checks the EKS health. CheckHealth() error // FetchServerVersion fetches the version from kube-apiserver. // // e.g. // // { // "major": "1", // "minor": "16+", // "gitVersion": "v1.16.8-eks-e16311", // "gitCommit": "e163110a04dcb2f39c3325af96d019b4925419eb", // "gitTreeState": "clean", // "buildDate": "2020-03-27T22:37:12Z", // "goVersion": "go1.13.8", // "compiler": "gc", // "platform": "linux/amd64" // } // FetchServerVersion() (ServerVersionInfo, error) // FetchSupportedAPIGroupVersions fetches all supported API group resources. // ref. https://github.com/kubernetes/kubernetes/tree/master/staging/src/k8s.io/kubectl/pkg/cmd/apiresources FetchSupportedAPIGroupVersions() (float64, map[string]struct{}, error) // ListNamespaces returns the list of existing namespace names. ListNamespaces(batchLimit int64, batchInterval time.Duration) ([]v1.Namespace, error) // ListNodes returns the list of existing nodes. ListNodes(batchLimit int64, batchInterval time.Duration) ([]v1.Node, error) // ListPods returns the list of existing namespace names. ListPods(namespace string, batchLimit int64, batchInterval time.Duration) ([]v1.Pod, error) // ListSecrets returns the list of existing Secret objects. ListSecrets(namespace string, batchLimit int64, batchInterval time.Duration) ([]v1.Secret, error) ListAppsV1Deployments(namespace string, batchLimit int64, batchInterval time.Duration) (ss []apps_v1.Deployment, err error) ListAppsV1StatefulSets(namespace string, batchLimit int64, batchInterval time.Duration) (ss []apps_v1.StatefulSet, err error) ListAppsV1DaemonSets(namespace string, batchLimit int64, batchInterval time.Duration) (ss []apps_v1.DaemonSet, err error) ListAppsV1ReplicaSets(namespace string, batchLimit int64, batchInterval time.Duration) (ss []apps_v1.ReplicaSet, err error) ListNetworkingV1NetworkPolicies(namespace string, batchLimit int64, batchInterval time.Duration) (ss []networking_v1.NetworkPolicy, err error) ListPolicyV1beta1PodSecurityPolicies(batchLimit int64, batchInterval time.Duration) (ss []policy_v1beta1.PodSecurityPolicy, err error) ListAppsV1beta1Deployments(namespace string, batchLimit int64, batchInterval time.Duration) (ss []apps_v1beta1.Deployment, err error) ListAppsV1beta1StatefulSets(namespace string, batchLimit int64, batchInterval time.Duration) (ss []apps_v1beta1.StatefulSet, err error) ListAppsV1beta2Deployments(namespace string, batchLimit int64, batchInterval time.Duration) (ss []apps_v1beta2.Deployment, err error) ListAppsV1beta2StatefulSets(namespace string, batchLimit int64, batchInterval time.Duration) (ss []apps_v1beta2.StatefulSet, err error) ListExtensionsV1beta1DaemonSets(namespace string, batchLimit int64, batchInterval time.Duration) (ss []extensions_v1beta1.DaemonSet, err error) ListExtensionsV1beta1Deployments(namespace string, batchLimit int64, batchInterval time.Duration) (ss []extensions_v1beta1.Deployment, err error) ListExtensionsV1beta1ReplicaSets(namespace string, batchLimit int64, batchInterval time.Duration) (ss []extensions_v1beta1.ReplicaSet, err error) ListExtensionsV1beta1NetworkPolicies(namespace string, batchLimit int64, batchInterval time.Duration) (ss []extensions_v1beta1.NetworkPolicy, err error) ListExtensionsV1beta1PodSecurityPolicies(batchLimit int64, batchInterval time.Duration) (ss []extensions_v1beta1.PodSecurityPolicy, err error) // GetObject get object type and object metadata using kubectl. // The internal API group version is not exposed, // thus kubectl converts API version internally. // ref. https://github.com/kubernetes/kubernetes/issues/58131#issuecomment-403829566 GetObject(namespace string, kind string, name string) (obj Object, d []byte, err error) // Deprecate checks deprecated API groups based on the current kube-apiserver version. Deprecate(batchLimit int64, batchInterval time.Duration) error }
EKS defines EKS client operations.
type EKSConfig ¶ added in v1.0.2
type EKSConfig struct { // Logger is the logger to log client operations. Logger *zap.Logger // 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 // KubectlPath is the kubectl path, used for health checks. KubectlPath string // KubeConfigPath is the kubeconfig path to load. KubeConfigPath string // KubeConfigContext is the kubeconfig context. KubeConfigContext string // ServerVersion is the kube-apiserver version. // If not empty, this is used for health checks. ServerVersion string // EncryptionEnabled is true if EKS cluster is created with KMS encryption enabled. // If true, the health check checks if data encryption key has been generated // to encrypt initial service account tokens, via kube-apiserver metrics endpoint. EncryptionEnabled bool // EnablePrompt is true to enable interactive mode. EnablePrompt bool // Dir is the directory to store all upgrade/rollback files. Dir string // 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 }
EKSConfig defines EKS client configuration.
type Object ¶ added in v1.0.2
type Object struct { // Kind is a string value representing the REST resource this object represents. // Servers may infer this from the endpoint the client submits requests to. // Cannot be updated. // In CamelCase. // More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds // ref. metav1.TypeMeta Kind string `json:"kind"` // APIVersion defines the versioned schema of this representation of an object. // Servers should convert recognized schemas to the latest internal value, and // may reject unrecognized values. // More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources // ref. metav1.TypeMeta APIVersion string `json:"apiVersion"` ObjectMeta metav1.ObjectMeta `json:"metadata"` }
Object contains all object metadata.
type ServerVersionInfo ¶ added in v1.0.2
ServerVersionInfo is the server version info from kube-apiserver
func (ServerVersionInfo) String ¶ added in v1.0.2
func (sv ServerVersionInfo) String() string
Directories ¶
Path | Synopsis |
---|---|
Package eksdeprecate defines deprecated APIs for EKS.
|
Package eksdeprecate defines deprecated APIs for EKS. |