kubernetes

package
v0.0.0-...-0b1ed72 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2024 License: MIT Imports: 13 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetLocalIP

func GetLocalIP() string

GetLocalIP returns the non loopback local IP of the host

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 New

func New(config *Config) (*Kubernetes, error)

New initialize Kubernetes

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

Jump to

Keyboard shortcuts

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