Skip to content

Latest commit

Β 

History

History

cronjobs

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Tekton Cron Jobs

This folder holds kustomize overlays, that are used to maintain cron job configurations. To add a new cron job to be deployed to a cluster, create a folder and add a kustomization.yaml into it, along with the cronjob overlay. Add the created folder to the kustomization.yaml of the containg folder.

There are several base cron jobs available, each linked to a dedicated trigger template:

  • release: trigger the pipeline repo nightly builds
  • image-build: build container images and push them to a container repo (by default gcr.io/tekton-releases/dogfooding/myimage)
  • folder: trigger deployment of manifests or overlays in a folder
  • configmap: trigger deployment a configmap from a YAML stored in git
  • cleanup: trigger cleanup of *Run resources from a namespace
  • helm: trigger deployment of an helm chart
  • tekton-service: deploy a Tekton service from a release file with an optional overlay from git

Cronjobs are organized per cluster where they are deployed and run. Note that a cronjob deployed to a cluster may act on a different one.

cronjobs
β”œβ”€β”€ dogfooding
β”œβ”€β”€ prow
β”œβ”€β”€ robocat
β”œβ”€β”€ kustomization.yaml
└── README.md

Existing cron jobs

Container Images

Images are build on the dogfooding cluster.

Nightly Releases

The following projects are released nightly on the dogfooding cluster:

Continuous Deployments

Tekton services in the Robocat cluster are deployed nightly from the dogfooding cluster. Other deployments are performed from the same cluster they target.

Adding a new cron job

To add a new cronjob for an existing base, follow these steps.

Example folders structure:

cronjobs
β”œβ”€β”€β”€ dogfooding
β”‚Β Β  β”œβ”€β”€ cleanup
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ kustomization.yaml
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ default-nightly
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ README.md
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ cronjob.yaml
β”‚Β Β  β”‚Β Β  β”‚Β Β  └── kustomization.yaml
β”‚Β Β  β”‚Β Β  └── *mynamespace-nightly*
β”‚Β Β  β”‚Β Β      β”œβ”€β”€ README.md
β”‚Β Β  β”‚Β Β      β”œβ”€β”€ cronjob.yaml
β”‚Β Β  β”‚Β Β      └── kustomization.yaml

Example Kustomization configuration file:

# kustomization.yaml
bases:
- ../../../bases/cleanup
patchesStrategicMerge:
- cronjob.yaml
nameSuffix: "-dogfooding-mynamespace"

Example Cronjob definition file. This file must give enough context for kustomize to match the correct resource to be patched - in this case to match cleanup-trigger. It allows cron jobs to override relevant parts of the template trigger, like schedule or the value of environment variables.

apiVersion: batch/v1
kind: CronJob
metadata:
  name: cleanup-trigger
spec:
  schedule: "0 11 * * *"
  concurrencyPolicy: Forbid
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - name: trigger
            env:
              - name: NAMESPACE
                value: "mynamespace"
              - name: CLUSTER_RESOURCE
                value: "dogfooding-tektoncd-cleaner"
              - name: CLEANUP_KEEP
                value: "200"

To generate the YAML for the newly defined cron configuration, run the following:

kustomize build tekton/cronjobs/dogfooding/cleanup/mynamespace-nightly

To apply the cron configuration directly, run the following:

kustomize build tekton/cronjobs/dogfooding/cleanup/mynamespace-nightly | kubectl apply -f -
# or
kubectl replace -k tekton/cronjobs/dogfooding/cleanup/mynamespace-nightly/

To reapply all cronjobs on dogfooding:

kubectl replace -k tekton/cronjobs/dogfooding

Make sure that RBAC is confifured properly to execute pipelinerun/taskrun triggered by cronjob. For cleanup, new RoleBinding should be added to serviceaccount.yaml.

apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: tektoncd-cleaner-delete-pr-tr-default
  namespace: mynamespace
subjects:
- kind: ServiceAccount
  name: tekton-cleaner
  namespace: default
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: delete-pr-tr

Adding a daily build for a new image

To build daily a container image, follow these steps:

  1. Create a new context folder with the Dockerfile in it:
tekton
β”œβ”€β”€ images
β”‚Β Β  └── myimage
β”‚Β Β      └── Dockerfile
  1. Create a new kustomize folder with kustomization.yaml and cronjob.yaml. Copy the content from an existing one, e.g. tkn-image-nightly-build-cron.
cronjobs
β”œβ”€β”€β”€ dogfooding
β”‚Β Β  β”œβ”€β”€ images
β”‚Β Β  β”‚Β Β  └── myimage-nightly
β”‚Β Β  β”‚Β Β      β”œβ”€β”€ README.md
β”‚Β Β  β”‚Β Β      β”œβ”€β”€ cronjob.yaml
β”‚Β Β  β”‚Β Β      └── kustomization.yaml
  1. Edit cronjob.yaml. Configure at least CONTEXT_PATH and TARGET_IMAGE.
apiVersion: batch/v1
kind: CronJob
metadata:
  name: image-build-cron-trigger
spec:
  schedule: "0 2 * * *"
  concurrencyPolicy: Forbid
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - name: trigger
            env:
            - name: SINK_URL
              value: el-image-builder.default.svc.cluster.local:8080
            - name: GIT_REPOSITORY
              value: github.com/tektoncd/plumbing
            - name: GIT_REVISION
              value: main
            - name: TARGET_IMAGE
              value: gcr.io/tekton-releases/dogfooding/myimage:latest
            - name: CONTEXT_PATH
              value: tekton/images/myimage
  1. Add PLATFORMS and BUILD_TYPE to cronjob.yaml if you want to build multi-arch image. List target architectures for the image. For BUILD_TYPE use docker or ko value to choose the image build tool.
...
            - name: PLATFORMS
              value: "linux/amd64,linux/s390x,linux/ppc64le"
            - name: BUILD_TYPE
              value: docker

Note Please, make sure that the image is buildable for listed architectures. For instance, base image in corresponding Dockerfile should support the same(or larger) list of architectures.

  1. Edit kustomization.yaml. Set the nameSuffix to identify the new cron job.
bases:
- ../../../bases/image-build
patchesStrategicMerge:
- cronjob.yaml
nameSuffix: "-myimage"
  1. Edit tekton/cronjobs/dogfooding/images/kustomization.yaml. Add name of your newly created directory
- myimage-nightly
  1. Apply your new job:
kubectl -k tekton/cronjobs/dogfooding/images/myimage-nightly/
  1. Check the result:
kubectl get cronjobs
  1. Run the build:
kubectl create job --from=cronjob/image-build-cron-trigger-myimage build-myimage-$(date +"%Y%m%d-%H%M")