forked from tektoncd/plumbing
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
5 changed files
with
173 additions
and
1 deletion.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
tekton/config/kubectl-image-nightly-build-cron/cronjob.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
5 changes: 5 additions & 0 deletions
5
tekton/config/kubectl-image-nightly-build-cron/kustomization.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |