Skip to content

Commit

Permalink
Merge pull request #92 from shoplineapp/feature/support-argo-rollout
Browse files Browse the repository at this point in the history
feat: support argo rollout
  • Loading branch information
bluesky6529 authored Nov 16, 2022
2 parents 89c85ce + 45fa6cf commit f468d28
Show file tree
Hide file tree
Showing 7 changed files with 248 additions and 6 deletions.
2 changes: 1 addition & 1 deletion simple/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
apiVersion: v1
description: Helm chart with simple deployment/service template
name: simple
version: 0.10.0
version: 0.11.0
appVersion: 0.0.1
tillerVersion: ">=2.14.3"
3 changes: 1 addition & 2 deletions simple/templates/_service_multiple.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ spec:
{{- end}}
type: {{ $ref.type | default "ClusterIP" }}
selector:
app: {{ $service_name }}
app: {{ $ref.selector.app | default $service_name }}
{{- end }}
{{- end }}

{{- end -}}
14 changes: 14 additions & 0 deletions simple/templates/analysis.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{{- range $analysis_name, $ref := .Values.analyses }}
apiVersion: argoproj.io/v1alpha1
kind: AnalysisTemplate
metadata:
name: {{ $analysis_name }}
spec:
args:
{{- toYaml ($ref.spec).args | nindent 4 }}
metrics:
{{- toYaml ($ref.spec).metrics | nindent 4 }}
dryRun:
{{- toYaml ($ref.spec).dryRun | nindent 4 }}
---
{{- end }}
14 changes: 12 additions & 2 deletions simple/templates/hpa.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@ metadata:
name: {{ .Values.name }}
spec:
scaleTargetRef:
kind: Deployment
name: {{ .Values.name }}
{{- if .Values.rollout }}
kind: Rollout
apiVersion: argoproj.io/v1alpha1
{{- else }}
kind: Deployment
apiVersion: apps/v1
{{- end }}
minReplicas: {{ .Values.hpa.minReplicas }}
maxReplicas: {{ .Values.hpa.maxReplicas }}
targetCPUUtilizationPercentage: {{ .Values.hpa.targetCPUUtilizationPercentage }}
Expand All @@ -21,8 +26,13 @@ spec:
minReplicas: {{ .Values.hpav2.minReplicas }}
maxReplicas: {{ .Values.hpav2.maxReplicas }}
scaleTargetRef:
apiVersion: apps/v1
{{- if .Values.rollout }}
kind: Rollout
apiVersion: argoproj.io/v1alpha1
{{- else }}
kind: Deployment
apiVersion: apps/v1
{{- end }}
name: {{ .Values.name }}
metrics:
{{- range .Values.hpav2.Resource }}
Expand Down
144 changes: 144 additions & 0 deletions simple/templates/rollout.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
{{ if .Values.rollout }}
apiVersion: argoproj.io/v1alpha1
kind: Rollout
metadata:
name: {{ .Values.name }}
annotations:
{{- toYaml .Values.rollout.annotations | nindent 4 }}
spec:
{{- if .Values.hpa }}
replicas: {{ .Values.hpa.minReplicas }}
{{- else if .Values.hpav2 }}
replicas: {{ .Values.hpav2.minReplicas }}
{{- else if .Values.KEDA}}
replicas: {{ .Values.KEDA.ScaledObject.spec.minReplicaCount | default .Values.replicaCount }}
{{- else }}
replicas: {{ .Values.replicaCount }}
{{- end }}
selector:
matchLabels:
app: {{ .Values.name }}
workloadRef:
apiVersion: apps/v1
kind: Deployment
name: {{ .Values.name }}
strategy:
{{- if and .Values.rollout.strategy.blueGreen .Values.rollout.strategy.canary}}
{{ fail "blueGreen and canary can't exist at the same time"}}
{{ end }}
{{- if .Values.rollout.strategy.blueGreen }}
blueGreen:
{{- if .Values.services }}
{{- if and .Values.rollout.strategy.blueGreen.activeService .Values.rollout.strategy.blueGreen.previewService }}
activeService: {{ .Values.rollout.strategy.blueGreen.activeService }}
previewService: {{ .Values.rollout.strategy.blueGreen.previewService }}
{{- else }}
{{ fail "Because you use \"services\", so you should define .rollout.strategy.blueGreen.activeService and .rollout.strategy.blueGreen.previewService" }}
{{- end }}
{{- else if .Values.service }}
activeService: {{ .Values.rollout.strategy.blueGreen.activeService | default .Values.name }}
previewService: {{ .Values.rollout.strategy.blueGreen.previewService| default (printf "%s-preview" .Values.name) }}
{{- end }}
autoPromotionEnabled: {{ .Values.rollout.strategy.blueGreen.autoPromotionEnabled }}
{{- if .Values.rollout.strategy.blueGreen.extra }}
{{- toYaml .Values.rollout.strategy.blueGreen.extra |nindent 6 }}
{{- end }}
{{ else if .Values.rollout.strategy.canary }}
canary:
{{- if .Values.services }}
{{- if and .Values.rollout.strategy.canary.canaryService .Values.rollout.strategy.canary.stableService }}
canaryService: {{ .Values.rollout.strategy.canary.canaryService }}
stableService: {{ .Values.rollout.strategy.canary.stableService }}
{{- else }}
{{ fail "Because you use \"services\", so you should define .rollout.strategy.canary.canaryService and .rollout.strategy.canary.stableService" }}
{{- end }}
{{- else if .Values.service}}
canaryService: {{ .Values.rollout.strategy.canary.canaryService| default (printf "%s-canary" .Values.name) }}
stableService: {{ .Values.rollout.strategy.canary.stableService | default (printf "%s-stable" .Values.name) }}
{{- end }}
steps:
{{- toYaml .Values.rollout.strategy.canary.steps | nindent 6 }}
{{ if .Values.rollout.strategy.canary.trafficRouting }}
trafficRouting:
{{- toYaml .Values.rollout.strategy.canary.trafficRouting | nindent 8 }}
{{- end }}
{{ if .Values.rollout.strategy.canary.extra }}
{{- toYaml .Values.rollout.strategy.canary.extra | nindent 6 }}
{{- end }}
{{ end }}
---
{{- if .Values.service }}
{{- if .Values.rollout.strategy.canary }}
apiVersion: v1
kind: Service
metadata:
name: {{ .Values.rollout.strategy.canary.canaryService | default (printf "%s-canary" .Values.name) }}
spec:
{{- if hasKey .Values.service "type" }}
{{- if eq .Values.service.type "ExternalName" }}
{{ fail "not support this service type on rollout"}}
{{- else }}
ports:
{{- range .Values.service.ports }}
- name: {{ .name | default .port | quote }}
port: {{ .port }}
targetPort: {{ .target | default .port }}
protocol: {{ .protocol | default "TCP" }}
{{- end }}
type: {{ .Values.service.type }}
selector:
app: {{ .Values.name }}
{{- end }}
{{- else}}
ports:
{{- range .Values.service.ports }}
- name: {{ .name | default .port | quote }}
port: {{ .port }}
targetPort: {{ .target | default .port }}
protocol: {{ .protocol | default "TCP" }}
{{- end}}
type: ClusterIP
selector:
app: {{ .Values.name }}
{{- end }}
{{- end }}
---
apiVersion: v1
kind: Service
metadata:
{{- if .Values.rollout.strategy.blueGreen }}
name: {{ .Values.rollout.strategy.blueGreen.previewService | default (printf "%s-preview" .Values.name) }}
{{- else }}
name: {{ .Values.rollout.strategy.canary.stableService | default (printf "%s-stable" .Values.name) }}
{{- end }}
spec:
{{- if hasKey .Values.service "type" }}
{{- if eq .Values.service.type "ExternalName" }}
{{ fail "not support this service type on rollout"}}
{{- else }}
ports:
{{- range .Values.service.ports }}
- name: {{ .name | default .port | quote }}
port: {{ .port }}
targetPort: {{ .target | default .port }}
protocol: {{ .protocol | default "TCP" }}
{{- end }}
type: {{ .Values.service.type }}
selector:
app: {{ .Values.name }}
{{- end }}
{{- else}}
ports:
{{- range .Values.service.ports }}
- name: {{ .name | default .port | quote }}
port: {{ .port }}
targetPort: {{ .target | default .port }}
protocol: {{ .protocol | default "TCP" }}
{{- end}}
type: ClusterIP
selector:
app: {{ .Values.name }}
{{- end }}
{{- end }}
{{- end }}
---
8 changes: 8 additions & 0 deletions simple/templates/scale_object.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ metadata:
namespace: {{ .Release.Namespace }}
spec: {{ toYaml .Values.KEDA.ScaledObject.spec | nindent 2 }}
scaleTargetRef:
{{- if .Values.rollout }}
kind: Rollout
apiVersion: argoproj.io/v1alpha1
{{- end }}
name: {{ .Values.name }}
{{- end }}
{{- end }}
Expand All @@ -24,6 +28,10 @@ metadata:
namespace: {{ .Release.Namespace }}
spec:
scaleTargetRef:
{{- if .Values.rollout }}
kind: Rollout
apiVersion: argoproj.io/v1alpha1
{{- end }}
name: {{ .Values.name }}
minReplicaCount: {{ .Values.hpav2.minReplicas }}
maxReplicaCount: {{ .Values.hpav2.maxReplicas }}
Expand Down
69 changes: 68 additions & 1 deletion simple/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -252,4 +252,71 @@ externalSecrets: {}
# exmaple yaml please refer to example/example-keda.yaml
# KEDA:
# ScaledObject:
# spec: {}
# spec: {}

