Documentation ¶
Index ¶
- Variables
- type Handler
- func (h *Handler) Apply(obj interface{}) (*unstructured.Unstructured, error)
- func (h *Handler) ApplyFromBytes(data []byte) (*unstructured.Unstructured, error)
- func (h *Handler) ApplyFromFile(filename string) (*unstructured.Unstructured, error)
- func (h *Handler) ApplyFromMap(obj map[string]interface{}) (*unstructured.Unstructured, error)
- func (h *Handler) ApplyFromObject(obj runtime.Object) (*unstructured.Unstructured, error)
- func (h *Handler) Create(obj interface{}) (*unstructured.Unstructured, error)
- func (h *Handler) CreateFromBytes(data []byte) (*unstructured.Unstructured, error)
- func (h *Handler) CreateFromFile(filename string) (*unstructured.Unstructured, error)
- func (h *Handler) CreateFromMap(obj map[string]interface{}) (*unstructured.Unstructured, error)
- func (h *Handler) CreateFromObject(obj runtime.Object) (*unstructured.Unstructured, error)
- func (in *Handler) DeepCopy() *Handler
- func (h *Handler) Delete(obj interface{}) error
- func (h *Handler) DeleteByName(name string) error
- func (h *Handler) DeleteFromBytes(data []byte) error
- func (h *Handler) DeleteFromFile(filename string) error
- func (h *Handler) DeleteFromMap(obj map[string]interface{}) error
- func (h *Handler) DeleteFromObject(obj runtime.Object) error
- func (h *Handler) DynamicClient() dynamic.Interface
- func (h *Handler) Get(obj interface{}) (*unstructured.Unstructured, error)
- func (h *Handler) GetByName(name string) (*unstructured.Unstructured, error)
- func (h *Handler) GetFromBytes(data []byte) (*unstructured.Unstructured, error)
- func (h *Handler) GetFromFile(filename string) (*unstructured.Unstructured, error)
- func (h *Handler) GetFromMap(obj map[string]interface{}) (*unstructured.Unstructured, error)
- func (h *Handler) GetFromObject(obj runtime.Object) (*unstructured.Unstructured, error)
- func (h *Handler) InformerFactory() dynamicinformer.DynamicSharedInformerFactory
- func (h *Handler) List() ([]*unstructured.Unstructured, error)
- func (h *Handler) ListAll() ([]*unstructured.Unstructured, error)
- func (h *Handler) ListByField(field string) ([]*unstructured.Unstructured, error)
- func (h *Handler) ListByLabel(labels string) ([]*unstructured.Unstructured, error)
- func (h *Handler) ListByNamespace(namespace string) ([]*unstructured.Unstructured, error)
- func (h *Handler) SetForceDelete(force bool)
- func (h *Handler) SetInformerFactoryNamespace(namespace string)
- func (h *Handler) SetInformerFactoryResyncPeriod(resyncPeriod time.Duration)
- func (h *Handler) SetInformerFactoryTweakListOptions(tweakListOptions dynamicinformer.TweakListOptionsFunc)
- func (h *Handler) SetLimit(limit int64)
- func (h *Handler) SetPropagationPolicy(policy string)
- func (h *Handler) SetTimeout(timeout int64)
- func (h *Handler) Update(obj interface{}) (*unstructured.Unstructured, error)
- func (h *Handler) UpdateFromBytes(data []byte) (*unstructured.Unstructured, error)
- func (h *Handler) UpdateFromFile(filename string) (*unstructured.Unstructured, error)
- func (h *Handler) UpdateFromMap(obj map[string]interface{}) (*unstructured.Unstructured, error)
- func (h *Handler) UpdateFromObject(obj runtime.Object) (*unstructured.Unstructured, error)
- func (h *Handler) Watch(addFunc, modifyFunc, deleteFunc func(obj interface{})) error
- func (h *Handler) WatchByField(field string, addFunc, modifyFunc, deleteFunc func(obj interface{})) error
- func (h *Handler) WatchByLabel(labels string, addFunc, modifyFunc, deleteFunc func(obj interface{})) error
- func (h *Handler) WatchByName(name string, addFunc, modifyFunc, deleteFunc func(obj interface{})) error
- func (h *Handler) WatchByNamespace(namespace string, addFunc, modifyFunc, deleteFunc func(obj interface{})) error
- func (h *Handler) WithDryRun() *Handler
- func (h *Handler) WithGVK(gvk schema.GroupVersionKind) *Handler
- func (h *Handler) WithNamespace(namespace string) *Handler
Constants ¶
This section is empty.
Variables ¶
var ( ErrGroupEmpty = errors.New("group must not be empty") ErrVersionEmpty = errors.New("version must not be empty") ErrResourceEmpty = errors.New("resource must not be empty") ErrInvalidType = errors.New("type must be string, []byte, runtime.Object, *unstructured.Unstructured, unstructured.Unstructured or map[string]interface{}") )
Functions ¶
This section is empty.
Types ¶
type Handler ¶
type Handler struct { Options *types.HandlerOptions // contains filtered or unexported fields }
Note: when you delete/get/list k8s resource and the parameter passed to Delete()/Get()/List()/Watch() is a k8s resource name, you should always call WithGVK() to specify the GVK explicitly.
func New ¶
New creates a Handler object from kubeconfig or in-cluster config.
The kubeconfig precedence is: * kubeconfig variable passed. * KUBECONFIG environment variable pointing at a file. * $HOME/.kube/config if exists. * In-cluster config if running in cluster.
func (*Handler) Apply ¶
func (h *Handler) Apply(obj interface{}) (*unstructured.Unstructured, error)
Apply applies unstructured k8s resource from type string, []byte, runtime.Object, *unstructured.Unstructured, unstructured.Unstructured or map[string]interface{}.
It's not necessary to explicitly specify the GVK or GVR by calling WithGVK(), Apply() will find the GVK and GVR by RESTMapper and apply the k8s resource that defined in yaml file, json file, bytes data, map[string]interface{} or runtime.Object.
func (*Handler) ApplyFromBytes ¶
func (h *Handler) ApplyFromBytes(data []byte) (*unstructured.Unstructured, error)
ApplyFromBytes applies unstructured k8s resource from bytes.
func (*Handler) ApplyFromFile ¶
func (h *Handler) ApplyFromFile(filename string) (*unstructured.Unstructured, error)
ApplyFromFile applies unstructured k8s resource from yaml file.
func (*Handler) ApplyFromMap ¶
func (h *Handler) ApplyFromMap(obj map[string]interface{}) (*unstructured.Unstructured, error)
ApplyFromMap applies unstructured k8s resource from map[string]interface{}.
func (*Handler) ApplyFromObject ¶
func (h *Handler) ApplyFromObject(obj runtime.Object) (*unstructured.Unstructured, error)
ApplyFromObject applies unstructured k8s resource from runtime.Object.
func (*Handler) Create ¶
func (h *Handler) Create(obj interface{}) (*unstructured.Unstructured, error)
Create creates unstructured k8s resource from type string, []byte, runtime.Object, *unstructured.Unstructured, unstructured.Unstructured or map[string]interface{}.
It's not necessary to explicitly specify the GVK or GVR by calling WithGVK(), Create() will find the GVK and GVR by RESTMapper and create the k8s resource that defined in yaml file, json file, bytes data, map[string]interface{} or runtime.Object.
func (*Handler) CreateFromBytes ¶
func (h *Handler) CreateFromBytes(data []byte) (*unstructured.Unstructured, error)
CreateFromBytes creates unstructured k8s resource from bytes.
func (*Handler) CreateFromFile ¶
func (h *Handler) CreateFromFile(filename string) (*unstructured.Unstructured, error)
CreateFromFile creates unstructured k8s resource from yaml file.
func (*Handler) CreateFromMap ¶
func (h *Handler) CreateFromMap(obj map[string]interface{}) (*unstructured.Unstructured, error)
CreateFromMap creates unstructured k8s resource from map[string]interface{}.
func (*Handler) CreateFromObject ¶
func (h *Handler) CreateFromObject(obj runtime.Object) (*unstructured.Unstructured, error)
CreateFromObject creates unstructured k8s resource from runtime.Object.
func (*Handler) Delete ¶
Delete deletes unstructured k8s resource from type string, []byte, runtime.Object, *unstructured.Unstructured, unstructured.Unstructured or map[string]interface{}.
If psssed parameter type is string, it will call DeleteByName insteard of DeleteFromFile. You should always explicitly call DeleteFromFile to delete a unstructured object from filename.
DeleteByName requires WithGVK() to explicitly specify the k8s resource's GroupVersionKind. DeleteFromFile, DeleteFromBytes and DeleteFromMap will find GVK and GVR from the provided structured or unstructured data, it's not reuqired to call WithGVK().
func (*Handler) DeleteByName ¶
DeleteByName deletes unstructured k8s resource with given name.
func (*Handler) DeleteFromBytes ¶
DeleteFromBytes deletes unstructured k8s resource from bytes.
func (*Handler) DeleteFromFile ¶
DeleteFromFile deletes unstructured k8s resource from yaml file.
func (*Handler) DeleteFromMap ¶
DeleteFromMap deletes unstructured k8s resource from map[string]interface{}.
func (*Handler) DeleteFromObject ¶
DeleteFromObject deletes unstructured k8s resource from runtime.Object.
func (*Handler) DynamicClient ¶
DynamicClient returns the underlying dynamic client used by this dynamic handler.
func (*Handler) Get ¶
func (h *Handler) Get(obj interface{}) (*unstructured.Unstructured, error)
Get gets unstructured k8s resource from type string, []byte, runtime.Object, *unstructured.Unstructured, unstructured.Unstructured or map[string]interface{}.
If psssed parameter type is string, it will call GetByName insteard of GetFromFile. You should always explicitly call GetFromFile to delete a unstructured object from filename.
GetByName requires WithGVK() to explicitly specify the k8s resource's GroupVersionKind. GetFromFile, GetFromBytes and GetFromMap will find GVK and GVR from the provided structured or unstructured data, it's not reuqired to call WithGVK().
func (*Handler) GetByName ¶
func (h *Handler) GetByName(name string) (*unstructured.Unstructured, error)
GetByName gets unstructured k8s resource with given name.
func (*Handler) GetFromBytes ¶
func (h *Handler) GetFromBytes(data []byte) (*unstructured.Unstructured, error)
GetFromBytes gets unstructured k8s resource from bytes.
func (*Handler) GetFromFile ¶
func (h *Handler) GetFromFile(filename string) (*unstructured.Unstructured, error)
GetFromFile gets unstructured k8s resource from yaml file.
func (*Handler) GetFromMap ¶
func (h *Handler) GetFromMap(obj map[string]interface{}) (*unstructured.Unstructured, error)
GetFromMap gets unstructured k8s resource from map[string]interface{}.
func (*Handler) GetFromObject ¶
func (h *Handler) GetFromObject(obj runtime.Object) (*unstructured.Unstructured, error)
GetFromObject gets unstructured k8s resource from runtime.Object.
func (*Handler) InformerFactory ¶ added in v0.10.4
func (h *Handler) InformerFactory() dynamicinformer.DynamicSharedInformerFactory
InformerFactory returns underlying DyanmicSharedInformerFactory which provides access to a shared informer and lister for dynamic client
func (*Handler) List ¶
func (h *Handler) List() ([]*unstructured.Unstructured, error)
List list all k8s objects in the k8s cluster, it simply call `ListAll`.
func (*Handler) ListAll ¶ added in v0.7.0
func (h *Handler) ListAll() ([]*unstructured.Unstructured, error)
ListAll list all k8s objects in the k8s cluster. Calling this method requires WithGVK() to explicitly specify GVK.
func (*Handler) ListByField ¶ added in v0.7.0
func (h *Handler) ListByField(field string) ([]*unstructured.Unstructured, error)
ListByField list k8s objects by field, work like `kubectl get xxx --field-selector=xxx`. Calling this method requires WithGVK() to explicitly specify GVK.
func (*Handler) ListByLabel ¶ added in v0.7.0
func (h *Handler) ListByLabel(labels string) ([]*unstructured.Unstructured, error)
ListByLabel list k8s objects by labels. Multiple labels separated by comma(",") eg: "name=myapp,role=devops", and there is an "And" relationship between multiple labels. Calling this method requires WithGVK() to explicitly specify GVK.
func (*Handler) ListByNamespace ¶ added in v0.7.0
func (h *Handler) ListByNamespace(namespace string) ([]*unstructured.Unstructured, error)
ListByNamespace list all k8s objects in the specified namespace. It will return empty slice and error if this k8s object is cluster scope. Calling this method requires WithGVK() to explicitly specify GVK.
func (*Handler) SetForceDelete ¶ added in v0.11.0
SetForceDelete
func (*Handler) SetInformerFactoryNamespace ¶ added in v0.10.4
SetInformerFactoryNamespace limit the scope of informer list-and-watch k8s resource. informer list-and-watch all namespace k8s resource by default.
func (*Handler) SetInformerFactoryResyncPeriod ¶ added in v0.10.4
SetInformerFactoryResyncPeriod will set informer resync period.
func (*Handler) SetInformerFactoryTweakListOptions ¶ added in v0.10.4
func (h *Handler) SetInformerFactoryTweakListOptions(tweakListOptions dynamicinformer.TweakListOptionsFunc)
SetInformerFactoryTweakListOptions sets a custom filter on all listers of the configured SharedInformerFactory.
func (*Handler) SetPropagationPolicy ¶ added in v0.11.0
SetPropagationPolicy will set the PropagationPolicy. If we delete job or/and cronjob, we should always set the PropagationPolicy to DeletePropagationBackground to delete all pods managed by that job or/and cronjob. Default to "DeletePropagationBackground" to job and/or cronjob.
func (*Handler) SetTimeout ¶ added in v0.11.0
SetTimeout
func (*Handler) Update ¶
func (h *Handler) Update(obj interface{}) (*unstructured.Unstructured, error)
Update updates unstructured k8s resource from type string, []byte, runtime.Object, *unstructured.Unstructured, unstructured.Unstructured or map[string]interface{}.
It's not necessary to explicitly specify the GVK or GVR by calling WithGVK(), Update() will find the GVK and GVR by RESTMapper and update the k8s resource that defined in yaml file, json file, bytes data, map[string]interface{} or runtime.Object.
func (*Handler) UpdateFromBytes ¶
func (h *Handler) UpdateFromBytes(data []byte) (*unstructured.Unstructured, error)
UpdateFromBytes updates unstructured k8s resource from bytes.
func (*Handler) UpdateFromFile ¶
func (h *Handler) UpdateFromFile(filename string) (*unstructured.Unstructured, error)
UpdateFromFile updates unstructured k8s resource from yaml file.
func (*Handler) UpdateFromMap ¶
func (h *Handler) UpdateFromMap(obj map[string]interface{}) (*unstructured.Unstructured, error)
UpdateFromMap updates unstructured k8s resource from map[string]interface{}.
func (*Handler) UpdateFromObject ¶
func (h *Handler) UpdateFromObject(obj runtime.Object) (*unstructured.Unstructured, error)
UpdateFromObject updates unstructured k8s resource from runtime.Object.
func (*Handler) Watch ¶ added in v0.11.0
Watch watch all k8s resource with the specified kind. You should always specify the GroupVersionKind with WithGVK() method.
Object as the parameter of addFunc, modifyFunc, deleteFunc:
- If Event.Type is Added or Modified: the new state of the object.
- If Event.Type is Deleted: the state of the object immediately before deletion.
- If Event.Type is Bookmark: the object (instance of a type being watched) where only ResourceVersion field is set. On successful restart of watch from a bookmark resourceVersion, client is guaranteed to not get repeat event nor miss any events.
- If Event.Type is Error: *api.Status is recommended; other types may make sense depending on context.
func (*Handler) WatchByField ¶ added in v0.11.0
func (h *Handler) WatchByField(field string, addFunc, modifyFunc, deleteFunc func(obj interface{})) error
WatchByField watch a single or multiple k8s resources with specified Kind and selected by the field. You should always specify the GroupVersionKind with WithGVK() method.
Object as the parameter of addFunc, modifyFunc, deleteFunc:
- If Event.Type is Added or Modified: the new state of the object.
- If Event.Type is Deleted: the state of the object immediately before deletion.
- If Event.Type is Bookmark: the object (instance of a type being watched) where only ResourceVersion field is set. On successful restart of watch from a bookmark resourceVersion, client is guaranteed to not get repeat event nor miss any events.
- If Event.Type is Error: *api.Status is recommended; other types may make sense depending on context.
func (*Handler) WatchByLabel ¶ added in v0.11.0
func (h *Handler) WatchByLabel(labels string, addFunc, modifyFunc, deleteFunc func(obj interface{})) error
WatchByLabel watch a single or multiple k8s resource with the specified Kind and selected by the labels. Multiple labels are separated by ",", label key and value conjunctaed by "=". You should always specify the GroupVersionKind with WithGVK() method.
Object as the parameter of addFunc, modifyFunc, deleteFunc:
- If Event.Type is Added or Modified: the new state of the object.
- If Event.Type is Deleted: the state of the object immediately before deletion.
- If Event.Type is Bookmark: the object (instance of a type being watched) where only ResourceVersion field is set. On successful restart of watch from a bookmark resourceVersion, client is guaranteed to not get repeat event nor miss any events.
- If Event.Type is Error: *api.Status is recommended; other types may make sense depending on context.
func (*Handler) WatchByName ¶ added in v0.11.0
func (h *Handler) WatchByName(name string, addFunc, modifyFunc, deleteFunc func(obj interface{})) error
WatchByName watch a single k8s resource with the specified Kind. You should always specify the GroupVersionKind with WithGVK() method.
Object as the parameter of addFunc, modifyFunc, deleteFunc:
- If Event.Type is Added or Modified: the new state of the object.
- If Event.Type is Deleted: the state of the object immediately before deletion.
- If Event.Type is Bookmark: the object (instance of a type being watched) where only ResourceVersion field is set. On successful restart of watch from a bookmark resourceVersion, client is guaranteed to not get repeat event nor miss any events.
- If Event.Type is Error: *api.Status is recommended; other types may make sense depending on context.
func (*Handler) WatchByNamespace ¶ added in v0.11.0
func (h *Handler) WatchByNamespace(namespace string, addFunc, modifyFunc, deleteFunc func(obj interface{})) error
WatchByNamespace watch all k8s resource with the specified kind in the specified namespace. You should always specify the GroupVersionKind with WithGVK() method.
Object as the parameter of addFunc, modifyFunc, deleteFunc:
- If Event.Type is Added or Modified: the new state of the object.
- If Event.Type is Deleted: the state of the object immediately before deletion.
- If Event.Type is Bookmark: the object (instance of a type being watched) where only ResourceVersion field is set. On successful restart of watch from a bookmark resourceVersion, client is guaranteed to not get repeat event nor miss any events.
- If Event.Type is Error: *api.Status is recommended; other types may make sense depending on context.
func (*Handler) WithDryRun ¶ added in v0.11.0
WithDryRun deep copies a new handler and prints the create/update/apply/delete operations, without sending it to apiserver.
func (*Handler) WithGVK ¶ added in v0.11.0
func (h *Handler) WithGVK(gvk schema.GroupVersionKind) *Handler
WithGVK returns the same handler but with provided group, version and resource.
func (*Handler) WithNamespace ¶ added in v0.7.0
WithNamespace returns the same handler but with provided namespace. If the k8s resource is namespace scope, it will create/delete/update/apply k8s resource in the new namespace. If the k8s resource is cluster scope, it will ignore the namespace.
But the namespace defined in yaml file have higher precedence than namespace specified here.
If no namespace is defined in yaml file and no namespace is specified using WithNamespace() method, then the namespace default to metav1.NamespaceDefault("default").
namespace precedence: * namespace defined in yaml file or json file. * namespace specified by WithNamespace() method. * namespace specified in dynamic.New() or dynamic.NewOrDie() funciton. * namespace will be ignored if k8s resource is cluster scope.