kjobrunner

package module
v0.0.0-...-ba58b1a Latest Latest
Warning

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

Go to latest
Published: May 1, 2019 License: MIT Imports: 10 Imported by: 0

README

kjobrunner

Simplify Kubernetes API for run jobs

Testing

# create namespace
$ kubectl create ns kjobrunner

# create service account
$ kubectl create sa runner -n kjobrunner

# grant service account permissions
$ cat << EOF | kubectl apply -f - -n kjobrunner
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  name: runner
rules:
- apiGroups: ["batch"]
  resources: ["jobs"]
  verbs: ["*"]
- apiGroups: [""]
  resources: ["pods"]
  verbs: ["get"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: runner
subjects:
- kind: ServiceAccount
  name: runner
roleRef:
  kind: Role
  name: runner
  apiGroup: rbac.authorization.k8s.io
EOF

# run test
$ TOKEN=$(kubectl get sa/runner -ojson | jq '.secrets[0].name' -r | xargs kubectl get secret -ojson | jq '.data.token' -r | base64 -D) go test .

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotExists = errors.New("kjobrunner: not exists")
)

Errors

Functions

This section is empty.

Types

type Envs

type Envs struct {
	// contains filtered or unexported fields
}

func (*Envs) Add

func (envs *Envs) Add(name, value string)

type RunOption

type RunOption struct {
	Name     string
	Image    string
	Envs     *Envs
	Args     []string
	Replicas int32
}

type Runner

type Runner struct {
	// contains filtered or unexported fields
}

Runner wraps k8s job with simple api

func New

func New(name string, client *kubernetes.Clientset, namespace string) *Runner

New creates new runner

func (*Runner) Cleanup

func (r *Runner) Cleanup() error

Cleanup deletes all success jobs

func (*Runner) Delete

func (r *Runner) Delete(name string) error

func (*Runner) Exists

func (r *Runner) Exists(name string) (bool, error)

func (*Runner) List

func (r *Runner) List() ([]string, error)

func (*Runner) Logs

func (r *Runner) Logs(name string) (string, error)

func (*Runner) Run

func (r *Runner) Run(opt *RunOption) error

func (*Runner) Wait

func (r *Runner) Wait(name string) error

Jump to

Keyboard shortcuts

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