From f3f9a8e0216da3c295d33311f1e1907980d94fd4 Mon Sep 17 00:00:00 2001 From: Michael Kalantar Date: Wed, 13 Dec 2023 15:28:04 -0500 Subject: [PATCH] mirrored release for deployments (#1657) * mirrored release for deployments Signed-off-by: Michael Kalantar * bump chart version Signed-off-by: Michael Kalantar --------- Signed-off-by: Michael Kalantar --- charts/release/Chart.yaml | 2 +- .../_deployment-istio.mirror.routemap.tpl | 74 +++++++++++++++++++ .../templates/_deployment-istio.mirror.tpl | 15 ++++ .../release/templates/_deployment-istio.tpl | 2 + 4 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 charts/release/templates/_deployment-istio.mirror.routemap.tpl create mode 100644 charts/release/templates/_deployment-istio.mirror.tpl diff --git a/charts/release/Chart.yaml b/charts/release/Chart.yaml index 1265e4e69..dc8c1246c 100644 --- a/charts/release/Chart.yaml +++ b/charts/release/Chart.yaml @@ -1,6 +1,6 @@ apiVersion: v2 name: release -version: 0.18.4 +version: 0.18.5 description: Iter8 supported application release type: application keywords: diff --git a/charts/release/templates/_deployment-istio.mirror.routemap.tpl b/charts/release/templates/_deployment-istio.mirror.routemap.tpl new file mode 100644 index 000000000..75273c9ea --- /dev/null +++ b/charts/release/templates/_deployment-istio.mirror.routemap.tpl @@ -0,0 +1,74 @@ +{{- define "env.deployment-istio.mirror.routemap" }} + +{{- $APP_NAME := (include "application.name" .) }} +{{- $APP_NAMESPACE := (include "application.namespace" .) }} +{{- $versions := include "normalize.versions.deployment" . | mustFromJson }} + +apiVersion: v1 +kind: ConfigMap +{{- template "routemap.metadata" . }} +data: + strSpec: | + versions: + {{- range $i, $v := $versions }} + - resources: + - gvrShort: svc + name: {{ template "svc.name" $v }} + namespace: {{ template "svc.namespace" $v }} + - gvrShort: deploy + name: {{ template "deploy.name" $v }} + namespace: {{ template "deploy.namespace" $v }} + - gvrShort: cm + name: {{ $v.VERSION_NAME }}-weight-config + namespace: {{ $v.VERSION_NAMESPACE }} + weight: {{ $v.weight }} + {{- end }} {{- /* range $i, $v := $versions */}} + routingTemplates: + {{ .Values.application.strategy }}: + gvrShort: vs + template: | + apiVersion: networking.istio.io/v1beta1 + kind: VirtualService + metadata: + name: {{ $APP_NAME }} + namespace: {{ $APP_NAMESPACE }} + spec: + gateways: + {{- if .Values.gateway }} + - {{ .Values.gateway }} + {{- end }} + - mesh + hosts: + - {{ $APP_NAME }}.{{ $APP_NAMESPACE }} + - {{ $APP_NAME }}.{{ $APP_NAMESPACE }}.svc + - {{ $APP_NAME }}.{{ $APP_NAMESPACE }}.svc.cluster.local + http: + - name: {{ $APP_NAME }} + route: + # primary version + {{- $v := (index $versions 0) }} + - destination: + host: {{ template "svc.name" $v }}.{{ $APP_NAMESPACE }}.svc.cluster.local + port: + number: {{ $v.port }} + {{- if gt (len $versions) 1 }} + {{ `{{- if gt (index .Weights 1) 0 }}` }} + weight: {{ `{{ index .Weights 0 }}` }} + {{ `{{- end }}` }} + {{- end }} + headers: + response: + add: + app-version: {{ template "svc.name" $v }} + # other versions + {{- range $i, $v := (rest $versions) }} + {{ `{{- if gt (index .Weights ` }}{{ print (add1 $i) }}{{ `) 0 }}` }} + mirror: + host: {{ template "svc.name" $v }}.{{ $APP_NAMESPACE }}.svc.cluster.local + port: + number: {{ $v.port }} + mirrorPercentage: + value: {{ `{{ index .Weights ` }}{{ print (add1 $i) }}{{ ` }}` }} + {{ `{{- end }}` }} + {{- end }} +{{- end }} {{- /* define "env.deployment-istio.mirror.routemap" */}} diff --git a/charts/release/templates/_deployment-istio.mirror.tpl b/charts/release/templates/_deployment-istio.mirror.tpl new file mode 100644 index 000000000..c475e0760 --- /dev/null +++ b/charts/release/templates/_deployment-istio.mirror.tpl @@ -0,0 +1,15 @@ +{{- define "env.deployment-istio.mirror" }} + +{{- /* prepare versions for simpler processing */}} +{{- $versions := include "normalize.versions.deployment" . | mustFromJson }} + +{{- /* weight-config ConfigMaps except for primary */}} +{{- range $i, $v := (rest $versions) }} + {{ include "configmap.weight-config" $v }} +--- +{{- end }} {{- /* range $i, $v := $versions */}} + +{{- /* routemap */}} +{{ include "env.deployment-istio.mirror.routemap" . }} + +{{- end }} {{- /* define "env.deployment-istio.mirror" */}} \ No newline at end of file diff --git a/charts/release/templates/_deployment-istio.tpl b/charts/release/templates/_deployment-istio.tpl index 0bc1a6d39..1a4d4b69d 100644 --- a/charts/release/templates/_deployment-istio.tpl +++ b/charts/release/templates/_deployment-istio.tpl @@ -25,6 +25,8 @@ {{ include "env.deployment-istio.blue-green" . }} {{- else if eq "canary" .Values.application.strategy }} {{ include "env.deployment-istio.canary" . }} +{{- else if eq "mirror" .Values.application.strategy }} +{{ include "env.deployment-istio.mirror" . }} {{- end }} {{- /* if eq ... .Values.application.strategy */}} {{- end }} {{- /* define "env.deployment-istio" */}} \ No newline at end of file