cronjob

package
v0.0.0-...-c76096c Latest Latest
Warning

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

Go to latest
Published: May 7, 2024 License: Apache-2.0 Imports: 13 Imported by: 1

Documentation

Overview

Example (Full)
package main

import (
	"embed"
	"os"

	v1 "k8s.io/api/core/v1"

	"knative.dev/reconciler-test/pkg/manifest"
	"knative.dev/reconciler-test/pkg/resources/job"

	testlog "knative.dev/reconciler-test/pkg/logging"
)

//go:embed *.yaml
var yaml embed.FS

func main() {
	ctx := testlog.NewContext()
	images := map[string]string{}
	cfg := map[string]interface{}{
		"name":      "foo",
		"namespace": "bar",
		"image":     "baz",
	}

	opts := []manifest.CfgFn{
		job.WithLabels(map[string]string{
			"color": "green",
			"app":   "foo",
			"bar":   "true",
		}),
		job.WithAnnotations(map[string]interface{}{
			"app.kubernetes.io/name": "app",
		}),
		job.WithPodLabels(map[string]string{
			"app": "my-app",
		}),
		job.WithPodAnnotations(map[string]interface{}{
			"pod-annotation": "foo",
		}),
		job.WithRestartPolicy(v1.RestartPolicyNever),
		job.WithImagePullPolicy(v1.PullNever),
		job.WithBackoffLimit(20),
		job.WithEnvs(map[string]string{
			"VAR": "VAL",
		}),
		job.WithTTLSecondsAfterFinished(30),
	}

	for _, opt := range opts {
		opt(cfg)
	}

	files, err := manifest.ExecuteYAML(ctx, yaml, images, cfg)
	if err != nil {
		panic(err)
	}

	manifest.OutputYAML(os.Stdout, files)
}
Output:

apiVersion: batch/v1
kind: CronJob
metadata:
  name: foo
  namespace: bar
  annotations:
    app.kubernetes.io/name: "app"
  labels:
    app: "foo"
    bar: "true"
    color: "green"
spec:
  schedule: "* * * * *"
  jobTemplate:
    metadata:
      labels:
        app: "foo"
        bar: "true"
        color: "green"
    spec:
      backoffLimit: 20
      ttlSecondsAfterFinished: 30
      template:
        metadata:
          annotations:
            pod-annotation: "foo"
          labels:
            app: "my-app"
        spec:
          restartPolicy: Never
          containers:
            - name: user-container
              image: baz
              env:
              - name: "VAR"
                value: "VAL"
              imagePullPolicy: Never
Example (Min)
package main

import (
	"embed"
	"os"

	"knative.dev/reconciler-test/pkg/manifest"

	testlog "knative.dev/reconciler-test/pkg/logging"
)

//go:embed *.yaml
var yaml embed.FS

func main() {
	ctx := testlog.NewContext()
	images := map[string]string{}
	cfg := map[string]interface{}{
		"name":      "foo",
		"namespace": "bar",
		"image":     "baz",
		"labels": map[string]string{
			"app": "foo",
		},
	}

	files, err := manifest.ExecuteYAML(ctx, yaml, images, cfg)
	if err != nil {
		panic(err)
	}

	manifest.OutputYAML(os.Stdout, files)
}
Output:

apiVersion: batch/v1
kind: CronJob
metadata:
  name: foo
  namespace: bar
  labels:
    app: "foo"
spec:
  schedule: "* * * * *"
  jobTemplate:
    metadata:
      labels:
        app: "foo"
    spec:
      template:
        spec:
          containers:
            - name: user-container
              image: baz

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	WithLabels                  = manifest.WithLabels
	WithAnnotations             = manifest.WithAnnotations
	WithPodAnnotations          = manifest.WithPodAnnotations
	WitEnvs                     = job.WithEnvs
	WithPodLabels               = job.WithLabels
	WithImagePullPolicy         = job.WithRestartPolicy
	WithRestartPolicy           = job.WithRestartPolicy
	WithBackoffLimit            = job.WithBackoffLimit
	WithTTLSecondsAfterFinished = job.WithTTLSecondsAfterFinished
)

Functions

func AtLeastOneIsDone

func AtLeastOneIsDone(name string, timing ...time.Duration) feature.StepFn

func AtLeastOneIsFailed

func AtLeastOneIsFailed(name string, timing ...time.Duration) feature.StepFn

func AtLeastOneIsSucceeded

func AtLeastOneIsSucceeded(name string, timing ...time.Duration) feature.StepFn

func Install

func Install(name string, image string, options ...manifest.CfgFn) feature.StepFn

Types

This section is empty.

Jump to

Keyboard shortcuts

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