|
| 1 | +{{- define "env.deployment-istio.mirror.routemap" }} |
| 2 | + |
| 3 | +{{- $APP_NAME := (include "application.name" .) }} |
| 4 | +{{- $APP_NAMESPACE := (include "application.namespace" .) }} |
| 5 | +{{- $versions := include "normalize.versions.deployment" . | mustFromJson }} |
| 6 | + |
| 7 | +apiVersion: v1 |
| 8 | +kind: ConfigMap |
| 9 | +{{- template "routemap.metadata" . }} |
| 10 | +data: |
| 11 | + strSpec: | |
| 12 | + versions: |
| 13 | + {{- range $i, $v := $versions }} |
| 14 | + - resources: |
| 15 | + - gvrShort: svc |
| 16 | + name: {{ template "svc.name" $v }} |
| 17 | + namespace: {{ template "svc.namespace" $v }} |
| 18 | + - gvrShort: deploy |
| 19 | + name: {{ template "deploy.name" $v }} |
| 20 | + namespace: {{ template "deploy.namespace" $v }} |
| 21 | + - gvrShort: cm |
| 22 | + name: {{ $v.VERSION_NAME }}-weight-config |
| 23 | + namespace: {{ $v.VERSION_NAMESPACE }} |
| 24 | + weight: {{ $v.weight }} |
| 25 | + {{- end }} {{- /* range $i, $v := $versions */}} |
| 26 | + routingTemplates: |
| 27 | + {{ .Values.application.strategy }}: |
| 28 | + gvrShort: vs |
| 29 | + template: | |
| 30 | + apiVersion: networking.istio.io/v1beta1 |
| 31 | + kind: VirtualService |
| 32 | + metadata: |
| 33 | + name: {{ $APP_NAME }} |
| 34 | + namespace: {{ $APP_NAMESPACE }} |
| 35 | + spec: |
| 36 | + gateways: |
| 37 | + {{- if .Values.gateway }} |
| 38 | + - {{ .Values.gateway }} |
| 39 | + {{- end }} |
| 40 | + - mesh |
| 41 | + hosts: |
| 42 | + - {{ $APP_NAME }}.{{ $APP_NAMESPACE }} |
| 43 | + - {{ $APP_NAME }}.{{ $APP_NAMESPACE }}.svc |
| 44 | + - {{ $APP_NAME }}.{{ $APP_NAMESPACE }}.svc.cluster.local |
| 45 | + http: |
| 46 | + - name: {{ $APP_NAME }} |
| 47 | + route: |
| 48 | + # primary version |
| 49 | + {{- $v := (index $versions 0) }} |
| 50 | + - destination: |
| 51 | + host: {{ template "svc.name" $v }}.{{ $APP_NAMESPACE }}.svc.cluster.local |
| 52 | + port: |
| 53 | + number: {{ $v.port }} |
| 54 | + {{- if gt (len $versions) 1 }} |
| 55 | + {{ `{{- if gt (index .Weights 1) 0 }}` }} |
| 56 | + weight: {{ `{{ index .Weights 0 }}` }} |
| 57 | + {{ `{{- end }}` }} |
| 58 | + {{- end }} |
| 59 | + headers: |
| 60 | + response: |
| 61 | + add: |
| 62 | + app-version: {{ template "svc.name" $v }} |
| 63 | + # other versions |
| 64 | + {{- range $i, $v := (rest $versions) }} |
| 65 | + {{ `{{- if gt (index .Weights ` }}{{ print (add1 $i) }}{{ `) 0 }}` }} |
| 66 | + mirror: |
| 67 | + host: {{ template "svc.name" $v }}.{{ $APP_NAMESPACE }}.svc.cluster.local |
| 68 | + port: |
| 69 | + number: {{ $v.port }} |
| 70 | + mirrorPercentage: |
| 71 | + value: {{ `{{ index .Weights ` }}{{ print (add1 $i) }}{{ ` }}` }} |
| 72 | + {{ `{{- end }}` }} |
| 73 | + {{- end }} |
| 74 | +{{- end }} {{- /* define "env.deployment-istio.mirror.routemap" */}} |
0 commit comments