Skip to content

Commit

Permalink
Added support for Argo Rollouts
Browse files Browse the repository at this point in the history
  • Loading branch information
bastianeicher committed Apr 10, 2022
1 parent 7dd9e99 commit e4d9551
Show file tree
Hide file tree
Showing 9 changed files with 106 additions and 9 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ jobs:
kubectl apply -f https://raw.githubusercontent.com/prometheus-operator/prometheus-operator/main/example/prometheus-operator-crd/monitoring.coreos.com_servicemonitors.yaml
kubectl apply -f https://raw.githubusercontent.com/prometheus-operator/prometheus-operator/main/example/prometheus-operator-crd/monitoring.coreos.com_prometheusrules.yaml
kubectl apply -f https://raw.githubusercontent.com/istio/istio/master/manifests/charts/base/crds/crd-all.gen.yaml
kubectl apply -f https://raw.githubusercontent.com/argoproj/argo-rollouts/master/manifests/crds/rollout-crd.yaml
- name: Install charts
run: ct install --all
6 changes: 3 additions & 3 deletions charts/generic-service/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ This Helm chart simplifies deploying a typical "80% case" service on Kubernetes.
- [nginx Ingress Controller](https://kubernetes.github.io/ingress-nginx/) or [Istio](https://istio.io/) for routing
- [Prometheus Operator](https://github.com/prometheus-operator/prometheus-operator) for monitoring
- [OpenTelemetry Operator](https://github.com/open-telemetry/opentelemetry-operator) or [Jaeger Operator](https://www.jaegertracing.io/docs/latest/operator/) for tracing
- [Flagger](https://flagger.app/) for canary deployments
- [Flagger](https://flagger.app/) and [Argo Rollouts](https://argoproj.github.io/argo-rollouts/) for canary and blue-green deployments

The [Generic Service Grafana Dashboard](https://grafana.com/grafana/dashboards/14759) is a useful companion to this chart.

Expand Down Expand Up @@ -57,11 +57,11 @@ app:
| `resources.requests.cpu` | `10m` | The number of CPU cores requested for the service |
| `resources.limits.memory` | `96Mi` | The maximum amount of memory the service may use (recommendation: slightly higher than worst-case usage) |
| `resources.limits.cpu` | `2000m` | The maximum number of CPU cores the service may use |
| `rollout.controller` | `Deployment` | The type of `Pod` controller to create (`Deployment`, `StatefulSet` or `DaemonSet`) |
| `rollout.controller` | `Deployment` | The type of `Pod` controller to create (`Deployment`, `StatefulSet`, `DaemonSet` or `ArgoRollout`) |
| `rollout.strategy` | `RollingUpdate` | The rollout strategy (`RollingUpdate`, `Recreate`, `OnDelete`, `Canary` or `BlueGreen`) |
| `rollout.autoPromotion` | `true` | Automatically promote rollouts (if `rollout.strategy` is `BlueGreen` and `rollout.flagger` if `false`) |
| `rollout.flagger` | `false` | Use Flagger to control rollouts (`rollout.controller` must be `Deployment` or `StatefulSet`) |
| `rollout.analysis` | req. for Canary or Flagger | Flagger analysis for automatic `Canary` or `BlueGreen` promotion |
| `rollout.analysis` | req. for Canary or Flagger | Flagger or Argo Rollouts analysis for automatic `Canary` or `BlueGreen` promotion |
| `replicas` | `1` | The number of instances of the service to run (set at least `2` for Pod Disruption Budget) |
| `autoscaling.enabled` | `false` | Enables automatic starting of additional instances based on CPU load |
| `autoscaling.maxReplicas` | `3` | The maximum number of instances to run (must be larger than `replicas`) |
Expand Down
14 changes: 14 additions & 0 deletions charts/generic-service/ci/argo-values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Argo Rollout controller test

image:
repository: jwilder/whoami
tag: latest

ingress:
enabled: true
port: 8000

rollout:
controller: ArgoRollout
strategy: BlueGreen
autoPromotionEnabled: true
2 changes: 2 additions & 0 deletions charts/generic-service/templates/alerts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ metadata:

spec:
groups:
{{- if ne .Values.rollout.controller "ArgoRollout" }}
- name: {{ include "generic-service.fullname" . }}.rules
rules:
- alert: Down
Expand Down Expand Up @@ -37,6 +38,7 @@ spec:
annotations:
summary: '{{ include "generic-service.fullname" . }} replicas are down.'
description: '{{"{{ $value }}"}} replicas for {{ include "generic-service.fullname" . }} are down.'
{{- end }}
{{- end }}

- alert: MemoryUsageAboveRequest
Expand Down
5 changes: 5 additions & 0 deletions charts/generic-service/templates/autoscaler.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@ metadata:

spec:
scaleTargetRef:
{{- if eq .Values.rollout.controller "ArgoRollout" }}
apiVersion: argoproj.io/v1alpha1
kind: Rollout
{{- else }}
apiVersion: apps/v1
kind: {{ .Values.rollout.controller }}
{{- end }}
name: {{ include "generic-service.fullname" . }}
minReplicas: {{ .Values.replicas }}
maxReplicas: {{ .Values.autoscaling.maxReplicas }}
Expand Down
56 changes: 52 additions & 4 deletions charts/generic-service/templates/controller.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
{{- if eq .Values.rollout.controller "ArgoRollout" }}
apiVersion: argoproj.io/v1alpha1
kind: Rollout
{{- else }}
apiVersion: apps/v1
kind: {{ .Values.rollout.controller }}
{{- end }}

metadata:
name: {{ include "generic-service.fullname" . }}
labels: {{ include "generic-service.default-labels" . | nindent 4 }}
Expand All @@ -18,10 +24,16 @@ spec:

strategy:
{{- if eq .Values.rollout.strategy "RollingUpdate" }}
{{- if eq .Values.rollout.controller "ArgoRollout" }}
{{ fail "rollout.strategy cannot be StatefulSet if rollout.controller is ArgoRollout, must be Canary or BlueGreen" }}
{{- end }}
{{- else if eq .Values.rollout.strategy "Recreate" }}
{{- if or (eq .Values.rollout.controller "StatefulSet") (eq .Values.rollout.controller "DaemonSet") }}
{{ fail "rollout.strategy cannot be Recreate if rollout.controller is StatefulSet or DaemonSet, use OnDelete instead" }}
{{- end }}
{{- if eq .Values.rollout.controller "ArgoRollout" }}
{{ fail "rollout.strategy cannot be Recreate if rollout.controller is ArgoRollout, must be Canary or BlueGreen" }}
{{- end }}
type: Recreate
{{- else if eq .Values.rollout.strategy "OnDelete" }}
{{- if and (ne .Values.rollout.controller "StatefulSet") (ne .Values.rollout.controller "DaemonSet") }}
Expand All @@ -35,15 +47,51 @@ spec:
{{- if not .Values.ingress.domains }}
{{ fail "ingress.domains must not be empty if rollout.strategy is Canary" }}
{{- end }}
{{- if not .Values.rollout.flagger }}
{{ fail "rollout.flagger must be true if rollout.strategy is Canary" }}
{{- if eq .Values.rollout.controller "ArgoRollout" }}
canary:
stableService: {{ include "generic-service.fullname" . }}
stableMetadata:
labels:
role: stable
canaryService: {{ include "generic-service.fullname" . }}-preview
canaryMetadata:
labels:
role: preview
analysis: {{ toYaml (.Values.rollout.analysis | required "rollout.analysis is required if rollout.strategy is Canary") | nindent 8 }}
trafficRouting:
{{- if .Values.ingress.istio.enabled }}
istio:
virtualService:
name: {{ include "generic-service.fullname" . }}
{{- else if eq .Values.ingress.class "nginx" }}
nginx:
stableIngress: {{ include "generic-service.fullname" . }}
{{- else }}
{{ fail "Ingress must use Istio or nginx if rollout.strategy is Canary" }}
{{- end }}
{{- else if not .Values.rollout.flagger }}
{{ fail "rollout.flagger must be true or rollout.controller must be ArgoRollout if rollout.strategy is Canary" }}
{{- end }}
{{- else if eq .Values.rollout.strategy "BlueGreen" }}
{{- if not .Values.ingress.enabled }}
{{ fail "ingress.enabled must be true if rollout.strategy is BlueGreen" }}
{{- end }}
{{- if not .Values.rollout.flagger }}
{{ fail "rollout.flagger must be true if rollout.strategy is BlueGreen" }}
{{- if eq .Values.rollout.controller "ArgoRollout" }}
blueGreen:
activeService: {{ include "generic-service.fullname" . }}
activeMetadata:
labels:
role: stable
previewService: {{ include "generic-service.fullname" . }}-preview
previewMetadata:
labels:
role: preview
autoPromotionEnabled: {{ .Values.rollout.autoPromotion }}
{{- if .Values.rollout.analysis }}
prePromotionAnalysis: {{ toYaml .Values.rollout.analysis | nindent 8 }}
{{- end }}
{{- else if not .Values.rollout.flagger }}
{{ fail "rollout.flagger must be true or rollout.controller must be ArgoRollout if rollout.strategy is BlueGreen" }}
{{- end }}
{{ else }}
{{ fail "Unknown rollout.strategy" }}
Expand Down
3 changes: 3 additions & 0 deletions charts/generic-service/templates/monitoring.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ spec:
targetLabels:
- app
- release
{{- if eq .Values.rollout.controller "ArgoRollout" }}
- role
{{- end }}
---
apiVersion: v1
kind: Service
Expand Down
24 changes: 24 additions & 0 deletions charts/generic-service/templates/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,28 @@ spec:
port: 80
targetPort: {{ .Values.ingress.port }}

{{- if eq .Values.rollout.controller "ArgoRollout" }}
---
apiVersion: v1
kind: Service
metadata:
name: '{{ include "generic-service.fullname" . }}-preview'
labels: {{ include "generic-service.default-labels" . | nindent 4 }}

spec:
selector: {{ include "generic-service.selector-labels" . | nindent 4 }}
{{- if .Values.ingress.additionalSelectors }}
{{- .Values.ingress.additionalSelectors | toYaml | nindent 4 }}
{{- end }}

{{- if .Values.ingress.headless }}
clusterIP: None
{{- end }}

ports:
- name: '{{ .Values.ingress.protocol }}-ingress'
port: 80
targetPort: {{ .Values.ingress.port }}
{{- end }}

{{- end }}
4 changes: 2 additions & 2 deletions charts/generic-service/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@
"properties": {
"controller": {
"type": "string",
"enum": ["Deployment", "StatefulSet", "DaemonSet"],
"enum": ["Deployment", "StatefulSet", "DaemonSet", "ArgoRollout"],
"default": "Deployment",
"description": "The type of Pod controller to create"
},
Expand All @@ -213,7 +213,7 @@
"description": "Use Flagger to control rollouts (rollout.controller must be Deployment or StatefulSet)"
},
"analysis": {
"description": "Flagger analysis for automatic Canary or BlueGreen promotion"
"description": "Flagger or Argo Rollouts analysis for automatic Canary or BlueGreen promotion"
}
}
},
Expand Down

0 comments on commit e4d9551

Please sign in to comment.