kube

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 15, 2020 License: Apache-2.0 Imports: 55 Imported by: 63

Documentation

Overview

Package kube provides helper utilities common for kubernetes

Index

Constants

View Source
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"
)

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 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(action func() error, desc string, ctx context.Context, timeout time.Duration)

RetryUntilSucceed keep retrying given action with specified timeout until action succeed or specified context is done.

func RunAllAsync

func RunAllAsync(count int, action func(i int) error) (err error)

func SplitYAML

func SplitYAML(out string) ([]*unstructured.Unstructured, error)

SplitYAML splits a YAML file into unstructured objects. Returns list of all unstructured objects found in the yaml. If any errors occurred, returns the first one

func TestConfig

func TestConfig(config *rest.Config) error

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

func Version

func Version() (string, error)

func WatchWithRetry

func WatchWithRetry(ctx context.Context, getWatch func() (watch.Interface, error)) chan struct {
	*watch.Event
	Error error
}

WatchWithRetry returns channel of watch events or errors of failed to call watch API.

func WriteKubeConfig

func WriteKubeConfig(restConfig *rest.Config, namespace, filename string) error

WriteKubeConfig takes a rest.Config and writes it as a kubeconfig at the specified path

Types

type APIResourceInfo

type APIResourceInfo struct {
	GroupKind            schema.GroupKind
	Meta                 metav1.APIResource
	GroupVersionResource schema.GroupVersionResource
}

type Kubectl

type Kubectl interface {
	ApplyResource(config *rest.Config, obj *unstructured.Unstructured, namespace string, dryRun, force, validate bool) (string, error)
	ConvertToVersion(obj *unstructured.Unstructured, group, version string) (*unstructured.Unstructured, error)
	DeleteResource(config *rest.Config, gvk schema.GroupVersionKind, name string, namespace string, forceDelete bool) error
	GetResource(config *rest.Config, gvk schema.GroupVersionKind, name string, namespace string) (*unstructured.Unstructured, error)
	PatchResource(config *rest.Config, gvk schema.GroupVersionKind, name string, namespace string, patchType types.PatchType, patchBytes []byte) (*unstructured.Unstructured, error)
	GetAPIResources(config *rest.Config, resourceFilter ResourceFilter) ([]APIResourceInfo, error)
	GetAPIGroups(config *rest.Config) ([]metav1.APIGroup, error)
	GetServerVersion(config *rest.Config) (string, error)
	NewDynamicClient(config *rest.Config) (dynamic.Interface, error)
	SetOnKubectlRun(onKubectlRun func(command string) (io.Closer, error))
}

type KubectlCmd

type KubectlCmd struct {
	OnKubectlRun func(command string) (io.Closer, error)
}

func (*KubectlCmd) ApplyResource

func (k *KubectlCmd) ApplyResource(config *rest.Config, obj *unstructured.Unstructured, namespace string, dryRun, force, validate bool) (string, error)

ApplyResource performs an apply of a unstructured resource

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(config *rest.Config, gvk schema.GroupVersionKind, name string, namespace string, forceDelete bool) error

DeleteResource deletes resource

func (*KubectlCmd) GetAPIGroups

func (k *KubectlCmd) GetAPIGroups(config *rest.Config) ([]metav1.APIGroup, error)

func (*KubectlCmd) GetAPIResources

func (k *KubectlCmd) GetAPIResources(config *rest.Config, resourceFilter ResourceFilter) ([]APIResourceInfo, error)

func (*KubectlCmd) GetResource

func (k *KubectlCmd) GetResource(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) NewDynamicClient

func (k *KubectlCmd) NewDynamicClient(config *rest.Config) (dynamic.Interface, error)

func (*KubectlCmd) PatchResource

func (k *KubectlCmd) PatchResource(config *rest.Config, gvk schema.GroupVersionKind, name string, namespace string, patchType types.PatchType, patchBytes []byte) (*unstructured.Unstructured, error)

PatchResource patches resource

func (*KubectlCmd) SetOnKubectlRun

func (k *KubectlCmd) SetOnKubectlRun(onKubectlRun func(command string) (io.Closer, error))

type ResourceFilter

type ResourceFilter interface {
	IsExcludedResource(group, kind, cluster string) bool
}

type ResourceInfoProvider

type ResourceInfoProvider interface {
	IsNamespaced(gk schema.GroupKind) (bool, error)
}

type ResourceKey

type ResourceKey struct {
	Group     string
	Kind      string
	Namespace string
	Name      string
}

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL