Skip to content

Commit

Permalink
CD prow config using tekton
Browse files Browse the repository at this point in the history
Define an event listener that triggers a tekton task that deploys
prow configurations on a target k8s cluster / namespace from a
give git repo / path.

Closes #1
  • Loading branch information
afrittoli committed Oct 26, 2019
1 parent 1b7124d commit 042c002
Show file tree
Hide file tree
Showing 5 changed files with 173 additions and 1 deletion.
24 changes: 24 additions & 0 deletions tekton/config/kubectl-image-nightly-build-cron/cronjob.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: batch/v1beta1
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/tekton/plumbing
- name: GIT_REVISION
value: master
- name: TARGET_IMAGE
value: gcr.io/tekton-releases/dogfooding/kubectl:latest
- name: CONTEXT_PATH
value: tekton/images/kubectl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
bases:
- ../nightly-image-build-cron-base
patchesStrategicMerge:
- cronjob.yaml
nameSuffix: "-kubectl"
21 changes: 21 additions & 0 deletions tekton/images/kubectl/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright 2019 The Tekton Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
FROM alpine:3.10
LABEL maintainer "Andrea Frittoli <andrea.frittoli@gmail.com>"

RUN apk update && apk add ca-certificates && rm -rf /var/cache/apk/*
RUN update-ca-certificates

ARG KUBECTL_VERSION=1.16.2
RUN wget -O/usr/local/bin/kubectl https://storage.googleapis.com/kubernetes-release/release/v$KUBECTL_VERSION/bin/linux/amd64/kubectl
5 changes: 4 additions & 1 deletion tekton/images/tkn/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2018 The Tekton Authors
# Copyright 2019 The Tekton Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -14,5 +14,8 @@
FROM alpine:3.10
LABEL maintainer "Andrea Frittoli <andrea.frittoli@gmail.com>"

RUN apk update && apk add ca-certificates && rm -rf /var/cache/apk/*
RUN update-ca-certificates

ARG TKN_VERSION=0.4.0
RUN wget -O- https://github.com/tektoncd/cli/releases/download/v${TKN_VERSION}/tkn_${TKN_VERSION}_Linux_x86_64.tar.gz | tar zxf - -C /usr/local/bin
119 changes: 119 additions & 0 deletions tekton/resources/prow-config-cd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
apiVersion: tekton.dev/v1alpha1
kind: TriggerBinding
metadata:
name: trigger-to-deploy-prow-config
spec:
params:
- name: gitRepository
value: $(body.gitRepository)
- name: gitRevision
value: $(body.gitRevision)
- name: configPath
value: $(body.configPath)
- name: namespace
value: $(body.namespace)
- name: clusterResource
value: $(body.clusterResource)
---
apiVersion: tekton.dev/v1alpha1
kind: EventListener
metadata:
name: prow-config-deployer
spec:
triggers:
- name: trigger
binding:
name: trigger-to-deploy-prow-config
template:
name: deploy-prow-config
---
apiVersion: tekton.dev/v1alpha1
kind: TriggerTemplate
metadata:
name: deploy-prow-config
spec:
params:
- name: gitRepository
description: URL of the repository that holds the prow configuration
- name: gitRevision
description: Git revision
- name: namespace
description: Namespace to deploy to in the target cluster
- name: configPath
description: Path in the git repo that holds prow configs
- name: clusterResource
description: Name of the cluster resource that points to the target cluster
resourcetemplates:
- apiVersion: tekton.dev/v1alpha1
kind: PipelineResource
metadata:
name: git-source-$(uid)
spec:
type: git
params:
- name: revision
value: $(params.gitRevision)
- name: url
value: https://$(params.gitRepository)
- apiVersion: tekton.dev/v1alpha1
kind: TaskRun
metadata:
generateName: deploy-prow-config-$(uid)-
spec:
taskSpec:
inputs:
params:
- name: configPath
description: Path in the git repo that holds prow configs
- name: namespace
description: Namespace to deploy to in the target cluster
resources:
- name: source
type: git
- name: prow-cluster
type: cluster
stepTemplate:
env:
name: KUBECONFIG
value: /workspace/$(inputs.resources.prow-cluster.name)/kubeconfig
steps:
- name: fetch-current-config
image: gcr.io/tekton-releases/dogfooding/kubectl
command:
- /bin/sh
args:
- -ce
- |
kubectl get configmap config -o template --template={{.data}} \
> /workspace/config.yaml
- name: deploy
image: gcr.io/tekton-releases/dogfooding/kubectl
command:
- /bin/sh
args:
- -ce
- |
echo "diff [current-config] [new config]"
diff /workspace/config.yaml $(inputs.resources.source.path)/$(inputs.params.configPath)=prow/config.yaml
if [ $? -eq 0 ]; then
echo "No change in config detected. Nothing to be done."
exit 0
fi
# Apply configuration changes
kubectl create configmap config \
--from-file=$(inputs.resources.source.path)/$(inputs.params.configPath)=prow/config.yaml \
--dry-run -o yaml | \
kubectl replace configmap config -n $(inputs.params.namespace) -f -
inputs:
params:
- name: configPath
value: $(params.configPath)
- name: namespace
value: $(params.namespace)
resources:
- name: source
resourceRef:
name: git-source-$(uid)
- name: prow-cluster
resourceRef:
name: $(params.clusterResource)

0 comments on commit 042c002

Please sign in to comment.