From 510a6eaaed3f75d9c9c7e56d0c37b615fac24a45 Mon Sep 17 00:00:00 2001 From: stefanprodan Date: Fri, 27 Sep 2019 15:19:03 +0300 Subject: [PATCH 1/6] Add JWT token issuing test to podinfo chart --- charts/podinfo/templates/tests/jwt.yaml | 29 +++++++++++++ .../podinfo/templates/tests/test-config.yaml | 22 ---------- charts/podinfo/templates/tests/test-pod.yaml | 43 ------------------- 3 files changed, 29 insertions(+), 65 deletions(-) create mode 100644 charts/podinfo/templates/tests/jwt.yaml delete mode 100755 charts/podinfo/templates/tests/test-config.yaml delete mode 100755 charts/podinfo/templates/tests/test-pod.yaml diff --git a/charts/podinfo/templates/tests/jwt.yaml b/charts/podinfo/templates/tests/jwt.yaml new file mode 100644 index 00000000..e9b08b4a --- /dev/null +++ b/charts/podinfo/templates/tests/jwt.yaml @@ -0,0 +1,29 @@ +apiVersion: v1 +kind: Pod +metadata: + name: {{ template "podinfo.fullname" . }}-jwt-test-{{ randAlphaNum 5 | lower }} + labels: + heritage: {{ .Release.Service }} + release: {{ .Release.Name }} + chart: {{ .Chart.Name }}-{{ .Chart.Version }} + app: {{ template "podinfo.name" . }} + annotations: + "helm.sh/hook": test-success + sidecar.istio.io/inject: "false" + linkerd.io/inject: disabled + appmesh.k8s.aws/sidecarInjectorWebhook: disabled +spec: + containers: + - name: tools + image: giantswarm/tiny-tools + command: + - sh + - -c + - | + TOKEN=$(curl -sd 'test' ${PODINFO_SVC}/token | jq -r .token) && + curl -H "Authorization: Bearer ${TOKEN}" ${PODINFO_SVC}/token/validate | grep test + env: + - name: PODINFO_SVC + value: {{ template "podinfo.fullname" . }}:{{ .Values.service.port }} + restartPolicy: Never + diff --git a/charts/podinfo/templates/tests/test-config.yaml b/charts/podinfo/templates/tests/test-config.yaml deleted file mode 100755 index 49a95554..00000000 --- a/charts/podinfo/templates/tests/test-config.yaml +++ /dev/null @@ -1,22 +0,0 @@ -{{- $url := printf "%s%s.%s:%v" (include "podinfo.fullname" .) (include "podinfo.suffix" .) .Release.Namespace .Values.service.port -}} -apiVersion: v1 -kind: ConfigMap -metadata: - name: {{ template "podinfo.fullname" . }}-tests - labels: - heritage: {{ .Release.Service }} - release: {{ .Release.Name }} - chart: {{ .Chart.Name }}-{{ .Chart.Version }} - app: {{ template "podinfo.name" . }} -data: - run.sh: |- - @test "HTTP POST /echo" { - run curl --retry 3 --connect-timeout 2 -sSX POST -d 'test' {{ $url }}/echo - [ $output = "test" ] - } - @test "HTTP POST /store" { - curl --retry 3 --connect-timeout 2 -sSX POST -d 'test' {{ $url }}/store - } - @test "HTTP GET /" { - curl --retry 3 --connect-timeout 2 -sS {{ $url }} | grep hostname - } diff --git a/charts/podinfo/templates/tests/test-pod.yaml b/charts/podinfo/templates/tests/test-pod.yaml deleted file mode 100755 index 5105ef4b..00000000 --- a/charts/podinfo/templates/tests/test-pod.yaml +++ /dev/null @@ -1,43 +0,0 @@ -apiVersion: v1 -kind: Pod -metadata: - name: {{ template "podinfo.fullname" . }}-tests-{{ randAlphaNum 5 | lower }} - annotations: - "helm.sh/hook": test-success - sidecar.istio.io/inject: "false" - labels: - heritage: {{ .Release.Service }} - release: {{ .Release.Name }} - chart: {{ .Chart.Name }}-{{ .Chart.Version }} - app: {{ template "podinfo.name" . }} -spec: - initContainers: - - name: "test-framework" - image: "dduportal/bats:0.4.0" - command: - - "bash" - - "-c" - - | - set -ex - # copy bats to tools dir - cp -R /usr/local/libexec/ /tools/bats/ - volumeMounts: - - mountPath: /tools - name: tools - containers: - - name: {{ .Release.Name }}-ui-test - image: dduportal/bats:0.4.0 - command: ["/tools/bats/bats", "-t", "/tests/run.sh"] - volumeMounts: - - mountPath: /tests - name: tests - readOnly: true - - mountPath: /tools - name: tools - volumes: - - name: tests - configMap: - name: {{ template "podinfo.fullname" . }}-tests - - name: tools - emptyDir: {} - restartPolicy: Never From 761746af213e4d398b2c07dfdc458998c466a2ac Mon Sep 17 00:00:00 2001 From: stefanprodan Date: Fri, 27 Sep 2019 15:52:30 +0300 Subject: [PATCH 2/6] Update podinfo to v3.1.0 --- charts/podinfo/Chart.yaml | 6 ++--- charts/podinfo/templates/deployment.yaml | 3 +++ charts/podinfo/values.yaml | 8 ++++--- docs/gitbook/tutorials/canary-helm-gitops.md | 23 ++++++++++---------- kustomize/podinfo/deployment.yaml | 20 +++++++++++------ 5 files changed, 36 insertions(+), 24 deletions(-) diff --git a/charts/podinfo/Chart.yaml b/charts/podinfo/Chart.yaml index 48442097..9483925c 100644 --- a/charts/podinfo/Chart.yaml +++ b/charts/podinfo/Chart.yaml @@ -1,10 +1,10 @@ apiVersion: v1 -version: 3.0.0 -appVersion: 2.0.0 +version: 3.1.0 +appVersion: 3.1.0 name: podinfo engine: gotpl description: Flagger canary deployment demo chart -home: https://github.com/weaveworks/flagger +home: https://flagger.app maintainers: - email: stefanprodan@users.noreply.github.com name: stefanprodan diff --git a/charts/podinfo/templates/deployment.yaml b/charts/podinfo/templates/deployment.yaml index cf4353aa..969e2a8a 100644 --- a/charts/podinfo/templates/deployment.yaml +++ b/charts/podinfo/templates/deployment.yaml @@ -37,6 +37,9 @@ spec: - --random-delay={{ .Values.faults.delay }} - --random-error={{ .Values.faults.error }} - --config-path=/podinfo/config + {{- range .Values.backends }} + - --backend-url={{ . }} + {{- end }} env: {{- if .Values.message }} - name: PODINFO_UI_MESSAGE diff --git a/charts/podinfo/values.yaml b/charts/podinfo/values.yaml index 886e6ca3..afe2d86a 100644 --- a/charts/podinfo/values.yaml +++ b/charts/podinfo/values.yaml @@ -1,24 +1,25 @@ # Default values for podinfo. image: repository: stefanprodan/podinfo - tag: 2.0.0 + tag: 3.1.0 pullPolicy: IfNotPresent podAnnotations: {} service: + enabled: false type: ClusterIP port: 9898 hpa: enabled: true minReplicas: 2 - maxReplicas: 2 + maxReplicas: 4 cpu: 80 memory: 512Mi canary: - enabled: true + enabled: false # Istio traffic policy tls can be DISABLE or ISTIO_MUTUAL istioTLS: DISABLE istioIngress: @@ -71,6 +72,7 @@ fullnameOverride: "" logLevel: info backend: #http://backend-podinfo:9898/echo +backends: [] message: #UI greetings faults: diff --git a/docs/gitbook/tutorials/canary-helm-gitops.md b/docs/gitbook/tutorials/canary-helm-gitops.md index f8527fc6..5727e854 100644 --- a/docs/gitbook/tutorials/canary-helm-gitops.md +++ b/docs/gitbook/tutorials/canary-helm-gitops.md @@ -51,7 +51,7 @@ helm upgrade -i frontend flagger/podinfo \ --namespace test \ --set nameOverride=frontend \ --set backend=http://backend.test:9898/echo \ ---set canary.loadtest.enabled=true \ +--set canary.enabled=true \ --set canary.istioIngress.enabled=true \ --set canary.istioIngress.gateway=public-gateway.istio-system.svc.cluster.local \ --set canary.istioIngress.host=frontend.istio.example.com @@ -91,7 +91,7 @@ Now let's install the `backend` release without exposing it outside the mesh: helm upgrade -i backend flagger/podinfo \ --namespace test \ --set nameOverride=backend \ ---set canary.loadtest.enabled=true \ +--set canary.enabled=true \ --set canary.istioIngress.enabled=false ``` @@ -138,7 +138,7 @@ helm upgrade -i frontend flagger/podinfo/ \ --reuse-values \ --set canary.loadtest.enabled=true \ --set canary.helmtest.enabled=true \ ---set image.tag=2.0.1 +--set image.tag=3.1.1 ``` Flagger detects that the deployment revision changed and starts the canary analysis: @@ -177,6 +177,7 @@ Now trigger a canary deployment for the `backend` app, but this time you'll chan helm upgrade -i backend flagger/podinfo/ \ --namespace test \ --reuse-values \ +--set canary.loadtest.enabled=true \ --set canary.helmtest.enabled=true \ --set httpServer.timeout=25s ``` @@ -283,7 +284,7 @@ metadata: namespace: test annotations: flux.weave.works/automated: "true" - flux.weave.works/tag.chart-image: semver:~2.0 + flux.weave.works/tag.chart-image: semver:~3.1 spec: releaseName: frontend chart: @@ -293,7 +294,7 @@ spec: values: image: repository: stefanprodan/podinfo - tag: 2.0.0 + tag: 3.1.0 backend: http://backend-podinfo:9898/echo canary: enabled: true @@ -311,7 +312,7 @@ In the `chart` section I've defined the release source by specifying the Helm re In the `values` section I've overwritten the defaults set in values.yaml. With the `flux.weave.works` annotations I instruct Flux to automate this release. -When an image tag in the sem ver range of `2.0.0 - 2.0.99` is pushed to Quay, +When an image tag in the sem ver range of `3.1.0 - 3.1.99` is pushed to Docker Hub, Flux will upgrade the Helm release and from there Flagger will pick up the change and start a canary deployment. Install [Weave Flux](https://github.com/weaveworks/flux) and its Helm Operator by specifying your Git repo URL: @@ -344,9 +345,9 @@ launch the `frontend` and `backend` apps. A CI/CD pipeline for the `frontend` release could look like this: -* cut a release from the master branch of the podinfo code repo with the git tag `2.0.1` -* CI builds the image and pushes the `podinfo:2.0.1` image to the container registry -* Flux scans the registry and updates the Helm release `image.tag` to `2.0.1` +* cut a release from the master branch of the podinfo code repo with the git tag `3.1.1` +* CI builds the image and pushes the `podinfo:3.1.1` image to the container registry +* Flux scans the registry and updates the Helm release `image.tag` to `3.1.1` * Flux commits and push the change to the cluster repo * Flux applies the updated Helm release on the cluster * Flux Helm Operator picks up the change and calls Tiller to upgrade the release @@ -354,9 +355,9 @@ A CI/CD pipeline for the `frontend` release could look like this: * Flagger runs the helm test before routing traffic to the canary service * Flagger starts the load test and runs the canary analysis * Based on the analysis result the canary deployment is promoted to production or rolled back -* Flagger sends a Slack notification with the canary result +* Flagger sends a Slack or MS Teams notification with the canary result -If the canary fails, fix the bug, do another patch release eg `2.0.2` and the whole process will run again. +If the canary fails, fix the bug, do another patch release eg `3.1.2` and the whole process will run again. A canary deployment can fail due to any of the following reasons: diff --git a/kustomize/podinfo/deployment.yaml b/kustomize/podinfo/deployment.yaml index a0b88aa9..ef6b0cd9 100644 --- a/kustomize/podinfo/deployment.yaml +++ b/kustomize/podinfo/deployment.yaml @@ -10,7 +10,7 @@ spec: progressDeadlineSeconds: 60 strategy: rollingUpdate: - maxUnavailable: 0 + maxUnavailable: 1 type: RollingUpdate selector: matchLabels: @@ -24,21 +24,27 @@ spec: spec: containers: - name: podinfod - image: stefanprodan/podinfo:2.0.0 + image: stefanprodan/podinfo:3.1.0 imagePullPolicy: IfNotPresent ports: - - containerPort: 9898 - name: http + - name: http + containerPort: 9898 + protocol: TCP + - name: http-metrics + containerPort: 9797 + protocol: TCP + - name: grpc + containerPort: 9999 protocol: TCP command: - ./podinfo - --port=9898 + - --port-metrics=9797 + - --grpc-port=9999 + - --grpc-service-name=podinfo - --level=info - --random-delay=false - --random-error=false - env: - - name: PODINFO_UI_COLOR - value: blue livenessProbe: exec: command: From d6027af632b13bcc916e58acd9d6e92934ad91d9 Mon Sep 17 00:00:00 2001 From: stefanprodan Date: Fri, 27 Sep 2019 16:33:06 +0300 Subject: [PATCH 3/6] Update go to 1.13 in CI --- .circleci/config.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index dc4aac5c..a9942efa 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -3,7 +3,7 @@ jobs: build-binary: docker: - - image: circleci/golang:1.12 + - image: circleci/golang:1.13 working_directory: ~/build steps: - checkout @@ -44,7 +44,7 @@ jobs: push-container: docker: - - image: circleci/golang:1.12 + - image: circleci/golang:1.13 steps: - checkout - setup_remote_docker: @@ -56,7 +56,7 @@ jobs: push-binary: docker: - - image: circleci/golang:1.12 + - image: circleci/golang:1.13 working_directory: ~/build steps: - checkout @@ -149,7 +149,7 @@ jobs: push-helm-charts: docker: - - image: circleci/golang:1.12 + - image: circleci/golang:1.13 steps: - checkout - run: From 7b7306584f27cb5d3919a33c3c2b14c125b5a8cb Mon Sep 17 00:00:00 2001 From: stefanprodan Date: Fri, 27 Sep 2019 16:33:56 +0300 Subject: [PATCH 4/6] Update alpine to 3.10 --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index f0cf8bd3..85af4aa8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM alpine:3.9 +FROM alpine:3.10 RUN addgroup -S flagger \ && adduser -S -g flagger flagger \ From 7a4e0bc80cc0f082f82ae606cffa70ea2e2f993b Mon Sep 17 00:00:00 2001 From: stefanprodan Date: Fri, 27 Sep 2019 16:53:55 +0300 Subject: [PATCH 5/6] Update go mod to 1.13 --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index e5cddb7d..26cb7569 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/weaveworks/flagger -go 1.12 +go 1.13 require ( cloud.google.com/go v0.37.4 // indirect From 053d0da617588fc34841498ab4c2d5dc90863688 Mon Sep 17 00:00:00 2001 From: stefanprodan Date: Fri, 27 Sep 2019 16:59:15 +0300 Subject: [PATCH 6/6] Remove thrift replace from go.mod --- go.mod | 1 - 1 file changed, 1 deletion(-) diff --git a/go.mod b/go.mod index 26cb7569..fd0ae8e2 100644 --- a/go.mod +++ b/go.mod @@ -56,7 +56,6 @@ require ( ) replace ( - git.apache.org/thrift.git => github.com/apache/thrift v0.12.0 github.com/google/uuid => github.com/google/uuid v1.0.0 golang.org/x/crypto => golang.org/x/crypto v0.0.0-20181025213731-e84da0312774 golang.org/x/net => golang.org/x/net v0.0.0-20190206173232-65e2d4e15006