Documentation ¶
Overview ¶
Package kube provides helper utilities common for kubernetes
Index ¶
- Constants
- func DeleteResourcesWithLabel(config *rest.Config, namespace string, labelName string, labelValue string) error
- func FlushServerResourcesCache()
- func GetCachedServerResources(host string, disco discovery.DiscoveryInterface) ([]*metav1.APIResourceList, error)
- func GetLiveResource(dynamicIf dynamic.Interface, obj *unstructured.Unstructured, ...) (*unstructured.Unstructured, error)
- func GetResourcesWithLabel(config *rest.Config, namespace string, labelName string, labelValue string) ([]*unstructured.Unstructured, error)
- func IsCRD(obj *unstructured.Unstructured) bool
- func IsCRDGroupVersionKind(gvk schema.GroupVersionKind) bool
- func ListResources(dynamicIf dynamic.Interface, apiResource metav1.APIResource, namespace string, ...) ([]*unstructured.Unstructured, error)
- func MustToUnstructured(obj interface{}) *unstructured.Unstructured
- func Remarshal(obj *unstructured.Unstructured) (*unstructured.Unstructured, error)
- func ServerResourceForGroupVersionKind(disco discovery.DiscoveryInterface, gvk schema.GroupVersionKind) (*metav1.APIResource, error)
- func SetLabel(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 WatchResourcesWithLabel(ctx context.Context, config *rest.Config, namespace string, labelName string) (chan watch.Event, error)
- func WriteKubeConfig(restConfig *rest.Config, namespace, filename string) error
- 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, obj *unstructured.Unstructured, namespace string) error
- func (k KubectlCmd) WatchResources(ctx context.Context, config *rest.Config, namespace string, ...) (chan watch.Event, error)
Constants ¶
const ( SecretKind = "Secret" ServiceKind = "Service" EndpointsKind = "Endpoints" DeploymentKind = "Deployment" ReplicaSetKind = "ReplicaSet" StatefulSetKind = "StatefulSet" DaemonSetKind = "DaemonSet" IngressKind = "Ingress" PersistentVolumeClaimKind = "PersistentVolumeClaim" CustomResourceDefinitionKind = "CustomResourceDefinition" )
Variables ¶
This section is empty.
Functions ¶
func DeleteResourcesWithLabel ¶ added in v0.10.5
func DeleteResourcesWithLabel(config *rest.Config, namespace string, labelName string, labelValue string) error
DeleteResourcesWithLabel delete all resources which match to specified label selector
func FlushServerResourcesCache ¶ added in v0.9.0
func FlushServerResourcesCache()
func GetCachedServerResources ¶ added in v0.4.0
func GetCachedServerResources(host string, disco discovery.DiscoveryInterface) ([]*metav1.APIResourceList, error)
GetCachedServerResources discovers API resources supported by a Kube API server. Caches the results for apiResourceCacheDuration (per host)
func GetLiveResource ¶
func GetLiveResource(dynamicIf dynamic.Interface, obj *unstructured.Unstructured, apiResource *metav1.APIResource, namespace string) (*unstructured.Unstructured, error)
GetLiveResource returns the corresponding live resource from a unstructured object
func GetResourcesWithLabel ¶ added in v0.3.0
func GetResourcesWithLabel(config *rest.Config, namespace string, labelName string, labelValue string) ([]*unstructured.Unstructured, error)
GetResourcesWithLabel returns all kubernetes resources with specified label
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 ListResources ¶
func ListResources(dynamicIf dynamic.Interface, apiResource metav1.APIResource, namespace string, listOpts metav1.ListOptions) ([]*unstructured.Unstructured, error)
ListResources returns a list of resources of a particular API type using the dynamic client
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 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 SetLabel ¶ added in v0.5.3
func SetLabel(target *unstructured.Unstructured, key, val string) error
SetLabel sets our app labels against an unstructured object
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
func WatchResourcesWithLabel ¶ added in v0.3.0
Types ¶
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, obj *unstructured.Unstructured, namespace string) error WatchResources(ctx context.Context, config *rest.Config, namespace string, selector func(kind schema.GroupVersionKind) metav1.ListOptions) (chan watch.Event, 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, obj *unstructured.Unstructured, namespace string) error
DeleteResource deletes resource
func (KubectlCmd) WatchResources ¶ added in v0.10.0
func (k KubectlCmd) WatchResources( ctx context.Context, config *rest.Config, namespace string, selector func(kind schema.GroupVersionKind) metav1.ListOptions, ) (chan watch.Event, error)
WatchResources Watches all the existing resources with the provided label name in the provided namespace in the cluster provided by the config