job

package
v0.12.4 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2022 License: Apache-2.0 Imports: 35 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidToolsType  = errors.New("type must be string, *batchv1.Job, batchv1.Job, metav1.Object or runtime.Object")
	ErrInvalidCreateType = errors.New("type must be string, []byte, *batchv1.Job, batchv1.Job, metav1.Object, runtime.Object, *unstructured.Unstructured, unstructured.Unstructured or map[string]interface{}")
	ErrInvalidUpdateType = ErrInvalidCreateType
	ErrInvalidApplyType  = ErrInvalidCreateType
	ErrInvalidDeleteType = ErrInvalidCreateType
	ErrInvalidGetType    = ErrInvalidCreateType
	ErrInvalidPatchType  = errors.New("patch data type must be string, []byte, *batchv1.Job, batchv1.Job, metav1.Object, runtime.Object, *unstructured.Unstructured, unstructured.Unstructured or map[string]interface{}")
)

GVK contains the Group, Version, Kind name of job.

GVR contains the Group, Version and Resource name of job.

View Source
var Group = GVK.Group

Group is the job Group name.

View Source
var Kind = GVK.Kind

Kind is the job Kind name.

View Source
var Resource = GVR.Resource

Resource is the job Resource name.

View Source
var Version = GVK.Version

Version is the job Version name.

Functions

This section is empty.

Types

type Handler

type Handler struct {
	Options *types.HandlerOptions
	// contains filtered or unexported fields
}

func New

func New(ctx context.Context, kubeconfig, namespace string) (*Handler, error)

New returns a job handler 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 NewOrDie added in v0.3.0

func NewOrDie(ctx context.Context, kubeconfig, namespace string) *Handler

NewOrDie simply call New() to get a job handler. panic if there is any error occurs.

func (*Handler) Apply

func (h *Handler) Apply(obj interface{}) (*batchv1.Job, error)

Apply applies job from type string, []byte, *batchv1.Job, batchv1.Job, metav1.Object, runtime.Object, *unstructured.Unstructured, unstructured.Unstructured or map[string]interface{}.

func (*Handler) ApplyFromBytes

func (h *Handler) ApplyFromBytes(data []byte) (job *batchv1.Job, err error)

ApplyFromBytes pply job from bytes data.

func (*Handler) ApplyFromFile

func (h *Handler) ApplyFromFile(filename string) (job *batchv1.Job, err error)

ApplyFromFile applies job from yaml or json file.

func (*Handler) ApplyFromMap added in v0.5.0

func (h *Handler) ApplyFromMap(u map[string]interface{}) (*batchv1.Job, error)

ApplyFromMap applies job from map[string]interface{}.

func (*Handler) ApplyFromObject added in v0.3.0

func (h *Handler) ApplyFromObject(obj interface{}) (*batchv1.Job, error)

ApplyFromObject applies job from metav1.Object or runtime.Object.

func (*Handler) ApplyFromUnstructured added in v0.3.0

func (h *Handler) ApplyFromUnstructured(u *unstructured.Unstructured) (*batchv1.Job, error)

ApplyFromUnstructured applies job from *unstructured.Unstructured.

func (*Handler) Clientset added in v0.2.0

func (h *Handler) Clientset() *kubernetes.Clientset

Clientset returns underlying clientset.

func (*Handler) Create

func (h *Handler) Create(obj interface{}) (*batchv1.Job, error)

Create creates job from type string, []byte, *batchv1.Job, batchv1.Job, metav1.Object, runtime.Object, *unstructured.Unstructured, unstructured.Unstructured or map[string]interface{}.

func (*Handler) CreateFromBytes

func (h *Handler) CreateFromBytes(data []byte) (*batchv1.Job, error)

CreateFromBytes creates job from bytes data.

func (*Handler) CreateFromFile

func (h *Handler) CreateFromFile(filename string) (*batchv1.Job, error)

CreateFromFile creates job from yaml or json file.

func (*Handler) CreateFromMap added in v0.5.0

func (h *Handler) CreateFromMap(u map[string]interface{}) (*batchv1.Job, error)

CreateFromMap creates job from map[string]interface{}.

func (*Handler) CreateFromObject added in v0.3.0

func (h *Handler) CreateFromObject(obj interface{}) (*batchv1.Job, error)

CreateFromObject creates job from metav1.Object or runtime.Object.

func (*Handler) CreateFromUnstructured added in v0.3.0

func (h *Handler) CreateFromUnstructured(u *unstructured.Unstructured) (*batchv1.Job, error)

CreateFromUnstructured creates job from *unstructured.Unstructured.

