Documentation ¶
Overview ¶
Package kube provides helper utilities common for kubernetes
Index ¶
- Constants
- func GetAppInstanceLabel(un *unstructured.Unstructured, key string) string
- func GetDeploymentReplicas(u *unstructured.Unstructured) *int64
- func GetObjectRef(obj *unstructured.Unstructured) v1.ObjectReference
- func IsCRD(obj *unstructured.Unstructured) bool
- func IsCRDGroupVersionKind(gvk schema.GroupVersionKind) bool
- func IsNamespacedOrUnknown(provider ResourceInfoProvider, gk schema.GroupKind) bool
- func MustToUnstructured(obj interface{}) *unstructured.Unstructured
- func NewKubeConfig(restConfig *rest.Config, namespace string) *clientcmdapi.Config
- func RetryUntilSucceed(ctx context.Context, interval time.Duration, desc string, log logr.Logger, ...)
- func RunAllAsync(count int, action func(i int) error) error
- func ServerResourceForGroupVersionKind(disco discovery.DiscoveryInterface, gvk schema.GroupVersionKind, verb string) (*metav1.APIResource, error)
- func SplitYAML(yamlData []byte) ([]*unstructured.Unstructured, error)
- func SplitYAMLToString(yamlData []byte) ([]string, error)
- func TestConfig(config *rest.Config) error
- func ToGroupVersionResource(groupVersion string, apiResource *metav1.APIResource) schema.GroupVersionResource
- func ToResourceInterface(dynamicIf dynamic.Interface, apiResource *metav1.APIResource, ...) dynamic.ResourceInterface
- func ToUnstructured(obj interface{}) (*unstructured.Unstructured, error)
- func UnsetLabel(target *unstructured.Unstructured, key string)
- func WatchWithRetry(ctx context.Context, getWatch func() (watch.Interface, error)) ...
- func WriteKubeConfig(restConfig *rest.Config, namespace, filename string) error
- type APIResourceInfo
- type CleanupFunc
- type CreateGVKParserError
- type Kubectl
- type KubectlCmd
- func (k *KubectlCmd) ConvertToVersion(obj *unstructured.Unstructured, group string, version string) (*unstructured.Unstructured, error)
- func (k *KubectlCmd) DeleteResource(ctx context.Context, config *rest.Config, gvk schema.GroupVersionKind, ...) error
- func (k *KubectlCmd) GetAPIResources(config *rest.Config, preferred bool, resourceFilter ResourceFilter) ([]APIResourceInfo, error)
- func (k *KubectlCmd) GetResource(ctx context.Context, config *rest.Config, gvk schema.GroupVersionKind, ...) (*unstructured.Unstructured, error)
- func (k *KubectlCmd) GetServerVersion(config *rest.Config) (string, error)
- func (k *KubectlCmd) LoadOpenAPISchema(config *rest.Config) (openapi.Resources, *managedfields.GvkParser, error)
- func (k *KubectlCmd) ManageResources(config *rest.Config, openAPISchema openapi.Resources) (ResourceOperations, func(), error)
- func (k *KubectlCmd) NewDynamicClient(config *rest.Config) (dynamic.Interface, error)
- func (k *KubectlCmd) PatchResource(ctx context.Context, config *rest.Config, gvk schema.GroupVersionKind, ...) (*unstructured.Unstructured, error)
- func (k *KubectlCmd) SetOnKubectlRun(onKubectlRun OnKubectlRunFunc)
- type OnKubectlRunFunc
- type ResourceFilter
- type ResourceInfoProvider
- type ResourceKey
- type ResourceOperations
Constants ¶
const ( SecretKind = "Secret" ServiceKind = "Service" ServiceAccountKind = "ServiceAccount" EndpointsKind = "Endpoints" DeploymentKind = "Deployment" ReplicaSetKind = "ReplicaSet" StatefulSetKind = "StatefulSet" DaemonSetKind = "DaemonSet" IngressKind = "Ingress" JobKind = "Job" PersistentVolumeClaimKind = "PersistentVolumeClaim" CustomResourceDefinitionKind = "CustomResourceDefinition" PodKind = "Pod" APIServiceKind = "APIService" NamespaceKind = "Namespace" HorizontalPodAutoscalerKind = "HorizontalPodAutoscaler" )
Variables ¶
This section is empty.
Functions ¶
func GetAppInstanceLabel ¶
func GetAppInstanceLabel(un *unstructured.Unstructured, key string) string
GetAppInstanceLabel returns the application instance name from labels
func GetDeploymentReplicas ¶
func GetDeploymentReplicas(u *unstructured.Unstructured) *int64
func GetObjectRef ¶
func GetObjectRef(obj *unstructured.Unstructured) v1.ObjectReference
func IsCRD ¶
func IsCRD(obj *unstructured.Unstructured) bool
func IsCRDGroupVersionKind ¶
func IsCRDGroupVersionKind(gvk schema.GroupVersionKind) bool
func IsNamespacedOrUnknown ¶
func IsNamespacedOrUnknown(provider ResourceInfoProvider, gk schema.GroupKind) bool
func MustToUnstructured ¶
func MustToUnstructured(obj interface{}) *unstructured.Unstructured
MustToUnstructured converts a concrete K8s API type to a un unstructured object and panics if not successful
func NewKubeConfig ¶
func NewKubeConfig(restConfig *rest.Config, namespace string) *clientcmdapi.Config
NewKubeConfig converts a clientcmdapi.Config (kubeconfig) from a rest.Config
func RetryUntilSucceed ¶
func RetryUntilSucceed(ctx context.Context, interval time.Duration, desc string, log logr.Logger, action func() error)
RetryUntilSucceed keep retrying given action with specified interval until action succeed or specified context is done.
func ServerResourceForGroupVersionKind ¶
func ServerResourceForGroupVersionKind(disco discovery.DiscoveryInterface, gvk schema.GroupVersionKind, verb string) (*metav1.APIResource, error)
ServerResourceForGroupVersionKind looks up and returns the API resource from the server for a given GVK scheme. If verb is set to the non-empty string, it will return the API resource which supports the verb. There are some edge cases, where the same GVK is represented by more than one API.
See: https://github.com/ksonnet/ksonnet/blob/master/utils/client.go
func SplitYAML ¶
func SplitYAML(yamlData []byte) ([]*unstructured.Unstructured, error)
SplitYAML splits a YAML file into unstructured objects. Returns list of all unstructured objects found in the yaml. If an error occurs, returns objects that have been parsed so far too.
func SplitYAMLToString ¶ added in v0.5.0
SplitYAMLToString splits a YAML file into strings. Returns list of yamls found in the yaml. If an error occurs, returns objects that have been parsed so far too.
func TestConfig ¶
TestConfig tests to make sure the REST config is usable
func ToGroupVersionResource ¶
func ToGroupVersionResource(groupVersion string, apiResource *metav1.APIResource) schema.GroupVersionResource
func ToResourceInterface ¶
func ToResourceInterface(dynamicIf dynamic.Interface, apiResource *metav1.APIResource, resource schema.GroupVersionResource, namespace string) dynamic.ResourceInterface
func ToUnstructured ¶
func ToUnstructured(obj interface{}) (*unstructured.Unstructured, error)
ToUnstructured converts a concrete K8s API type to a un unstructured object
func UnsetLabel ¶
func UnsetLabel(target *unstructured.Unstructured, key string)
UnsetLabel removes our app labels from an unstructured object
Types ¶
type APIResourceInfo ¶
type APIResourceInfo struct { GroupKind schema.GroupKind Meta metav1.APIResource GroupVersionResource schema.GroupVersionResource }
type CleanupFunc ¶ added in v0.2.0
type CleanupFunc func()
type CreateGVKParserError ¶ added in v0.7.0
type CreateGVKParserError struct {
// contains filtered or unexported fields
}
func NewCreateGVKParserError ¶ added in v0.7.0
func NewCreateGVKParserError(err error) *CreateGVKParserError
func (*CreateGVKParserError) Error ¶ added in v0.7.0
func (e *CreateGVKParserError) Error() string
type Kubectl ¶
type Kubectl interface { ManageResources(config *rest.Config, openAPISchema openapi.Resources) (ResourceOperations, func(), error) LoadOpenAPISchema(config *rest.Config) (openapi.Resources, *managedfields.GvkParser, error) ConvertToVersion(obj *unstructured.Unstructured, group, version string) (*unstructured.Unstructured, error) DeleteResource(ctx context.Context, config *rest.Config, gvk schema.GroupVersionKind, name string, namespace string, deleteOptions metav1.DeleteOptions) error GetResource(ctx context.Context, config *rest.Config, gvk schema.GroupVersionKind, name string, namespace string) (*unstructured.Unstructured, error) PatchResource(ctx context.Context, config *rest.Config, gvk schema.GroupVersionKind, name string, namespace string, patchType types.PatchType, patchBytes []byte, subresources ...string) (*unstructured.Unstructured, error) GetAPIResources(config *rest.Config, preferred bool, resourceFilter ResourceFilter) ([]APIResourceInfo, error) GetServerVersion(config *rest.Config) (string, error) NewDynamicClient(config *rest.Config) (dynamic.Interface, error) SetOnKubectlRun(onKubectlRun OnKubectlRunFunc) }
type KubectlCmd ¶
type KubectlCmd struct { Log logr.Logger Tracer tracing.Tracer OnKubectlRun OnKubectlRunFunc }
func (*KubectlCmd) ConvertToVersion ¶
func (k *KubectlCmd) ConvertToVersion(obj *unstructured.Unstructured, group string, version string) (*unstructured.Unstructured, error)
ConvertToVersion converts an unstructured object into the specified group/version
func (*KubectlCmd) DeleteResource ¶
func (k *KubectlCmd) DeleteResource(ctx context.Context, config *rest.Config, gvk schema.GroupVersionKind, name string, namespace string, deleteOptions metav1.DeleteOptions) error
DeleteResource deletes resource
func (*KubectlCmd) GetAPIResources ¶
func (k *KubectlCmd) GetAPIResources(config *rest.Config, preferred bool, resourceFilter ResourceFilter) ([]APIResourceInfo, error)
func (*KubectlCmd) GetResource ¶
func (k *KubectlCmd) GetResource(ctx context.Context, config *rest.Config, gvk schema.GroupVersionKind, name string, namespace string) (*unstructured.Unstructured, error)
GetResource returns resource
func (*KubectlCmd) GetServerVersion ¶
func (k *KubectlCmd) GetServerVersion(config *rest.Config) (string, error)
func (*KubectlCmd) LoadOpenAPISchema ¶ added in v0.4.0
func (k *KubectlCmd) LoadOpenAPISchema(config *rest.Config) (openapi.Resources, *managedfields.GvkParser, error)
LoadOpenAPISchema will load all existing resource schemas from the cluster and return: - openapi.Resources: used for getting the proto.Schema from a GVK - managedfields.GvkParser: used for building a ParseableType to be used in structured-merge-diffs
func (*KubectlCmd) ManageResources ¶ added in v0.4.0
func (k *KubectlCmd) ManageResources(config *rest.Config, openAPISchema openapi.Resources) (ResourceOperations, func(), error)
func (*KubectlCmd) NewDynamicClient ¶
func (*KubectlCmd) PatchResource ¶
func (k *KubectlCmd) PatchResource(ctx context.Context, config *rest.Config, gvk schema.GroupVersionKind, name string, namespace string, patchType types.PatchType, patchBytes []byte, subresources ...string) (*unstructured.Unstructured, error)
PatchResource patches resource
func (*KubectlCmd) SetOnKubectlRun ¶
func (k *KubectlCmd) SetOnKubectlRun(onKubectlRun OnKubectlRunFunc)
type OnKubectlRunFunc ¶ added in v0.2.0
type OnKubectlRunFunc func(command string) (CleanupFunc, error)
type ResourceFilter ¶
type ResourceInfoProvider ¶
type ResourceKey ¶
func GetResourceKey ¶
func GetResourceKey(obj *unstructured.Unstructured) ResourceKey
func NewResourceKey ¶
func NewResourceKey(group string, kind string, namespace string, name string) ResourceKey
func (ResourceKey) GroupKind ¶
func (k ResourceKey) GroupKind() schema.GroupKind
func (*ResourceKey) String ¶
func (k *ResourceKey) String() string
type ResourceOperations ¶ added in v0.4.0
type ResourceOperations interface { ApplyResource(ctx context.Context, obj *unstructured.Unstructured, dryRunStrategy cmdutil.DryRunStrategy, force, validate, serverSideApply bool) (string, error) ReplaceResource(ctx context.Context, obj *unstructured.Unstructured, dryRunStrategy cmdutil.DryRunStrategy, force bool) (string, error) CreateResource(ctx context.Context, obj *unstructured.Unstructured, dryRunStrategy cmdutil.DryRunStrategy, validate bool) (string, error) UpdateResource(ctx context.Context, obj *unstructured.Unstructured, dryRunStrategy cmdutil.DryRunStrategy) (*unstructured.Unstructured, error) }
ResourceOperations provides methods to manage k8s resources