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 buildsimage-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 folderconfigmap
: trigger deployment a configmap from a YAML stored in gitcleanup
: trigger cleanup of*Run
resources from a namespacehelm
: trigger deployment of an helm charttekton-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
Images are build on the dogfooding cluster.
The following projects are released nightly on the dogfooding cluster:
Tekton services in the Robocat cluster are deployed nightly from the dogfooding cluster. Other deployments are performed from the same cluster they target.
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
To build daily a container image, follow these steps:
- Create a new context folder with the Dockerfile in it:
tekton
βββ images
βΒ Β βββ myimage
βΒ Β βββ Dockerfile
- Create a new kustomize folder with
kustomization.yaml
andcronjob.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
- 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: ghcr.io/tektoncd/plumbing/myimage:latest
- name: CONTEXT_PATH
value: tekton/images/myimage
- 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.
- Edit
kustomization.yaml
. Set the nameSuffix to identify the new cron job.
bases:
- ../../../bases/image-build
patchesStrategicMerge:
- cronjob.yaml
nameSuffix: "-myimage"
- Edit
tekton/cronjobs/dogfooding/images/kustomization.yaml
. Add name of your newly created directory
- myimage-nightly
- Apply your new job:
kubectl -k tekton/cronjobs/dogfooding/images/myimage-nightly/
- Check the result:
kubectl get cronjobs
- Run the build:
kubectl create job --from=cronjob/image-build-cron-trigger-myimage build-myimage-$(date +"%Y%m%d-%H%M")