Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update traffic-templates chart for kserve #1560

Merged
merged 5 commits into from
Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions charts/routing-actions/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*.orig
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/

# generated files need to be ignored
experiment.yaml
21 changes: 21 additions & 0 deletions charts/routing-actions/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
apiVersion: v2
name: routing-actions
version: 0.1.0
description: Iter8 routing actions
type: application
keywords:
- Iter8
- traffic
- blue-green
- canary
- mirroring
home: https://iter8.tools
sources:
- https://github.com/iter8-tools/iter8
maintainers:
- name: Michael Kalantar
email: [email protected]
- name: Iter8
email: [email protected]
icon: https://github.com/iter8-tools/iter8/raw/master/mkdocs/docs/images/favicon.png
appVersion: v0.15
12 changes: 12 additions & 0 deletions charts/routing-actions/templates/_configmap.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{{- define "create.weight-config" }}
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ .name }}-weight-config
labels:
iter8.tools/watch: "true"
{{- if .weight }}
annotations:
iter8.tools/weight: "{{ .weight }}"
{{- end }}
{{- end }}
16 changes: 16 additions & 0 deletions charts/routing-actions/templates/_gateway.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{{- define "initial.gateway" }}
apiVersion: networking.istio.io/v1beta1
kind: Gateway
metadata:
name: {{ .Values.externalGateway }}
spec:
selector:
istio: ingressgateway
servers:
- port:
number: 80
name: http
protocol: HTTP
hosts:
- "*"
{{- end }}
33 changes: 33 additions & 0 deletions charts/routing-actions/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{{- define "iter8-traffic-template.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{- define "iter8-traffic-template.labels" -}}
labels:
helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
{{- end -}}

{{- define "resolve.appVersions" }}
{{- /* produce a list of versions with all fields filled in with user specified values or defaults */}}
{{- /* default values for fields depend on strategy */}}
{{- $defaultNamespace := .Release.Namespace }}
{{- $defaultWeight := ternary "100" "50" (eq .Values.strategy "mirror") }}
{{- $defaultMatch := ternary (list (dict "headers" (dict "traffic" (dict "exact" "test")))) (dict) (eq .Values.strategy "canary") }}

{{- $mV := list }}
{{- if .Values.appVersions }}
{{- /* appVersions were listed so just fill in any missing fields */}}
{{- range $i, $ver := .Values.appVersions }}
{{- $v := merge $ver }}
{{- $v = set $v "name" (default (printf "%s-%d" $.Values.appName $i) $ver.name) }}
{{- $v = set $v "namespace" (default $defaultNamespace $ver.namespace) }}
{{- $v = set $v "weight" (default $defaultWeight $ver.weight | toString) }}
{{- $v = set $v "match" (default $defaultMatch $ver.match) }}
{{- $mV = append $mV $v }}
{{- end }}
{{- else }} {{- /* appVersions NOT set, so use defaults for all fields */}}
{{- $mV = append $mV (dict "name" (printf "%s-0" .Values.appName) "namespace" $defaultNamespace "weight" $defaultWeight "match" $defaultMatch ) }}
{{- $mV = append $mV (dict "name" (printf "%s-1" .Values.appName ) "namespace" $defaultNamespace "weight" $defaultWeight "match" $defaultMatch ) }}
{{- end }}
{{- mustToJson $mV }}
{{- end }}
112 changes: 112 additions & 0 deletions charts/routing-actions/templates/_routemap-bluegreen-kserve.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
{{- define "routemap-bluegreen-kserve" }}
{{- $versions := include "resolve.appVersions" . | mustFromJson }}
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ .Values.appName }}-routemap
labels:
app.kubernetes.io/managed-by: iter8
iter8.tools/kind: routemap
iter8.tools/version: {{ .Values.iter8Version }}
data:
strSpec: |
versions:
{{- range $i, $v := $versions }}
- weight: {{ $v.weight }}
resources:
- gvrShort: cm
name: {{ $v.name }}-weight-config
namespace: {{ $v.namespace }}
- gvrShort: isvc
name: {{ $v.name }}
namespace: {{ $v.namespace }}
{{- end }}
routingTemplates:
{{ .Values.strategy }}:
gvrShort: vs
template: |
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
name: {{ .Values.appName }}
spec:
gateways:
- knative-serving/knative-ingress-gateway
- knative-serving/knative-local-gateway
- mesh
hosts:
- {{ .Values.appName }}.{{ .Release.Namespace }}
- {{ .Values.appName }}.{{ .Release.Namespace }}.svc
- {{ .Values.appName }}.{{ .Release.Namespace }}.svc.cluster.local
http:
- name: {{ (index $versions 0).name }}
match:
- headers:
branch:
exact: {{ (index $versions 0).name }}
rewrite:
uri: /v2/models/{{ (index $versions 0).name }}/infer
route:
# primary model
- destination:
host: knative-local-gateway.istio-system.svc.cluster.local
headers:
request:
set:
Host: {{ (index $versions 0).name }}-predictor-default.{{ .Release.Namespace }}.svc.cluster.local
remove:
- branch
response:
add:
app-version: {{ (index $versions 0).name }}
# other models
{{- range $i, $v := (rest $versions) }}
{{ `{{- if gt (index .Weights ` }}{{ print (add1 $i) }}{{ `) 0 }}`}}
- name: {{ (index $versions (add1 $i)).name }}
match:
- headers:
branch:
exact: {{ (index $versions (add1 $i)).name }}
rewrite:
uri: /v2/models/{{ (index $versions (add1 $i)).name }}/infer
route:
# primary model
- destination:
host: knative-local-gateway.istio-system.svc.cluster.local
headers:
request:
set:
Host: {{ (index $versions (add1 $i)).name }}-predictor-default.{{ $.Release.Namespace }}.svc.cluster.local
remove:
- branch
response:
add:
app-version: {{ (index $versions (add1 $i)).name }}
{{ `{{- end }}`}}
{{- end }}
- name: split
route:
- destination:
host: knative-local-gateway.istio-system.svc.cluster.local
{{ `{{- if gt (index .Weights 1) 0 }}` }}
weight: {{ `{{ index .Weights 0 }}` }}
{{ `{{- end }}`}}
headers:
request:
set:
branch: {{ (index $versions 0).name }}
host: {{ .Values.appName }}.{{ .Release.Namespace }}
{{- range $i, $v := (rest $versions) }}
{{ `{{- if gt (index .Weights ` }}{{ print (add1 $i) }}{{ `) 0 }}`}}
- destination:
host: knative-local-gateway.istio-system.svc.cluster.local
weight: {{ `{{ index .Weights `}}{{ print (add1 $i) }}{{` }}`}}
headers:
request:
set:
branch: {{ (index $versions (add1 $i)).name }}
host: {{ $.Values.appName }}.{{ $.Release.Namespace }}
{{ `{{- end }}`}}
{{- end }}
immutable: true
{{- end }}
75 changes: 75 additions & 0 deletions charts/routing-actions/templates/_routemap-bluegreen.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{{- define "routemap-bluegreen" }}
{{- $versions := include "resolve.appVersions" . | mustFromJson }}
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ .Values.appName }}-routemap
labels:
app.kubernetes.io/managed-by: iter8
iter8.tools/kind: routemap
iter8.tools/version: {{ .Values.iter8Version }}
data:
strSpec: |
versions:
{{- range $i, $v := $versions }}
- weight: {{ $v.weight }}
resources:
- gvrShort: cm
name: {{ $v.name }}-weight-config
namespace: {{ $v.namespace }}
- gvrShort: isvc
name: {{ $v.name }}
namespace: {{ $v.namespace }}
{{- end }}
routingTemplates:
{{ .Values.strategy }}:
gvrShort: vs
template: |
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
name: {{ .Values.appName }}
spec:
gateways:
- {{ .Values.externalGateway }}
- mesh
hosts:
- {{ .Values.appName }}.{{ .Release.Namespace }}
- {{ .Values.appName }}.{{ .Release.Namespace }}.svc
- {{ .Values.appName }}.{{ .Release.Namespace }}.svc.cluster.local
http:
- route:
# primary model
- destination:
host: {{ .Values.modelmeshServingService }}.{{ .Release.Namespace }}.svc.cluster.local
port:
number: {{ $.Values.modelmeshServingPort }}
{{ `{{- if gt (index .Weights 1) 0 }}` }}
weight: {{ `{{ index .Weights 0 }}` }}
{{ `{{- end }}`}}
headers:
request:
set:
mm-vmodel-id: "{{ (index $versions 0).name }}"
response:
add:
app-version: "{{ (index $versions 0).name }}"
# other models
{{- range $i, $v := (rest $versions) }}
{{ `{{- if gt (index .Weights ` }}{{ print (add1 $i) }}{{ `) 0 }}`}}
- destination:
host: {{ $.Values.modelmeshServingService }}.{{ $.Release.Namespace }}.svc.cluster.local
port:
number: {{ $.Values.modelmeshServingPort }}
weight: {{ `{{ index .Weights `}}{{ print (add1 $i) }}{{` }}`}}
headers:
request:
set:
mm-vmodel-id: "{{ (index $versions (add1 $i)).name }}"
resppnse:
add:
app-version: "{{ (index $versions (add1 $i)).name }}"
{{ `{{- end }}`}}
{{- end }}
immutable: true
{{- end }}
84 changes: 84 additions & 0 deletions charts/routing-actions/templates/_routemap-canary-kserve.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
{{- define "routemap-canary-kserve" }}
{{- $versions := include "resolve.appVersions" . | mustFromJson }}
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ .Values.appName }}-routemap
labels:
app.kubernetes.io/managed-by: iter8
iter8.tools/kind: routemap
iter8.tools/version: {{ .Values.iter8Version }}
data:
strSpec: |
versions:
{{- range $i, $v := $versions }}
- resources:
- gvrShort: isvc
name: {{ default (printf "%s-%d" $.Values.appName $i) $v.name }}
namespace: {{ default "modelmesh-serving" $v.namespace }}
{{- end }}
routingTemplates:
{{ .Values.strategy }}:
gvrShort: vs
template: |
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
name: {{ .Values.appName }}
spec:
gateways:
- knative-serving/knative-ingress-gateway
- knative-serving/knative-local-gateway
- mesh
hosts:
- {{ .Values.appName }}.{{ .Release.Namespace }}
- {{ .Values.appName }}.{{ .Release.Namespace }}.svc
- {{ .Values.appName }}.{{ .Release.Namespace }}.svc.cluster.local
http:
{{- /* For candidate versions, ensure mm-model header is required in all matches */}}
{{- range $i, $v := (rest $versions) }}
{{- /* continue only if candidate is ready (weight > 0) */}}
{{ `{{- if gt (index .Weights ` }}{{ print (add1 $i) }}{{ `) 0 }}`}}
- name: {{ (index $versions (add1 $i)).name }}
match:
{{- /* A match may have several ORd clauses */}}
{{- range $j, $m := $v.match }}
{{- /* include any other header requirements */}}
{{- if (hasKey $m "headers") }}
- headers:
{{ toYaml (pick $m "headers").headers | indent 18 }}
{{- end }}
{{- /* include any other (non-header) requirements */}}
{{- if gt (omit $m "headers" | keys | len) 0 }}
{{ toYaml (omit $m "headers") | indent 16 }}
{{- end }}
{{- end }}
rewrite:
uri: /v2/models/{{ (index $versions (add1 $i)).name }}/infer
route:
- destination:
host: knative-local-gateway.istio-system.svc.cluster.local
headers:
request:
set:
Host: {{ (index $versions (add1 $i)).name }}-predictor-default.{{ $.Release.Namespace }}.svc.cluster.local
response:
add:
app-version: "{{ (index $versions (add1 $i)).name }}"
{{ `{{- end }}`}}
{{- end }}
- name: {{ (index $versions 0).name }}
rewrite:
uri: /v2/models/{{ (index $versions 0).name }}/infer
route:
- destination:
host: knative-local-gateway.istio-system.svc.cluster.local
headers:
request:
set:
Host: {{ (index $versions 0).name }}-predictor-default.{{ .Release.Namespace }}.svc.cluster.local
response:
add:
app-version: "{{ (index $versions 0).name }}"
immutable: true
{{- end }}
Loading
Loading