From 3509ad21d8fbcac551250883d8add67340bafbb0 Mon Sep 17 00:00:00 2001 From: Stefan McShane Date: Wed, 3 Jul 2024 01:30:46 -0400 Subject: [PATCH 1/4] support bluegreen rollouts on worker and web --- .../deployment-analysis-template.yaml | 31 +++++++++++++++++++ applications/web/templates/deployment.yaml | 18 +++++++++-- .../deployment-analysis-template.yaml | 31 +++++++++++++++++++ applications/worker/templates/deployment.yaml | 14 +++++++++ 4 files changed, 92 insertions(+), 2 deletions(-) create mode 100644 applications/web/templates/deployment-analysis-template.yaml create mode 100644 applications/worker/templates/deployment-analysis-template.yaml diff --git a/applications/web/templates/deployment-analysis-template.yaml b/applications/web/templates/deployment-analysis-template.yaml new file mode 100644 index 000000000..42ad23474 --- /dev/null +++ b/applications/web/templates/deployment-analysis-template.yaml @@ -0,0 +1,31 @@ +{{- if eq .Values.deploymentStrategy.kind "blueGreen" }} +{{- if .Values.deploymentStrategy.blueGreen }} +kind: AnalysisTemplate +apiVersion: argoproj.io/v1alpha1 +metadata: + name: {{ include "docker-template.fullname" . }}-bluegreen +spec: + metrics: + - name: {{ include "docker-template.fullname" . }}-bluegreen + count: 1 + interval: 5s + failureLimit: 1 + provider: + job: + spec: + template: + spec: + containers: + - name: rollout-sync + image: ghcr.io/porter-dev/rollout-sync:latest + command: [sh, -c] + args: + {{- if .Values.deploymentStrategy.blueGreen.partnerApps }} + - rollout sync --strategy blue-green --blue-green-apps {{ range $index, $app := .Values.deploymentStrategy.blueGreen.partnerApps }}{{ if $index }},{{ end }}{{ $app }}{{ end }} + {{- else }} + - rollout sync --strategy blue-green --blue-green-apps {{ include "docker-template.fullname" . }} + {{- end }} + restartPolicy: Never + backoffLimit: 0 +{{- end }} +{{- end }} \ No newline at end of file diff --git a/applications/web/templates/deployment.yaml b/applications/web/templates/deployment.yaml index 94c6ebfda..f98fc8d06 100644 --- a/applications/web/templates/deployment.yaml +++ b/applications/web/templates/deployment.yaml @@ -1,6 +1,11 @@ {{- if and (not .Values.statefulset.enabled) (or (not .Values.bluegreen.disablePrimaryDeployment) (eq (len .Values.bluegreen.imageTags) 0)) -}} +{{- if eq .Values.deploymentStrategy.kind "blueGreen" }} +apiVersion: argoproj.io/v1alpha1 +kind: Rollout +{{- else }} apiVersion: apps/v1 kind: Deployment +{{- end }} metadata: name: {{ include "docker-template.fullname" . }} labels: @@ -9,11 +14,20 @@ metadata: {{- toYaml .Values.labels | nindent 4 }} {{- end }} spec: + {{- if eq .Values.deploymentStrategy.kind "blueGreen" }} + strategy: + blueGreen: + activeService: {{ include "docker-template.fullname" . }} + autoPromotionEnabled: false + prePromotionAnalysis: + templates: + - templateName: {{ include "docker-template.fullname" . }}-bluegreen + {{- end }} {{- if not .Values.autoscaling.enabled }} {{- if not .Values.keda.enabled }} replicas: {{ .Values.replicaCount }} - {{ end }} - {{ end }} + {{- end }} + {{- end }} selector: matchLabels: {{- include "docker-template.selectorLabels" . | nindent 6 }} diff --git a/applications/worker/templates/deployment-analysis-template.yaml b/applications/worker/templates/deployment-analysis-template.yaml new file mode 100644 index 000000000..42ad23474 --- /dev/null +++ b/applications/worker/templates/deployment-analysis-template.yaml @@ -0,0 +1,31 @@ +{{- if eq .Values.deploymentStrategy.kind "blueGreen" }} +{{- if .Values.deploymentStrategy.blueGreen }} +kind: AnalysisTemplate +apiVersion: argoproj.io/v1alpha1 +metadata: + name: {{ include "docker-template.fullname" . }}-bluegreen +spec: + metrics: + - name: {{ include "docker-template.fullname" . }}-bluegreen + count: 1 + interval: 5s + failureLimit: 1 + provider: + job: + spec: + template: + spec: + containers: + - name: rollout-sync + image: ghcr.io/porter-dev/rollout-sync:latest + command: [sh, -c] + args: + {{- if .Values.deploymentStrategy.blueGreen.partnerApps }} + - rollout sync --strategy blue-green --blue-green-apps {{ range $index, $app := .Values.deploymentStrategy.blueGreen.partnerApps }}{{ if $index }},{{ end }}{{ $app }}{{ end }} + {{- else }} + - rollout sync --strategy blue-green --blue-green-apps {{ include "docker-template.fullname" . }} + {{- end }} + restartPolicy: Never + backoffLimit: 0 +{{- end }} +{{- end }} \ No newline at end of file diff --git a/applications/worker/templates/deployment.yaml b/applications/worker/templates/deployment.yaml index df3058adb..862e91c02 100644 --- a/applications/worker/templates/deployment.yaml +++ b/applications/worker/templates/deployment.yaml @@ -1,5 +1,10 @@ +{{- if eq .Values.deploymentStrategy.kind "blueGreen" }} +apiVersion: argoproj.io/v1alpha1 +kind: Rollout +{{- else }} apiVersion: apps/v1 kind: Deployment +{{- end }} metadata: name: {{ include "docker-template.fullname" . }} labels: @@ -8,6 +13,15 @@ metadata: {{- toYaml .Values.labels | nindent 4 }} {{- end }} spec: + {{- if eq .Values.deploymentStrategy.kind "blueGreen" }} + strategy: + blueGreen: + activeService: {{ include "docker-template.fullname" . }} + autoPromotionEnabled: false + prePromotionAnalysis: + templates: + - templateName: {{ include "docker-template.fullname" . }}-bluegreen + {{- end }} {{- if and (not .Values.keda.enabled) (not .Values.autoscaling.enabled) }} replicas: {{ .Values.replicaCount }} {{ end }} From 145e701201e38b755069349476e7d8506df67745 Mon Sep 17 00:00:00 2001 From: Stefan McShane Date: Wed, 3 Jul 2024 01:37:32 -0400 Subject: [PATCH 2/4] support bluegreen rollouts on worker and web --- applications/web/templates/deployment-analysis-template.yaml | 4 +--- .../worker/templates/deployment-analysis-template.yaml | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/applications/web/templates/deployment-analysis-template.yaml b/applications/web/templates/deployment-analysis-template.yaml index 42ad23474..0e7cf5eb3 100644 --- a/applications/web/templates/deployment-analysis-template.yaml +++ b/applications/web/templates/deployment-analysis-template.yaml @@ -1,5 +1,4 @@ {{- if eq .Values.deploymentStrategy.kind "blueGreen" }} -{{- if .Values.deploymentStrategy.blueGreen }} kind: AnalysisTemplate apiVersion: argoproj.io/v1alpha1 metadata: @@ -20,12 +19,11 @@ spec: image: ghcr.io/porter-dev/rollout-sync:latest command: [sh, -c] args: - {{- if .Values.deploymentStrategy.blueGreen.partnerApps }} + {{- if and (.Values.deploymentStrategy.blueGreen) (.Values.deploymentStrategy.blueGreen.partnerApps) }} - rollout sync --strategy blue-green --blue-green-apps {{ range $index, $app := .Values.deploymentStrategy.blueGreen.partnerApps }}{{ if $index }},{{ end }}{{ $app }}{{ end }} {{- else }} - rollout sync --strategy blue-green --blue-green-apps {{ include "docker-template.fullname" . }} {{- end }} restartPolicy: Never backoffLimit: 0 -{{- end }} {{- end }} \ No newline at end of file diff --git a/applications/worker/templates/deployment-analysis-template.yaml b/applications/worker/templates/deployment-analysis-template.yaml index 42ad23474..0e7cf5eb3 100644 --- a/applications/worker/templates/deployment-analysis-template.yaml +++ b/applications/worker/templates/deployment-analysis-template.yaml @@ -1,5 +1,4 @@ {{- if eq .Values.deploymentStrategy.kind "blueGreen" }} -{{- if .Values.deploymentStrategy.blueGreen }} kind: AnalysisTemplate apiVersion: argoproj.io/v1alpha1 metadata: @@ -20,12 +19,11 @@ spec: image: ghcr.io/porter-dev/rollout-sync:latest command: [sh, -c] args: - {{- if .Values.deploymentStrategy.blueGreen.partnerApps }} + {{- if and (.Values.deploymentStrategy.blueGreen) (.Values.deploymentStrategy.blueGreen.partnerApps) }} - rollout sync --strategy blue-green --blue-green-apps {{ range $index, $app := .Values.deploymentStrategy.blueGreen.partnerApps }}{{ if $index }},{{ end }}{{ $app }}{{ end }} {{- else }} - rollout sync --strategy blue-green --blue-green-apps {{ include "docker-template.fullname" . }} {{- end }} restartPolicy: Never backoffLimit: 0 -{{- end }} {{- end }} \ No newline at end of file From 61604cb1ea2eca5c739f66b65397bd2831fefb0f Mon Sep 17 00:00:00 2001 From: Stefan McShane Date: Wed, 3 Jul 2024 13:25:53 -0400 Subject: [PATCH 3/4] support bluegreen rollouts on worker and web --- .../deployment-analysis-template.yaml | 40 +++++++++++++++++++ applications/web/templates/deployment.yaml | 3 ++ .../deployment-analysis-template.yaml | 40 +++++++++++++++++++ applications/worker/templates/deployment.yaml | 3 ++ 4 files changed, 86 insertions(+) diff --git a/applications/web/templates/deployment-analysis-template.yaml b/applications/web/templates/deployment-analysis-template.yaml index 0e7cf5eb3..2da682d0f 100644 --- a/applications/web/templates/deployment-analysis-template.yaml +++ b/applications/web/templates/deployment-analysis-template.yaml @@ -14,6 +14,7 @@ spec: spec: template: spec: + serviceAccountName: {{ include "docker-template.fullname" . }}-aj containers: - name: rollout-sync image: ghcr.io/porter-dev/rollout-sync:latest @@ -26,4 +27,43 @@ spec: {{- end }} restartPolicy: Never backoffLimit: 0 +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + name: {{ include "docker-template.fullname" . }}-aj +rules: +- apiGroups: [""] + resources: ["pods"] + verbs: ["get", "list"] +- apiGroups: ["apps"] + resources: ["replicasets"] + verbs: ["get", "list"] +- apiGroups: ["argoproj.io"] + resources: ["rollouts"] + verbs: ["get", "list"] +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + name: {{ include "docker-template.fullname" . }}-aj +subjects: +- kind: ServiceAccount + name: {{ include "docker-template.fullname" . }}-aj + namespace: {{ $.Release.Namespace }} +roleRef: + kind: ClusterRole + name: {{ include "docker-template.fullname" . }}-aj + apiGroup: rbac.authorization.k8s.io +--- +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ include "docker-template.fullname" . }}-aj + labels: + {{- include "docker-template.labels" . | nindent 4 }} + {{- with .Values.serviceAccount.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} {{- end }} \ No newline at end of file diff --git a/applications/web/templates/deployment.yaml b/applications/web/templates/deployment.yaml index f98fc8d06..fde0daeea 100644 --- a/applications/web/templates/deployment.yaml +++ b/applications/web/templates/deployment.yaml @@ -19,6 +19,9 @@ spec: blueGreen: activeService: {{ include "docker-template.fullname" . }} autoPromotionEnabled: false + previewMetadata: + labels: + role: preview prePromotionAnalysis: templates: - templateName: {{ include "docker-template.fullname" . }}-bluegreen diff --git a/applications/worker/templates/deployment-analysis-template.yaml b/applications/worker/templates/deployment-analysis-template.yaml index 0e7cf5eb3..2da682d0f 100644 --- a/applications/worker/templates/deployment-analysis-template.yaml +++ b/applications/worker/templates/deployment-analysis-template.yaml @@ -14,6 +14,7 @@ spec: spec: template: spec: + serviceAccountName: {{ include "docker-template.fullname" . }}-aj containers: - name: rollout-sync image: ghcr.io/porter-dev/rollout-sync:latest @@ -26,4 +27,43 @@ spec: {{- end }} restartPolicy: Never backoffLimit: 0 +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + name: {{ include "docker-template.fullname" . }}-aj +rules: +- apiGroups: [""] + resources: ["pods"] + verbs: ["get", "list"] +- apiGroups: ["apps"] + resources: ["replicasets"] + verbs: ["get", "list"] +- apiGroups: ["argoproj.io"] + resources: ["rollouts"] + verbs: ["get", "list"] +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + name: {{ include "docker-template.fullname" . }}-aj +subjects: +- kind: ServiceAccount + name: {{ include "docker-template.fullname" . }}-aj + namespace: {{ $.Release.Namespace }} +roleRef: + kind: ClusterRole + name: {{ include "docker-template.fullname" . }}-aj + apiGroup: rbac.authorization.k8s.io +--- +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ include "docker-template.fullname" . }}-aj + labels: + {{- include "docker-template.labels" . | nindent 4 }} + {{- with .Values.serviceAccount.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} {{- end }} \ No newline at end of file diff --git a/applications/worker/templates/deployment.yaml b/applications/worker/templates/deployment.yaml index 862e91c02..14405cedd 100644 --- a/applications/worker/templates/deployment.yaml +++ b/applications/worker/templates/deployment.yaml @@ -18,6 +18,9 @@ spec: blueGreen: activeService: {{ include "docker-template.fullname" . }} autoPromotionEnabled: false + previewMetadata: + labels: + role: preview prePromotionAnalysis: templates: - templateName: {{ include "docker-template.fullname" . }}-bluegreen From 2b0ad100b7f66e56255ecb5ae95bd0fe2aaf20b0 Mon Sep 17 00:00:00 2001 From: Stefan McShane Date: Wed, 3 Jul 2024 16:28:15 -0400 Subject: [PATCH 4/4] support bluegreen rollouts on worker and web --- applications/web/templates/deployment-analysis-template.yaml | 2 +- applications/web/templates/deployment.yaml | 3 ++- .../worker/templates/deployment-analysis-template.yaml | 2 +- applications/worker/templates/deployment.yaml | 3 ++- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/applications/web/templates/deployment-analysis-template.yaml b/applications/web/templates/deployment-analysis-template.yaml index 2da682d0f..3c8748ffc 100644 --- a/applications/web/templates/deployment-analysis-template.yaml +++ b/applications/web/templates/deployment-analysis-template.yaml @@ -41,7 +41,7 @@ rules: verbs: ["get", "list"] - apiGroups: ["argoproj.io"] resources: ["rollouts"] - verbs: ["get", "list"] + verbs: ["get", "list", "patch"] --- apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding diff --git a/applications/web/templates/deployment.yaml b/applications/web/templates/deployment.yaml index fde0daeea..02f37c48a 100644 --- a/applications/web/templates/deployment.yaml +++ b/applications/web/templates/deployment.yaml @@ -18,7 +18,8 @@ spec: strategy: blueGreen: activeService: {{ include "docker-template.fullname" . }} - autoPromotionEnabled: false + autoPromotionEnabled: true + scaleDownDelayRevisionLimit: 5 previewMetadata: labels: role: preview diff --git a/applications/worker/templates/deployment-analysis-template.yaml b/applications/worker/templates/deployment-analysis-template.yaml index 2da682d0f..3c8748ffc 100644 --- a/applications/worker/templates/deployment-analysis-template.yaml +++ b/applications/worker/templates/deployment-analysis-template.yaml @@ -41,7 +41,7 @@ rules: verbs: ["get", "list"] - apiGroups: ["argoproj.io"] resources: ["rollouts"] - verbs: ["get", "list"] + verbs: ["get", "list", "patch"] --- apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding diff --git a/applications/worker/templates/deployment.yaml b/applications/worker/templates/deployment.yaml index 14405cedd..0550edebf 100644 --- a/applications/worker/templates/deployment.yaml +++ b/applications/worker/templates/deployment.yaml @@ -17,7 +17,8 @@ spec: strategy: blueGreen: activeService: {{ include "docker-template.fullname" . }} - autoPromotionEnabled: false + autoPromotionEnabled: true + scaleDownDelayRevisionLimit: 5 previewMetadata: labels: role: preview