diff --git a/README.md b/README.md index 0973d5a..5f42d36 100644 --- a/README.md +++ b/README.md @@ -13,5 +13,4 @@ to explore ArgoCD and GitOps! | [kustomize-guestbook](kustomize-guestbook/) | The guestbook application as a kustomize app | | [pre-post-sync](pre-post-sync/) | Demonstrates Argo CD PreSync and PostSync hooks | | [blue-green-deploy](blue-green-deploy/) | Demonstrates an Argo CD Sync hook which performs a blue/green deployment | -| [blue-green-deploy-workflow](blue-green-deploy-workflow/) | Demonstrates an ArgoCD Sync hook which performs a blue/green deployment as an Argo Workflow | | [sock-shop](sock-shop/) | A microservices demo application (https://microservices-demo.github.io) | diff --git a/blue-green-deploy-workflow/.gitignore b/blue-green-deploy-workflow/.gitignore deleted file mode 100644 index f8714d3..0000000 --- a/blue-green-deploy-workflow/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -/lib -/.ksonnet/registries -/app.override.yaml -/.ks_environment diff --git a/blue-green-deploy-workflow/app.yaml b/blue-green-deploy-workflow/app.yaml deleted file mode 100644 index 3ece49c..0000000 --- a/blue-green-deploy-workflow/app.yaml +++ /dev/null @@ -1,11 +0,0 @@ -apiVersion: 0.1.0 -environments: - default: - destination: - namespace: default - server: https://kubernetes.default.svc - k8sVersion: v1.10.0 - path: default -kind: ksonnet.io/app -name: blue-green-deploy-workflow -version: 0.0.1 diff --git a/blue-green-deploy-workflow/components/bg-guestbook.jsonnet b/blue-green-deploy-workflow/components/bg-guestbook.jsonnet deleted file mode 100644 index f6e83a6..0000000 --- a/blue-green-deploy-workflow/components/bg-guestbook.jsonnet +++ /dev/null @@ -1,64 +0,0 @@ -local env = std.extVar("__ksonnet/environments"); -local params = std.extVar("__ksonnet/params").components["bg-guestbook"]; -[ - { - "apiVersion": "v1", - "kind": "Service", - "metadata": { - "name": params.name, - "annotations": { - "argocd.argoproj.io/hook": "Skip", - }, - }, - "spec": { - "ports": [ - { - "port": params.servicePort, - "targetPort": params.containerPort - } - ], - "selector": { - "app": params.name - }, - "type": params.type - } - }, - { - "apiVersion": "apps/v1beta2", - "kind": "Deployment", - "metadata": { - "name": params.name, - "annotations": { - "argocd.argoproj.io/hook": "Skip", - }, - }, - "spec": { - "replicas": params.replicas, - "selector": { - "matchLabels": { - "app": params.name - }, - }, - "template": { - "metadata": { - "labels": { - "app": params.name - } - }, - "spec": { - "containers": [ - { - "image": params.image, - "name": params.name, - "ports": [ - { - "containerPort": params.containerPort - } - ] - } - ] - } - } - } - } -] diff --git a/blue-green-deploy-workflow/components/bg-workflow.jsonnet b/blue-green-deploy-workflow/components/bg-workflow.jsonnet deleted file mode 100644 index c14af2a..0000000 --- a/blue-green-deploy-workflow/components/bg-workflow.jsonnet +++ /dev/null @@ -1,20 +0,0 @@ -local bgGuestbook = std.extVar("__ksonnet/components")["bg-guestbook"]; -local bgGuestbookSvc = bgGuestbook[0]; -local bgGuestbookDeploy = bgGuestbook[1]; -local parseYaml = std.native("parseYaml"); -local bgWorkflow = parseYaml(importstr 'wf/bluegreen.yaml')[0]; - -[ - bgWorkflow + { - spec +: { - arguments +: { - parameters : [ - {name: "deployment-name", value: bgGuestbookDeploy.metadata.name}, - {name: "service-name", value: bgGuestbookSvc.metadata.name}, - {name: "new-deployment-manifest", value: std.manifestJson(bgGuestbookDeploy)}, - {name: "new-service-manifest", value: std.manifestJson(bgGuestbookSvc)}, - ], - }, - }, - } -] \ No newline at end of file diff --git a/blue-green-deploy-workflow/components/params.libsonnet b/blue-green-deploy-workflow/components/params.libsonnet deleted file mode 100644 index 4e14e47..0000000 --- a/blue-green-deploy-workflow/components/params.libsonnet +++ /dev/null @@ -1,19 +0,0 @@ -{ - global: { - // User-defined global parameters; accessible to all component and environments, Ex: - // replicas: 4, - }, - components: { - // Component-level parameters, defined initially from 'ks prototype use ...' - // Each object below should correspond to a component in the components/ directory - "bg-guestbook": { - containerPort: 80, - image: "gcr.io/heptio-images/ks-guestbook-demo:0.2", - name: "bg-guestbook", - replicas: 3, - servicePort: 80, - type: "LoadBalancer", - }, - "bg-workflow": {}, - }, -} diff --git a/blue-green-deploy-workflow/components/wf/bluegreen.yaml b/blue-green-deploy-workflow/components/wf/bluegreen.yaml deleted file mode 100644 index 27dce4a..0000000 --- a/blue-green-deploy-workflow/components/wf/bluegreen.yaml +++ /dev/null @@ -1,150 +0,0 @@ -# This workflow performs a "blue-green" deployment, while preserving the original deployment object -# and name. It accomplishes this by temporarily redirecting traffic to a *clone* of the original -# deployment. Then after upgrading the original deployment to a later version, redirects traffic -# back to the original (now upgraded) deployment. -apiVersion: argoproj.io/v1alpha1 -kind: Workflow -metadata: - generateName: k8s-bluegreen- - annotations: - argocd.argoproj.io/hook: Sync -spec: - entrypoint: k8s-bluegreen - arguments: - parameters: - - name: deployment-name - - name: service-name - - name: new-deployment-manifest - - name: new-service-manifest - - templates: - - name: k8s-bluegreen - steps: - # 1. Create a parallel Kubernetes deployment with tweaks to name and selectors - - - name: create-blue-deployment - template: clone-deployment - - # 2. Wait for parallel deployment to become ready - - - name: wait-for-blue-deployment - template: wait-deployment-ready - arguments: - parameters: - - name: deployment-name - value: '{{workflow.parameters.deployment-name}}-blue' - - # 3. Patch the named service to point to the parallel deployment app - - - name: switch-service-to-blue-deployment - template: patch-service - - # 4. Update the original deployment (receiving no traffic) with a new version - - - name: apply-green-deployment - template: apply-manifest - arguments: - parameters: - - name: manifest - value: '{{workflow.parameters.new-deployment-manifest}}' - - # 5. Wait for the original deployment, now updated, to become ready - - - name: wait-for-green-deployment - template: wait-deployment-ready - arguments: - parameters: - - name: deployment-name - value: '{{workflow.parameters.deployment-name}}' - - # dummy approval step for demo purposes. Sleeps for 30 seconds - - - name: approve - template: approve - - # 6. Patch the named service to point to the original, now updated app - - - name: switch-service-to-green-deployment - template: apply-manifest - arguments: - parameters: - - name: manifest - value: '{{workflow.parameters.new-service-manifest}}' - - # 7. Remove the cloned deployment (no longer receiving traffic) - - - name: delete-cloned-deployment - template: delete-deployment - -# end of steps - - # clone-deployment creates a "blue" clone of an existing deployment. The string -blue is appended to: - # - metadata.name - # - spec.selector.matchLabels - # - spec.template.metadata.labels - - name: clone-deployment - container: - image: argoproj/argoexec:v2.1.1 - command: [sh, -c, -x] - args: - - kubectl get --export -o json deployment.apps/{{workflow.parameters.deployment-name}} > /original-deploy && - jq -r '.metadata.name+="-blue" | - .spec.template.metadata.labels += (.spec.template.metadata.labels | to_entries | map(select(.key != "app.kubernetes.io/instance")) | map(.value+="-blue") | from_entries) | - .spec.selector.matchLabels += (.spec.selector.matchLabels | to_entries | map(select(.key != "app.kubernetes.io/instance")) | map(.value+="-blue") | from_entries)' - /original-deploy > /cloned-deploy && - cat /cloned-deploy && - kubectl apply -o yaml -f /cloned-deploy - - # apply-manifest takes a kubernetes manifest and carrys over the app-name label (if present) - # before running `kubectl apply`. The label is used by ArgoCD for monitoring. - - name: apply-manifest - inputs: - parameters: - - name: manifest - artifacts: - - name: manifest-file - path: /manifest - raw: - data: '{{inputs.parameters.manifest}}' - container: - image: argoproj/argoexec:v2.1.1 - command: [sh, -c, -x] - args: - - cp /manifest /manifest-new && - APP_NAME=$(kubectl get -f /manifest-new -o json | jq -r '.metadata.labels."app.kubernetes.io/instance"') && - if [ "$APP_NAME" != "null" ]; then - jq -r --arg APP_NAME "$APP_NAME" '.metadata.labels."app.kubernetes.io/instance" = $APP_NAME' /manifest-new > /manifest-new.tmp && - mv /manifest-new.tmp /manifest-new && - if [ "$(jq -r .spec.template.metadata.labels /manifest-new)" != "null" ]; then - jq -r --arg APP_NAME "$APP_NAME" '.spec.template.metadata.labels."app.kubernetes.io/instance" = $APP_NAME' /manifest-new > /manifest-new.tmp && - mv /manifest-new.tmp /manifest-new ; - fi ; - fi && - cat /manifest-new && - kubectl apply -f /manifest-new - - # wait-deployment-ready waits for a deployment to become fully deployed and ready, using the - # `kubectl rollout` command - - name: wait-deployment-ready - inputs: - parameters: - - name: deployment-name - container: - image: argoproj/argoexec:v2.1.1 - command: [kubectl, rollout, status, --watch=true, 'deployments/{{inputs.parameters.deployment-name}}'] - - # patch-service updates the service selector labels to point to the "blue" deployment - - name: patch-service - container: - image: argoproj/argoexec:v2.1.1 - command: [sh, -c, -x] - args: - - kubectl get service {{workflow.parameters.service-name}} --export -o json > /original-svc && - jq '.spec.selector = (.spec.selector | with_entries(.value+="-blue"))' /original-svc > /blue-svc && - kubectl apply -o yaml -f /blue-svc - - - name: delete-deployment - resource: - action: delete - manifest: | - apiVersion: apps/v1 - kind: Deployment - metadata: - name: {{workflow.parameters.deployment-name}}-blue - - - name: approve - container: - image: argoproj/argoexec:v2.1.1 - command: [sleep, "30"] diff --git a/blue-green-deploy-workflow/environments/base.libsonnet b/blue-green-deploy-workflow/environments/base.libsonnet deleted file mode 100644 index a129aff..0000000 --- a/blue-green-deploy-workflow/environments/base.libsonnet +++ /dev/null @@ -1,4 +0,0 @@ -local components = std.extVar("__ksonnet/components"); -components + { - // Insert user-specified overrides here. -} diff --git a/blue-green-deploy-workflow/environments/default/globals.libsonnet b/blue-green-deploy-workflow/environments/default/globals.libsonnet deleted file mode 100644 index 7a73a41..0000000 --- a/blue-green-deploy-workflow/environments/default/globals.libsonnet +++ /dev/null @@ -1,2 +0,0 @@ -{ -} \ No newline at end of file diff --git a/blue-green-deploy-workflow/environments/default/main.jsonnet b/blue-green-deploy-workflow/environments/default/main.jsonnet deleted file mode 100644 index 58695a8..0000000 --- a/blue-green-deploy-workflow/environments/default/main.jsonnet +++ /dev/null @@ -1,8 +0,0 @@ -local base = import "base.libsonnet"; -// uncomment if you reference ksonnet-lib -// local k = import "k.libsonnet"; - -base + { - // Insert user-specified overrides here. For example if a component is named \"nginx-deployment\", you might have something like:\n") - // "nginx-deployment"+: k.deployment.mixin.metadata.labels({foo: "bar"}) -} diff --git a/blue-green-deploy-workflow/environments/default/params.libsonnet b/blue-green-deploy-workflow/environments/default/params.libsonnet deleted file mode 100644 index b6eb32d..0000000 --- a/blue-green-deploy-workflow/environments/default/params.libsonnet +++ /dev/null @@ -1,17 +0,0 @@ -local params = std.extVar("__ksonnet/params"); -local globals = import "globals.libsonnet"; -local envParams = params + { - components +: { - // Insert component parameter overrides here. Ex: - // guestbook +: { - // name: "guestbook-dev", - // replicas: params.global.replicas, - // }, - }, -}; - -{ - components: { - [x]: envParams.components[x] + globals, for x in std.objectFields(envParams.components) - }, -} diff --git a/blue-green-deploy/components/bg-guestbook.jsonnet b/blue-green-deploy/components/bg-guestbook.jsonnet index f6e83a6..7d10e12 100644 --- a/blue-green-deploy/components/bg-guestbook.jsonnet +++ b/blue-green-deploy/components/bg-guestbook.jsonnet @@ -34,6 +34,7 @@ local params = std.extVar("__ksonnet/params").components["bg-guestbook"]; }, "spec": { "replicas": params.replicas, + "revisionHistoryLimit": 3, "selector": { "matchLabels": { "app": params.name diff --git a/guestbook/README.md b/guestbook/README.md new file mode 100644 index 0000000..e69de29 diff --git a/guestbook/guestbook-ui-deployment.yaml b/guestbook/guestbook-ui-deployment.yaml index 45182ce..f9b5a83 100644 --- a/guestbook/guestbook-ui-deployment.yaml +++ b/guestbook/guestbook-ui-deployment.yaml @@ -4,6 +4,7 @@ metadata: name: guestbook-ui spec: replicas: 1 + revisionHistoryLimit: 3 selector: matchLabels: app: guestbook-ui diff --git a/guestbook/guestbook-ui-svc.yaml b/guestbook/guestbook-ui-svc.yaml deleted file mode 100644 index 918bbc5..0000000 --- a/guestbook/guestbook-ui-svc.yaml +++ /dev/null @@ -1,11 +0,0 @@ -apiVersion: v1 -kind: Service -metadata: - name: guestbook-ui -spec: - ports: - - port: 80 - targetPort: 80 - selector: - app: guestbook-ui - type: LoadBalancer diff --git a/helm-guestbook/templates/deployment.yaml b/helm-guestbook/templates/deployment.yaml index 6b14d3f..4be0e2d 100644 --- a/helm-guestbook/templates/deployment.yaml +++ b/helm-guestbook/templates/deployment.yaml @@ -9,6 +9,7 @@ metadata: heritage: {{ .Release.Service }} spec: replicas: {{ .Values.replicaCount }} + revisionHistoryLimit: 3 selector: matchLabels: app: {{ template "helm-guestbook.name" . }} diff --git a/jsonnet-guestbook/guestbook-ui.jsonnet b/jsonnet-guestbook/guestbook-ui.jsonnet index b1b377e..c5c0dbc 100644 --- a/jsonnet-guestbook/guestbook-ui.jsonnet +++ b/jsonnet-guestbook/guestbook-ui.jsonnet @@ -28,6 +28,7 @@ local params = import 'params.libsonnet'; }, "spec": { "replicas": params.replicas, + "revisionHistoryLimit": 3, "selector": { "matchLabels": { "app": params.name diff --git a/ksonnet-guestbook/components/guestbook-ui.jsonnet b/ksonnet-guestbook/components/guestbook-ui.jsonnet index a34f1ad..25ae460 100644 --- a/ksonnet-guestbook/components/guestbook-ui.jsonnet +++ b/ksonnet-guestbook/components/guestbook-ui.jsonnet @@ -28,6 +28,7 @@ local params = std.extVar("__ksonnet/params").components["guestbook-ui"]; }, "spec": { "replicas": params.replicas, + "revisionHistoryLimit": 3, "selector": { "matchLabels": { "app": params.name