func (*Handler) DeepCopy

func (in *Handler) DeepCopy() *Handler

func (*Handler) Delete

func (h *Handler) Delete(obj interface{}) error

Delete deletes job from type string, []byte, *batchv1.Job, batchv1.Job, metav1.Object, runtime.Object, *unstructured.Unstructured, unstructured.Unstructured or map[string]interface{}.

If passed parameter type is string, it will simply call DeleteByName instead of DeleteFromFile. You should always explicitly call DeleteFromFile to delete a job from file path.

func (*Handler) DeleteByName

func (h *Handler) DeleteByName(name string) error

DeleteByName deletes job by name.

func (*Handler) DeleteFromBytes

func (h *Handler) DeleteFromBytes(data []byte) error

DeleteFromBytes deletes job from bytes data.

func (*Handler) DeleteFromFile

func (h *Handler) DeleteFromFile(filename string) error

DeleteFromFile deletes job from yaml or json file.

func (*Handler) DeleteFromMap added in v0.5.0

func (h *Handler) DeleteFromMap(u map[string]interface{}) error

DeleteFromMap deletes job from map[string]interface{}.

func (*Handler) DeleteFromObject added in v0.3.0

func (h *Handler) DeleteFromObject(obj interface{}) error

DeleteFromObject deletes job from metav1.Object or runtime.Object.

func (*Handler) DeleteFromUnstructured added in v0.3.0

func (h *Handler) DeleteFromUnstructured(u *unstructured.Unstructured) error

DeleteFromUnstructured deletes job from *unstructured.Unstructured.

func (*Handler) DiscoveryClient added in v0.2.0

func (h *Handler) DiscoveryClient() *discovery.DiscoveryClient

DiscoveryClient returns underlying discovery client.

func (*Handler) DurationOfCompleted added in v0.2.0

func (h *Handler) DurationOfCompleted(object interface{}) (time.Duration, error)

DurationOfCompletion returns the duration from job start time to now.

func (*Handler) DurationOfStarted added in v0.2.0

func (h *Handler) DurationOfStarted(object interface{}) (time.Duration, error)

DurationOfStarted returns the duration from job start time to now.

func (*Handler) DynamicClient added in v0.2.0

func (h *Handler) DynamicClient() dynamic.Interface

DynamicClient returns underlying dynamic client.

func (*Handler) Get

func (h *Handler) Get(obj interface{}) (*batchv1.Job, error)

Get gets job from type string, []byte, *batchv1.Job, batchv1.Job, metav1.Object, runtime.Object, *unstructured.Unstructured, unstructured.Unstructured or map[string]interface{}.

If passed parameter type is string, it will simply call GetByName instead of GetFromFile. You should always explicitly call GetFromFile to get a job from file path.

func (*Handler) GetAge added in v0.2.0

func (h *Handler) GetAge(object interface{}) (time.Duration, error)

GetAge get job age.

func (*Handler) GetByName

func (h *Handler) GetByName(name string) (*batchv1.Job, error)

GetByName gets job by name.

func (*Handler) GetController

func (h *Handler) GetController(object interface{}) (*JobController, error)

GetController returns a JobController object by job name if the controllee(job) has a controller.

func (*Handler) GetFromBytes

func (h *Handler) GetFromBytes(data []byte) (*batchv1.Job, error)

GetFromBytes gets job from bytes data.

func (*Handler) GetFromFile

func (h *Handler) GetFromFile(filename string) (*batchv1.Job, error)

GetFromFile gets job from yaml or json file.

func (*Handler) GetFromMap added in v0.5.0

func (h *Handler) GetFromMap(u map[string]interface{}) (*batchv1.Job, error)

GetFromMap gets job from unstructured.Unstructured.

func (*Handler) GetFromObject added in v0.3.0

func (h *Handler) GetFromObject(obj interface{}) (*batchv1.Job, error)

GetFromObject gets job from metav1.Object or runtime.Object.

func (*Handler) GetFromUnstructured added in v0.3.0

func (h *Handler) GetFromUnstructured(u *unstructured.Unstructured) (*batchv1.Job, error)

GetFromUnstructured gets job from *unstructured.Unstructured.

func (*Handler) Informer added in v0.5.0

func (h *Handler) Informer() cache.SharedIndexInformer

Informer returns underlying SharedIndexInformer which provides add and Indexers ability based on SharedInformer.

func (*Handler) InformerFactory added in v0.5.0

func (h *Handler) InformerFactory() informers.SharedInformerFactory

InformerFactory returns underlying SharedInformerFactory which provides shared informer for resources in all known API group version.

