From f967c90da89ceae2b1f527dd11f155b0b4ed438a Mon Sep 17 00:00:00 2001 From: James Pace Date: Sat, 27 Aug 2022 21:53:10 -0400 Subject: [PATCH] Track efforts to get trigger working. --- ambassador/listener.yaml | 22 +++++++++++ ambassador/mapping.yaml | 7 ++++ notes.md | 23 +++++++++++ scripts/Dockerfile_flask | 11 ++++++ scripts/test.py | 22 +++++++++++ serviceaccounts/tekton-bot.yaml | 31 +++++++++++++++ triggers/eventlistener.yaml | 67 +++++++++++++++++++++++++++++++++ 7 files changed, 183 insertions(+) create mode 100644 ambassador/listener.yaml create mode 100644 ambassador/mapping.yaml create mode 100644 scripts/Dockerfile_flask create mode 100644 scripts/test.py create mode 100644 serviceaccounts/tekton-bot.yaml create mode 100644 triggers/eventlistener.yaml diff --git a/ambassador/listener.yaml b/ambassador/listener.yaml new file mode 100644 index 0000000..1ef59cb --- /dev/null +++ b/ambassador/listener.yaml @@ -0,0 +1,22 @@ +--- +apiVersion: getambassador.io/v3alpha1 +kind: Host +metadata: + name: tekton-host +spec: + hostname: "tekton.internal.jpace121.net" + requestPolicy: + insecure: + action: Route +--- +apiVersion: getambassador.io/v3alpha1 +kind: Listener +metadata: + name: http-listener +spec: + port: 8080 + protocol: HTTP + securityModel: INSECURE + hostBinding: + namespace: + from: SELF \ No newline at end of file diff --git a/ambassador/mapping.yaml b/ambassador/mapping.yaml new file mode 100644 index 0000000..8103b8a --- /dev/null +++ b/ambassador/mapping.yaml @@ -0,0 +1,7 @@ +apiVersion: getambassador.io/v3alpha1 +kind: Mapping +metadata: + name: test-listener-mapping +spec: + prefix: /test-event/ + service: el-test-listener.default.svc.cluster.local:8080 \ No newline at end of file diff --git a/notes.md b/notes.md index 2c21c7a..14636e4 100644 --- a/notes.md +++ b/notes.md @@ -37,6 +37,7 @@ kubectl config set-context j7s-dev --namespace=j7s-dev \ --cluster=j7s-dev \ --user=default ``` +I'm not sure the above command works... Stuff I installed from tkn. ``` @@ -45,4 +46,26 @@ tkn hub install task ansible-runner tkn hub install task git-batch-merge ``` +Triggers: + +Install: + +kubectl apply --filename https://storage.googleapis.com/tekton-releases/triggers/latest/release.yaml +kubectl apply --filename https://storage.googleapis.com/tekton-releases/triggers/latest/interceptors.yaml + + +Amabassador: (for knative) + +Start with these instruction to disable traefik. +https://www.suse.com/c/rancher_blog/deploy-an-ingress-controller-on-k3s/ +use `--disable=traefik` in systemd. +The equal is important... + +Follow the instructions https://www.getambassador.io/docs/edge-stack/latest/topics/install/yaml-install/ to install ambassador. + +I used the file in ./ambassador/listener.yaml to set up the listener. + +I'm not sure why ambassdor is listening on 80 instead of 8080 given the +settings I applied, or why changing from 8080 to 80 in the seeting borks +it. diff --git a/scripts/Dockerfile_flask b/scripts/Dockerfile_flask new file mode 100644 index 0000000..37190b3 --- /dev/null +++ b/scripts/Dockerfile_flask @@ -0,0 +1,11 @@ +FROM docker.io/debian:bullseye-slim + +RUN apt update -y && \ + apt install -y python3-flask && \ + mkdir /app + +COPY test.py /app/test.py + +WORKDIR /app +ENV FLASK_APP=test +CMD ["flask", "run", "--host", "0.0.0.0"] \ No newline at end of file diff --git a/scripts/test.py b/scripts/test.py new file mode 100644 index 0000000..3c8df86 --- /dev/null +++ b/scripts/test.py @@ -0,0 +1,22 @@ +from flask import Flask +from flask import request +import logging + +app = Flask(__name__) + +logger = logging.getLogger('j7s-app') +logger.setLevel(logging.INFO) +handler = logging.StreamHandler() +logger.addHandler(handler) + + +@app.route("/", defaults={"path": ""}, methods = ['POST', 'GET']) +@app.route('/', methods=['POST', 'GET']) +def root(path): + logger.info("Path") + logger.info(path) + logger.info("Headers:") + logger.info(request.headers) + logger.info("Body:") + logger.info(request.json) + return "

Hello

" diff --git a/serviceaccounts/tekton-bot.yaml b/serviceaccounts/tekton-bot.yaml new file mode 100644 index 0000000..2e7a1e0 --- /dev/null +++ b/serviceaccounts/tekton-bot.yaml @@ -0,0 +1,31 @@ +apiVersion: v1 +kind: ServiceAccount +metadata: + name: tekton-bot +secrets: + - name: git-credentials +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: RoleBinding +metadata: + name: tekton-bot-eventlistener-binding +subjects: +- kind: ServiceAccount + name: tekton-bot +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: tekton-triggers-eventlistener-roles +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + name: tekton-bot-eventlistener-clusterbinding +subjects: +- kind: ServiceAccount + name: tekton-bot + namespace: default +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: tekton-triggers-eventlistener-clusterroles \ No newline at end of file diff --git a/triggers/eventlistener.yaml b/triggers/eventlistener.yaml new file mode 100644 index 0000000..58cb6a1 --- /dev/null +++ b/triggers/eventlistener.yaml @@ -0,0 +1,67 @@ +--- +apiVersion: triggers.tekton.dev/v1beta1 +kind: EventListener +metadata: + name: test-listener +spec: + serviceAccountName: tekton-bot + triggers: + - name: test-trigger + bindings: + - ref: message-binding + template: + ref: pipeline-template +--- +apiVersion: triggers.tekton.dev/v1beta1 +kind: TriggerBinding +metadata: + name: pipeline-binding +spec: + params: + - name: gitrevision + value: $(body.patchSet.revision) +--- +apiVersion: triggers.tekton.dev/v1beta1 +kind: TriggerBinding +metadata: + name: message-binding +spec: + params: + - name: gitrepositoryurl + value: ssh://gerrit.internal.jpace121.net:29418/ci/test +--- + +apiVersion: triggers.tekton.dev/v1beta1 +kind: TriggerTemplate +metadata: + name: pipeline-template +spec: + params: + - name: gitrevision + description: The git revision + default: main + - name: gitrepositoryurl + description: The git repository url + resourcetemplates: + - apiVersion: tekton.dev/v1beta1 + kind: PipelineRun + metadata: + generateName: test-run- + spec: + pipelineRef: + name: git-pipeline + params: + - name: repo-url + value: $(tt.params.gitrepositoryurl) + workspaces: + - name: shared-data + volumeClaimTemplate: + spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 1Gi + - name: git-credentials + secret: + secretName: git-credentials \ No newline at end of file