Documentation ¶
Overview ¶
Package kube provides helper utilities common for kubernetes
Index ¶
- Constants
- func GetAppInstanceLabel(un *unstructured.Unstructured, key string) string
- func IsCRD(obj *unstructured.Unstructured) bool
- func IsCRDGroupVersionKind(gvk schema.GroupVersionKind) bool
- func MustToUnstructured(obj interface{}) *unstructured.Unstructured
- func NewKubeConfig(restConfig *rest.Config, namespace string) *clientcmdapi.Config
- func Remarshal(obj *unstructured.Unstructured) (*unstructured.Unstructured, error)
- func ServerResourceForGroupVersionKind(disco discovery.DiscoveryInterface, gvk schema.GroupVersionKind) (*metav1.APIResource, error)
- func SetAppInstanceLabel(target *unstructured.Unstructured, key, val string) error
- func SplitYAML(out string) ([]*unstructured.Unstructured, 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 CacheRefreshEvent
- type CachedVersionSource
- type Kubectl
- type KubectlCmd
- func (k KubectlCmd) ApplyResource(config *rest.Config, obj *unstructured.Unstructured, namespace string, ...) (string, error)
- func (k KubectlCmd) ConvertToVersion(obj *unstructured.Unstructured, group, version string) (*unstructured.Unstructured, error)
- func (k KubectlCmd) DeleteResource(config *rest.Config, gvk schema.GroupVersionKind, name string, ...) error
- func (k KubectlCmd) GetAPIResources(config *rest.Config) ([]*metav1.APIResourceList, error)
- func (k KubectlCmd) GetResource(config *rest.Config, gvk schema.GroupVersionKind, name string, ...) (*unstructured.Unstructured, error)
- func (k KubectlCmd) GetResources(config *rest.Config, resourceFilter ResourceFilter, namespace string) (chan ResourcesBatch, error)
- func (k KubectlCmd) PatchResource(config *rest.Config, gvk schema.GroupVersionKind, name string, ...) (*unstructured.Unstructured, error)
- func (k KubectlCmd) WatchResources(ctx context.Context, config *rest.Config, resourceFilter ResourceFilter, ...) (chan WatchEvent, error)
- type ResourceFilter
- type ResourceKey
- type ResourcesBatch
- type WatchEvent
Constants ¶
const ( SecretKind = "Secret" ServiceKind = "Service" EndpointsKind = "Endpoints" DeploymentKind = "Deployment" ReplicaSetKind = "ReplicaSet" StatefulSetKind = "StatefulSet" DaemonSetKind = "DaemonSet" IngressKind = "Ingress" JobKind = "Job" PersistentVolumeClaimKind = "PersistentVolumeClaim" CustomResourceDefinitionKind = "CustomResourceDefinition" PodKind = "Pod" NetworkPolicyKind = "NetworkPolicy" PodSecurityPolicyKind = "PodSecurityPolicy" )
Variables ¶
This section is empty.
Functions ¶
func GetAppInstanceLabel ¶ added in v0.11.0
func GetAppInstanceLabel(un *unstructured.Unstructured, key string) string
GetAppInstanceLabel returns the application instance name from labels
func IsCRD ¶ added in v0.9.0
func IsCRD(obj *unstructured.Unstructured) bool
func IsCRDGroupVersionKind ¶ added in v0.9.0
func IsCRDGroupVersionKind(gvk schema.GroupVersionKind) 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 ¶ added in v0.10.6
func NewKubeConfig(restConfig *rest.Config, namespace string) *clientcmdapi.Config
NewKubeConfig converts a clientcmdapi.Config (kubeconfig) from a rest.Config
func Remarshal ¶ added in v0.9.0
func Remarshal(obj *unstructured.Unstructured) (*unstructured.Unstructured, error)
Remarshal checks resource kind and version and re-marshal using corresponding struct custom marshaller. This ensures that expected resource state is formatter same as actual resource state in kubernetes and allows to find differences between actual and target states more accurately.
func ServerResourceForGroupVersionKind ¶
func ServerResourceForGroupVersionKind(disco discovery.DiscoveryInterface, gvk schema.GroupVersionKind) (*metav1.APIResource, error)
See: https://github.com/ksonnet/ksonnet/blob/master/utils/client.go
func SetAppInstanceLabel ¶ added in v0.11.0
func SetAppInstanceLabel(target *unstructured.Unstructured, key, val string) error
SetAppInstanceLabel the recommended app.kubernetes.io/instance label against an unstructured object Uses the legacy labeling if environment variable is set
func SplitYAML ¶ added in v0.7.0
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 ¶
TestConfig tests to make sure the REST config is usable
func ToGroupVersionResource ¶ added in v0.10.5
func ToGroupVersionResource(groupVersion string, apiResource *metav1.APIResource) schema.GroupVersionResource
func ToResourceInterface ¶ added in v0.10.5
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 ¶ added in v0.8.0
func UnsetLabel(target *unstructured.Unstructured, key string)
UnsetLabel removes our app labels from an unstructured object
Types ¶
type CacheRefreshEvent ¶
type CacheRefreshEvent struct { GVK schema.GroupVersionKind ResourceVersion string Objects []unstructured.Unstructured }
type Kubectl ¶ added in v0.9.0
type Kubectl interface { ApplyResource(config *rest.Config, obj *unstructured.Unstructured, namespace string, dryRun, force 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) WatchResources(ctx context.Context, config *rest.Config, resourceFilter ResourceFilter, versionSource CachedVersionSource) (chan WatchEvent, error) GetResources(config *rest.Config, resourceFilter ResourceFilter, namespace string) (chan ResourcesBatch, error) GetAPIResources(config *rest.Config) ([]*metav1.APIResourceList, error) }
type KubectlCmd ¶ added in v0.9.0
type KubectlCmd struct{}
func (KubectlCmd) ApplyResource ¶ added in v0.9.0
func (k KubectlCmd) ApplyResource(config *rest.Config, obj *unstructured.Unstructured, namespace string, dryRun, force bool) (string, error)
ApplyResource performs an apply of a unstructured resource
func (KubectlCmd) ConvertToVersion ¶ added in v0.9.0
func (k KubectlCmd) ConvertToVersion(obj *unstructured.Unstructured, group, version string) (*unstructured.Unstructured, error)
ConvertToVersion converts an unstructured object into the specified group/version
func (KubectlCmd) DeleteResource ¶ added in v0.9.0
func (k KubectlCmd) DeleteResource(config *rest.Config, gvk schema.GroupVersionKind, name string, namespace string, forceDelete bool) error
DeleteResource deletes resource
func (KubectlCmd) GetAPIResources ¶ added in v0.11.0
func (k KubectlCmd) GetAPIResources(config *rest.Config) ([]*metav1.APIResourceList, error)
func (KubectlCmd) GetResource ¶ added in v0.11.0
func (k KubectlCmd) GetResource(config *rest.Config, gvk schema.GroupVersionKind, name string, namespace string) (*unstructured.Unstructured, error)
GetResource returns resource
func (KubectlCmd) GetResources ¶ added in v0.11.0
func (k KubectlCmd) GetResources(config *rest.Config, resourceFilter ResourceFilter, namespace string) (chan ResourcesBatch, error)
GetResources returns all kubernetes resources
func (KubectlCmd) PatchResource ¶ added in v0.12.0
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) WatchResources ¶ added in v0.10.0
func (k KubectlCmd) WatchResources( ctx context.Context, config *rest.Config, resourceFilter ResourceFilter, versionSource CachedVersionSource, ) (chan WatchEvent, error)
WatchResources watches all the existing resources in the cluster provided by the config. Method retries watch with the most recent resource version stored in cache. The WatchResources returns channel which container either watch event with updated resource info or new list of resources if cached resource version had expired.
type ResourceFilter ¶ added in v0.12.0
type ResourceKey ¶ added in v0.11.0
func GetResourceKey ¶ added in v0.11.0
func GetResourceKey(obj *unstructured.Unstructured) ResourceKey
func NewResourceKey ¶ added in v0.11.0
func NewResourceKey(group string, kind string, namespace string, name string) ResourceKey
func (*ResourceKey) String ¶ added in v0.11.0
func (k *ResourceKey) String() string
type ResourcesBatch ¶
type ResourcesBatch struct { GVK schema.GroupVersionKind ResourceInfo metav1.APIResource ListResourceVersion string Objects []unstructured.Unstructured Error error }
type WatchEvent ¶
type WatchEvent struct { WatchEvent *watch.Event CacheRefresh *CacheRefreshEvent }