func (*Handler) IsCompleted added in v0.2.0

func (h *Handler) IsCompleted(name string) bool

IsCompleted will check if the job was successfully scheduled and run to completed job 成功调度并且其 pod 成功执行

func (*Handler) IsFailed added in v0.7.0

func (h *Handler) IsFailed(name string) bool

IsFailed will check if the job was successfully scheduled but run to failed.

func (*Handler) IsFinished added in v0.2.0

func (h *Handler) IsFinished(name string) bool

IsFinished will check the job was successfully scheduled, it doesn't matter if the job runs to completion or fails. job 成功调度, pod 不再产生, 比如 job 设置了 backoffLimit: 3, 则限制 job 产生的 pod 最多失败3次, 超过3次, job 不再创建 pod 来做执行任务. 这样也是 Finished 总结就是: job 不再创建 pod 来执行任务, 不管任务是否成功或失败 如果执行任务成功, job 只会创建一次 pod, 如果任务执行失败,创建多少次 pod 取决于 backoffLimit 的设置.

func (*Handler) IsSuspended added in v0.7.0

func (h *Handler) IsSuspended(name string) bool

IsSuspended will check if the job was successfully scheduled but the job was suspended.

func (*Handler) JobInformer added in v0.5.0

func (h *Handler) JobInformer() informersbatch.JobInformer

JobInformer returns underlying JobInformer which provides access to a shared informer and lister for job.

func (*Handler) List

func (h *Handler) List() ([]*batchv1.Job, error)

List list all jobs in the k8s cluster, it simply call `ListAll`.

func (*Handler) ListAll

func (h *Handler) ListAll() ([]*batchv1.Job, error)

ListAll list all jobs in the k8s cluster.

func (*Handler) ListByField added in v0.7.0

func (h *Handler) ListByField(field string) ([]*batchv1.Job, error)

ListByField list jobs by field, work like `kubectl get xxx --field-selector=xxx`.

func (*Handler) ListByLabel

func (h *Handler) ListByLabel(labels string) ([]*batchv1.Job, error)

ListByLabel list jobs by labels. Multiple labels separated by comma(",") eg: "name=myapp,role=devops", and there is an "And" relationship between multiple labels.

func (*Handler) ListByNamespace

func (h *Handler) ListByNamespace(namespace string) ([]*batchv1.Job, error)

ListByNamespace list all jobs in the specified namespace.

func (*Handler) Lister added in v0.5.0

func (h *Handler) Lister() listersbatch.JobLister

Lister returns underlying JobLister which helps list jobs.

func (*Handler) NumActive added in v0.2.0

func (h *Handler) NumActive(object interface{}) (int32, error)

NumActive returns the number of pending or running pod created by given job.

func (*Handler) NumFailed added in v0.2.0

func (h *Handler) NumFailed(object interface{}) (int32, error)

NumFailed returns the number of pods created by given job which reach phase failed.

func (*Handler) NumSucceeded added in v0.2.0

func (h *Handler) NumSucceeded(object interface{}) (int32, error)

NumSucceeded returns the number of pods created by given job which reach phase Succeeded.

func (*Handler) Patch added in v0.11.1

func (h *Handler) Patch(original *batchv1.Job, patch interface{}, patchOptions ...types.PatchType) (*batchv1.Job, error)

Patch use the default patch type(Strategic Merge Patch) to patch job. Supported patch types are: "StrategicMergePatchType", "MergePatchType", "JSONPatchType".

For further more Strategic Merge patch, see:

https://kubernetes.io/docs/tasks/manage-kubernetes-objects/update-api-object-kubectl-patch/#before-you-begin

For a comparison of JSON patch and JSON merge patch, see:

https://erosb.github.io/post/json-patch-vs-merge-patch/

func (*Handler) RESTClient added in v0.2.0

func (h *Handler) RESTClient() *rest.RESTClient

RESTClient returns underlying rest client.

func (*Handler) RESTConfig added in v0.3.0

func (h *Handler) RESTConfig() *rest.Config

RESTConfig returns underlying rest config.

func (*Handler) ResetNamespace added in v0.11.4

func (h *Handler) ResetNamespace(namespace string)

func (*Handler) RunInformer

func (h *Handler) RunInformer(
	stopCh <-chan struct{},
	addFunc func(obj interface{}),
	updateFunc func(oldObj, newObj interface{}),
	deleteFunc func(obj interface{}))

RunInformer start and run the shared informer, returning after it stops. The informer will be stopped when stopCh is closed.

AddFunc, updateFunc, and deleteFunc are used to handle add, update, and delete event of k8s job resource, respectively.

