From 737c6ca06ae07edd09e89fb34ec1601356d9f5d4 Mon Sep 17 00:00:00 2001 From: Gerald Nunn Date: Mon, 23 Oct 2023 13:56:22 -0700 Subject: [PATCH] Start adding inline analysis content --- .../base/analysistemplate.yaml | 42 ++++++++++ .../canary-analysis/base/kustomization.yaml | 5 ++ .../canary-analysis/base/rollout.yaml | 42 ++++++++++ .../examples/canary-analysis/base/routes.yaml | 44 ++++++++++ .../canary-analysis/base/services.yaml | 38 +++++++++ .../modules/ROOT/pages/05-canary-rollout.adoc | 83 ++++++++++++++++++- 6 files changed, 253 insertions(+), 1 deletion(-) create mode 100644 documentation/modules/ROOT/examples/canary-analysis/base/analysistemplate.yaml create mode 100644 documentation/modules/ROOT/examples/canary-analysis/base/kustomization.yaml create mode 100644 documentation/modules/ROOT/examples/canary-analysis/base/rollout.yaml create mode 100644 documentation/modules/ROOT/examples/canary-analysis/base/routes.yaml create mode 100644 documentation/modules/ROOT/examples/canary-analysis/base/services.yaml diff --git a/documentation/modules/ROOT/examples/canary-analysis/base/analysistemplate.yaml b/documentation/modules/ROOT/examples/canary-analysis/base/analysistemplate.yaml new file mode 100644 index 0000000..2a88a32 --- /dev/null +++ b/documentation/modules/ROOT/examples/canary-analysis/base/analysistemplate.yaml @@ -0,0 +1,42 @@ +kind: AnalysisTemplate +apiVersion: argoproj.io/v1alpha1 +metadata: + name: smoke-tests +spec: + args: + - name: query + - name: route-url + - name: api-token + valueFrom: + secretKeyRef: + name: monitor-auth-secret + key: token + metrics: + - name: success-rate + interval: 30s + count: 4 + # Prometheus queries return results in the form of a vector so it is + # common to access the index 0 of the returned array to obtain the value + successCondition: result[0].value[1] == '0' + failureLimit: 0 + provider: + web: + url: https://thanos-querier.openshift-monitoring:9091/api/v1/query?query={{ args.query }} + insecure: true + headers: + - key: Authorization + value: "Bearer {{args.api-token}}" + jsonPath: "{$.data.result}" + - name: run-load + provider: + job: + spec: + backoffLimit: 1 + template: + spec: + containers: + - name: siege + image: quay.io/gnunn/tools:latest + command: [sh, -c] + args: ["siege -c 20 -r 15 -d10 -v http://{{args.route-url}}"] + restartPolicy: Never diff --git a/documentation/modules/ROOT/examples/canary-analysis/base/kustomization.yaml b/documentation/modules/ROOT/examples/canary-analysis/base/kustomization.yaml new file mode 100644 index 0000000..4b1791d --- /dev/null +++ b/documentation/modules/ROOT/examples/canary-analysis/base/kustomization.yaml @@ -0,0 +1,5 @@ +resources: +- analysistemplate.yaml +- rollout.yaml +- services.yaml +- routes.yaml diff --git a/documentation/modules/ROOT/examples/canary-analysis/base/rollout.yaml b/documentation/modules/ROOT/examples/canary-analysis/base/rollout.yaml new file mode 100644 index 0000000..ec4466b --- /dev/null +++ b/documentation/modules/ROOT/examples/canary-analysis/base/rollout.yaml @@ -0,0 +1,42 @@ +apiVersion: argoproj.io/v1alpha1 +kind: Rollout +metadata: + name: rollouts-demo +spec: + replicas: 8 + revisionHistoryLimit: 10 + selector: + matchLabels: + app: rollouts-demo + template: + metadata: + labels: + app: rollouts-demo + spec: + containers: + - name: rollouts-demo + image: quay.io/openshiftdemos/rollouts-demo:blue + imagePullPolicy: IfNotPresent + ports: + - containerPort: 8080 + strategy: + canary: + canaryService: canary + stableService: stable + steps: + - setWeight: 20 + - analysis: + args: + - name: query + # Note encoded so it can be used as a query parameter, unencode: + # irate(haproxy_backend_http_responses_total{exported_namespace='rollouts-demo-prod',route=~'rollout-bluegreen-preview',code='5xx'}[1m])>5 or on() vector(0) + value: irate(haproxy_backend_http_responses_total%7Bexported_namespace='user%USER%-prod',route=~'canary',code='5xx'%7D%5B1m%5D)%3E5%20or%20on()%20vector(0) + - name: route-url + value: canary-user%USER%-prod.%SUB_DOMAIN% + templates: + - templateName: smoke-tests + - pause: {duration: 10s} + - setWeight: 60 + - pause: {duration: 10s} + - setWeight: 80 + - pause: {duration: 10s} diff --git a/documentation/modules/ROOT/examples/canary-analysis/base/routes.yaml b/documentation/modules/ROOT/examples/canary-analysis/base/routes.yaml new file mode 100644 index 0000000..d54e5b7 --- /dev/null +++ b/documentation/modules/ROOT/examples/canary-analysis/base/routes.yaml @@ -0,0 +1,44 @@ +apiVersion: route.openshift.io/v1 +kind: Route +metadata: + name: stable +spec: + port: + targetPort: http + tls: + insecureEdgeTerminationPolicy: Redirect + termination: edge + to: + kind: Service + name: stable +--- +apiVersion: route.openshift.io/v1 +kind: Route +metadata: + name: canary +spec: + port: + targetPort: http + tls: + insecureEdgeTerminationPolicy: Redirect + termination: edge + to: + kind: Service + name: canary +--- +apiVersion: route.openshift.io/v1 +kind: Route +metadata: + name: all + annotations: + haproxy.router.openshift.io/disable_cookies: 'true' + haproxy.router.openshift.io/balance: roundrobin +spec: + port: + targetPort: http + tls: + insecureEdgeTerminationPolicy: Redirect + termination: edge + to: + kind: Service + name: all diff --git a/documentation/modules/ROOT/examples/canary-analysis/base/services.yaml b/documentation/modules/ROOT/examples/canary-analysis/base/services.yaml new file mode 100644 index 0000000..a4d3c56 --- /dev/null +++ b/documentation/modules/ROOT/examples/canary-analysis/base/services.yaml @@ -0,0 +1,38 @@ +apiVersion: v1 +kind: Service +metadata: + name: stable +spec: + ports: + - name: http + protocol: TCP + port: 8080 + targetPort: 8080 + selector: + app: rollouts-demo +--- +apiVersion: v1 +kind: Service +metadata: + name: canary +spec: + ports: + - name: http + protocol: TCP + port: 8080 + targetPort: 8080 + selector: + app: rollouts-demo +--- +apiVersion: v1 +kind: Service +metadata: + name: all +spec: + ports: + - name: http + protocol: TCP + port: 8080 + targetPort: 8080 + selector: + app: rollouts-demo diff --git a/documentation/modules/ROOT/pages/05-canary-rollout.adoc b/documentation/modules/ROOT/pages/05-canary-rollout.adoc index f7e9227..a18170e 100644 --- a/documentation/modules/ROOT/pages/05-canary-rollout.adoc +++ b/documentation/modules/ROOT/pages/05-canary-rollout.adoc @@ -275,7 +275,88 @@ oc argo rollouts promote rollouts-demo -n user%USERNUM%-prod Observe the dashboard once it has been promoted, the dashboard will show the progression of the steps by highlight each step as it is being executed. +Prior to moving on to the next section, perform a cleanup to remove the current rollout +and reset the Deployment in the dev environment back to blue. + +Update the deployment: + +[.console-input] +[source,bash,subs="attributes+,+macros"] +---- +oc apply -k ./deploy/base -n user%USERNUM%-dev +---- + +Delete the current rollout: + +[.console-input] +[source,bash,subs="attributes+,+macros"] +---- +oc delete -k ./canary/base -n user%USERNUM%-prod +---- + [#inline-analysis] == Inline Analysis -In the last section there was a pause step that provided an opportunity +In the last section there was a pause step that provided an opportunity to test the canary +before progressing further. However we can accomplish the same goal my using an analysis. With +respect the canary strategy, an analysis can be performed in the link:https://argo-rollouts.readthedocs.io/en/stable/features/analysis/#background-analysis[background,window='_blank'] +or as an link:https://argo-rollouts.readthedocs.io/en/stable/features/analysis/#inline-analysis[inline] analysis. + +A background analysis happens asynchronously and does not block the progression of steps, however +if the analysis fails it will abort the rollout similar to what we saw in the previous module with +the blue-green strategy. In the case of an inline analysis, the analysis is performed as a step +and will block the progression of the rollout until it completes. + +The files for this example are in the `./canary-analysis/base` folder, to view the list of files +perform an `ls` as follows: + +[.console-input] +[source,bash,subs="attributes+,+macros"] +---- +ls ./canary-analysis/base +---- + +Note that the files are identical to the previous example other then the `rollout.yaml` and the +`analysistemplate.yaml` file. The AnalysisTemplate being used here is identical to the one +we used in the blue-green example so we will not cover it again here. + +The one change in the rollout is that it now as an inline analysis step. + +.link:https://github.com/OpenShiftDemos/argo-rollouts-workshop/blob/main/documentation/modules/ROOT/examples/canary-analysis/base/rollout.yaml[./canary-analysis/base/rollout.yaml,window='_blank'] +[source,yaml,subs="+macros,attributes+"] +---- +include::ROOT:example$canary-analysis/base/rollout.yaml[] +---- + +Notice that the structure of the inline analysis is identical to what was used in the `prePromotionAnalysis` +in the blue-green rollout with analysis. + +To deploy the canary with the inline analysis execute the following command: + +[.console-input] +[source,bash,subs="attributes+,+macros"] +---- +kustomize build ./canary-analysis/base | sed "s/%SUB_DOMAIN%/$SUB_DOMAIN/" | sed "s/%USER%/%USERNUM%/" | oc delete -n user%USERNUM%-prod -f - +---- + +Once the command has been executed, verify that the rollout was deployed: + +[.console-input] +[source,bash,subs="attributes+,+macros"] +---- +oc argo rollouts get rollout rollouts-demo -n user%USERNUM%-prod +---- + +You should see output as follows: + +[.console-output] +[source,bash,subs="attributes+,+macros"] +---- + + +---- + +Since we no longer have a manual pause step the promotion will occur automatically as long as the analysis step completes successfully. + +While the analysis is executing, or at anytime during the promotion, you can view the progress either in the dashboard or with the +Argo Rollouts kubectl command.