README ¶
Kubernetes Backend for QOR Worker
This package provides QOR worker's backend based on Kubernetes Job
Basic Usage
In the basic usage mode, we will collect currently running pod's information like containers, volumes to create a new job pod to complete your requests.
kubernetesBackend, err := kubernetes.New(&kubernetes.Config{})
Worker := worker.New(&worker.Config{
Queue: kubernetesBackend,
})
Worker.RegisterJob(&worker.Job{
Name: "Send Newsletter",
Handler: func(argument interface{}, qorJob worker.QorJobInterface) error {
})
Advanced Usage
For advanced requirements, like manage job's priority, cpu/memory's requests/limits, you could customize Job's template based on your requirements.
For example:
func main() {
kubernetesBackend, err := kubernetes.New(&kubernetes.Config{
JobTemplateMaker: func(qorJob worker.QorJobInterface) string {
// Job `process order` has higher priority than other jobs
if qorJob.GetJobName() == "process_order" {
return `
apiVersion: batch/v1
kind: Job
metadata:
name: jobname
spec:
template:
spec:
containers:
- name: app
image: my_image
priorityClassName: high-priority
`
}
return `
apiVersion: batch/v1
kind: Job
metadata:
name: jobname
spec:
template:
spec:
containers:
- name: app
image: my_image
resources:
limits:
cpu: "750m"
priorityClassName: low-priority
`
},
})
Worker := worker.New(&worker.Config{
Queue: kubernetesBackend,
})
}
Documentation ¶
Index ¶
- func GetLocalIP() string
- type Config
- type Kubernetes
- func (k8s *Kubernetes) Add(qorJob worker.QorJobInterface) error
- func (k8s *Kubernetes) GetCurrentPod() *corev1.Pod
- func (k8s *Kubernetes) GetJobSpec(qorJob worker.QorJobInterface) (*v1.Job, error)
- func (k8s *Kubernetes) Kill(qorJob worker.QorJobInterface) error
- func (k8s *Kubernetes) Remove(qorJob worker.QorJobInterface) error
- func (k8s *Kubernetes) Run(qorJob worker.QorJobInterface) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Config ¶
type Config struct { Namespace string JobTemplateMaker func(worker.QorJobInterface) string ClusterConfig *rest.Config }
Config kubernetes config
type Kubernetes ¶
type Kubernetes struct { Clientset *kubernetes.Clientset Config *Config }
Kubernetes implemented a worker Queue based on kubernetes jobs
func (*Kubernetes) Add ¶
func (k8s *Kubernetes) Add(qorJob worker.QorJobInterface) error
Add a job to k8s queue
func (*Kubernetes) GetCurrentPod ¶
func (k8s *Kubernetes) GetCurrentPod() *corev1.Pod
GetCurrentPod get current pod
func (*Kubernetes) GetJobSpec ¶
func (k8s *Kubernetes) GetJobSpec(qorJob worker.QorJobInterface) (*v1.Job, error)
GetJobSpec get job spec
func (*Kubernetes) Kill ¶
func (k8s *Kubernetes) Kill(qorJob worker.QorJobInterface) error
Kill a job from k8s queue
func (*Kubernetes) Remove ¶
func (k8s *Kubernetes) Remove(qorJob worker.QorJobInterface) error
Remove a job from k8s queue
func (*Kubernetes) Run ¶
func (k8s *Kubernetes) Run(qorJob worker.QorJobInterface) error
Run a job from k8s queue
Click to show internal directories.
Click to hide internal directories.