func (*Handler) SetForceDelete

func (h *Handler) SetForceDelete(force bool)

func (*Handler) SetInformerFactoryNamespace added in v0.10.4

func (h *Handler) SetInformerFactoryNamespace(namespace string)

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

func (h *Handler) SetInformerFactoryResyncPeriod(resyncPeriod time.Duration)

SetInformerFactoryResyncPeriod will set informer resync period.

func (*Handler) SetInformerFactoryTweakListOptions added in v0.10.4

func (h *Handler) SetInformerFactoryTweakListOptions(tweakListOptions internalinterfaces.TweakListOptionsFunc)

SetInformerFactoryTweakListOptions sets a custom filter on all listers of the configured SharedInformerFactory.

func (*Handler) SetLimit

func (h *Handler) SetLimit(limit int64)

func (*Handler) SetPropagationPolicy

func (h *Handler) SetPropagationPolicy(policy string)

SetPropagationPolicy determined whether and how garbage collection will be performed. There are supported values are "Background", "Orphan", "Foreground", default is "Background".

func (*Handler) SetTimeout

func (h *Handler) SetTimeout(timeout int64)

func (*Handler) StartInformer added in v0.10.1

func (h *Handler) StartInformer(
	stopCh <-chan struct{},
	addFunc func(obj interface{}),
	updateFunc func(oldObj, newObj interface{}),
	deleteFunc func(obj interface{}))

StartInformer simply call RunInformer.

func (*Handler) Update

func (h *Handler) Update(obj interface{}) (*batchv1.Job, error)

Update updates job from type string, []byte, *batchv1.Job, batchv1.Job, metav1.Object, runtime.Object, *unstructured.Unstructured, unstructured.Unstructured or map[string]interface{}.

func (*Handler) UpdateFromBytes

func (h *Handler) UpdateFromBytes(data []byte) (*batchv1.Job, error)

UpdateFromBytes updates job from bytes data.

func (*Handler) UpdateFromFile

func (h *Handler) UpdateFromFile(filename string) (*batchv1.Job, error)

UpdateFromFile updates job from yaml or json file.

func (*Handler) UpdateFromMap added in v0.5.0

func (h *Handler) UpdateFromMap(u map[string]interface{}) (*batchv1.Job, error)

UpdateFromMap updates job from map[string]interface{}.

func (*Handler) UpdateFromObject added in v0.3.0

func (h *Handler) UpdateFromObject(obj interface{}) (*batchv1.Job, error)

UpdateFromObject updates job from metav1.Object or runtime.Object.

func (*Handler) UpdateFromUnstructured added in v0.3.0

func (h *Handler) UpdateFromUnstructured(u *unstructured.Unstructured) (*batchv1.Job, error)

UpdateFromUnstructured updates job from *unstructured.Unstructured.

func (*Handler) WaitFinish

func (h *Handler) WaitFinish(name string) (err error)

WaitFinish wait job status to be "true"

func (*Handler) WaitNotExist

func (h *Handler) WaitNotExist(name string) (err error)

WaitNotExist wait job not exist

func (*Handler) Watch

func (h *Handler) Watch(addFunc, modifyFunc, deleteFunc func(obj interface{})) error

Watch watch all job resources.

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.1

func (h *Handler) WatchByField(field string, addFunc, modifyFunc, deleteFunc func(obj interface{})) error

WatchByField watch a single or multiple Job resources selected by the field.

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

func (h *Handler) WatchByLabel(labels string, addFunc, modifyFunc, deleteFunc func(obj interface{})) error

WatchByLabel watch a single or multiple Job resources selected by the label. Multiple labels are separated by ",", label key and value conjunctaed by "=".

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

func (h *Handler) WatchByName(name string, addFunc, modifyFunc, deleteFunc func(obj interface{})) error

WatchByName watch a single job reseource.

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.1

func (h *Handler) WatchByNamespace(namespace string, addFunc, modifyFunc, deleteFunc func(obj interface{})) error

WatchByNamespace watch all job resources in the specified namespace.

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

func (h *Handler) WithDryRun() *Handler

WithDryRun deep copies a new handler and prints the create/update/apply/delete operations, without sending it to apiserver.

func (*Handler) WithNamespace

func (h *Handler) WithNamespace(namespace string) *Handler

WithNamespace deep copies a new handler, but set the handler.namespace to the provided namespace.

type JobController

type JobController struct {
	metav1.OwnerReference `json:"ownerReference"`
}
   metav1.OwnerReference `json:"ownerReference"`
}

Jump to

Keyboard shortcuts

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