Skip to content

Commit

Permalink
Merge pull request #1324 from porter-dev/sms/proto-deployment-strat
Browse files Browse the repository at this point in the history
support bluegreen rollouts on worker and web
  • Loading branch information
stefanmcshane authored Jul 8, 2024
2 parents ddf8d20 + 2b0ad10 commit 07572ee
Show file tree
Hide file tree
Showing 4 changed files with 176 additions and 2 deletions.
69 changes: 69 additions & 0 deletions applications/web/templates/deployment-analysis-template.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{{- if eq .Values.deploymentStrategy.kind "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:
serviceAccountName: {{ include "docker-template.fullname" . }}-aj
containers:
- name: rollout-sync
image: ghcr.io/porter-dev/rollout-sync:latest
command: [sh, -c]
args:
{{- 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
---
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", "patch"]
---
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 }}
22 changes: 20 additions & 2 deletions applications/web/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -9,11 +14,24 @@ metadata:
{{- toYaml .Values.labels | nindent 4 }}
{{- end }}
spec:
{{- if eq .Values.deploymentStrategy.kind "blueGreen" }}
strategy:
blueGreen:
activeService: {{ include "docker-template.fullname" . }}
autoPromotionEnabled: true
scaleDownDelayRevisionLimit: 5
previewMetadata:
labels:
role: preview
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 }}
Expand Down
69 changes: 69 additions & 0 deletions applications/worker/templates/deployment-analysis-template.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{{- if eq .Values.deploymentStrategy.kind "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:
serviceAccountName: {{ include "docker-template.fullname" . }}-aj
containers:
- name: rollout-sync
image: ghcr.io/porter-dev/rollout-sync:latest
command: [sh, -c]
args:
{{- 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
---
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", "patch"]
---
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 }}
18 changes: 18 additions & 0 deletions applications/worker/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -8,6 +13,19 @@ metadata:
{{- toYaml .Values.labels | nindent 4 }}
{{- end }}
spec:
{{- if eq .Values.deploymentStrategy.kind "blueGreen" }}
strategy:
blueGreen:
activeService: {{ include "docker-template.fullname" . }}
autoPromotionEnabled: true
scaleDownDelayRevisionLimit: 5
previewMetadata:
labels:
role: preview
prePromotionAnalysis:
templates:
- templateName: {{ include "docker-template.fullname" . }}-bluegreen
{{- end }}
{{- if and (not .Values.keda.enabled) (not .Values.autoscaling.enabled) }}
replicas: {{ .Values.replicaCount }}
{{ end }}
Expand Down

0 comments on commit 07572ee

Please sign in to comment.