# rollout: {}
# https://argoproj.github.io/argo-rollouts/features/specification/
# rollout:
# annotations:
# notifications.argoproj.io/subscribe.on-rollout-completed.slack_webhook: ""
# revisionHistoryLimit: 10
# strategy:
# # blueGreen and canary CANNOT exist at the same time
# blueGreen:
# activeService: "app-name" # If uses service, this is an optional value; if uses services, then this is a required value
# previewService: "app-name-preview" # If uses service, this is an optional value; if uses services, then this is a required value
# autoPromotionEnabled: false # Required value. if you don't want auto promotion, type false.
# extra:
# prePromotionAnalysis:
# templates:
# - templateName: success-rate
# args:
# - name: service-name
# value: guestbook-svc.default.svc.cluster.local
# canary:
# canaryService: "app-name-canary" # If uses service, this is an optional value; if uses services, then this is a required value
# stableService: "app-name-stable"# If uses service, this is an optional value; if uses services, then this is a required value
# steps:
# - setWeight: 10
# - pause: { duration: 1h }
# - analysis:
# templates:
# - templateName: success-rate
# - setWeight: 100
# trafficRouting:
# alb: # If choose trafficRouting.alb, remember to modify ingress servicePort: use-annotation
# ingress: ingress
# servicePort: 443
# rootService: "app-name" # origin service name
# extra:
# analysis:
# templates:
# - templateName: success-rate
# args:
# - name: service-name
# value: guestbook-svc.default.svc.cluster.local

analyses: {}
# https://argoproj.github.io/argo-rollouts/features/analysis
# analyses:
# success-rate:
# spec:
# dryRun:
# - metricName: .*
# args:
# - name: service-name
# metrics:
# - name: success-rate
# interval: 5m
# successCondition: result[0] >= 0.95
# failureLimit: 3
# provider:
# prometheus:
# address: http://prometheus.example.com:9090
# query: |
# sum(irate(
# istio_requests_total{reporter="source",destination_service=~"{{args.service-name}}",response_code!~"5.*"}[5m]
# )) /
# sum(irate(
# istio_requests_total{reporter="source",destination_service=~"{{args.service-name}}"}[5m]
# ))

0 comments on commit f468d28

Please sign in to comment.