From 133219325cbc6f0566ad7d9260e8aec45e530f41 Mon Sep 17 00:00:00 2001 From: Michael Kalantar Date: Mon, 9 Oct 2023 15:23:01 -0400 Subject: [PATCH] kserve canary routemap template Signed-off-by: Michael Kalantar --- .../templates/_kserve.canary.routemap.tpl | 87 +++++++++++++++++++ .../templates/_kserve.version.isvc.tpl | 1 - .../templates/_mm-istio.canary.routemap.tpl | 5 +- 3 files changed, 89 insertions(+), 4 deletions(-) create mode 100644 charts/release/templates/_kserve.canary.routemap.tpl diff --git a/charts/release/templates/_kserve.canary.routemap.tpl b/charts/release/templates/_kserve.canary.routemap.tpl new file mode 100644 index 000000000..206369732 --- /dev/null +++ b/charts/release/templates/_kserve.canary.routemap.tpl @@ -0,0 +1,87 @@ +{{- define "env.kserve.canary.routemap" }} + +{{- $APP_NAME := (include "application.name" .) }} +{{- $APP_NAMESPACE := (include "application.namespace" .) }} +{{- $versions := include "normalize.versions" . | mustFromJson }} + +apiVersion: v1 +kind: ConfigMap +{{ template "routemap.metadata" . }} +data: + strSpec: | + versions: + {{- range $i, $v := $versions }} + - resources: + - gvrShort: isvc + name: {{ $v.VERSION_NAME }} + namespace: {{ $v.VERSION_NAMESPACE }} + weight: {{ $v.weight }} + {{- end }} {{- /* range $i, $v := .Values.application.versions */}} + routingTemplates: + {{ .Values.application.strategy }}: + gvrShort: vs + template: | + apiVersion: networking.istio.io/v1beta1 + kind: VirtualService + metadata: + name: {{ $APP_NAME }} + namespace: {{ $APP_NAMESPACE }} + spec: + gateways: + - knative-serving/knative-ingress-gateway + - knative-serving/knative-local-gateway + - mesh + hosts: + - {{ $APP_NAME }}.{{ $APP_NAMESPACE }} + - {{ $APP_NAME }}.{{ $APP_NAMESPACE }}.svc + - {{ $APP_NAME }}.{{ $APP_NAMESPACE }}.svc.cluster.local + http: + # non-primary versions + {{- /* 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)).VERSION_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)).VERSION_NAME }}/infer + route: + - destination: + host: knative-local-gateway.istio-system.svc.cluster.local + headers: + request: + set: + Host: {{ (index $versions (add1 $i)).VERSION_NAME }}-{{ template "kserve.host" $ }} + response: + add: + app-version: "{{ (index $versions (add1 $i)).VERSION_NAME }}" + {{ `{{- end }}`}} + {{- end }} + # primary version (default) + - name: {{ (index $versions 0).VERSION_NAME }} + rewrite: + uri: /v2/models/{{ (index $versions 0).VERSION_NAME }}/infer + route: + - destination: + host: knative-local-gateway.istio-system.svc.cluster.local + headers: + request: + set: + Host: {{ (index $versions 0).VERSION_NAME }}-{{ template "kserve.host" $ }} + response: + add: + app-version: "{{ (index $versions 0).VERSION_NAME }}" + +{{- end }} {{- /* define "env.kserve.canary.routemap" */}} diff --git a/charts/release/templates/_kserve.version.isvc.tpl b/charts/release/templates/_kserve.version.isvc.tpl index a9df5fb8b..3232e89bf 100644 --- a/charts/release/templates/_kserve.version.isvc.tpl +++ b/charts/release/templates/_kserve.version.isvc.tpl @@ -3,7 +3,6 @@ {{- /* compute basic metadata */}} {{- $metadata := include "application.version.metadata" . | mustFromJson }} {{- /* add annotation serving.kserve.io/deploymentMode */}} -{{- $metadata := set $metadata "annotations" (merge $metadata.annotations (dict "serving.kserve.io/deploymentMode" "ModelMesh")) }} {{- /* define InferenceServcie */}} apiVersion: serving.kserve.io/v1beta1 diff --git a/charts/release/templates/_mm-istio.canary.routemap.tpl b/charts/release/templates/_mm-istio.canary.routemap.tpl index 4ab2a0263..4f805f5b5 100644 --- a/charts/release/templates/_mm-istio.canary.routemap.tpl +++ b/charts/release/templates/_mm-istio.canary.routemap.tpl @@ -34,8 +34,7 @@ data: - {{ $APP_NAME }}.{{ $APP_NAMESPACE }}.svc - {{ $APP_NAME }}.{{ $APP_NAMESPACE }}.svc.cluster.local http: - # non-primary model versions - + # non-primary versions {{- /* For candidate versions, ensure mm-model header is required in all matches */}} {{- range $i, $v := (rest $versions) }} {{- /* continue only if candidate is ready (ie, weight > 0) */}} @@ -67,7 +66,7 @@ data: app-version: {{ (index $versions (add1 $i)).VERSION_NAME }} {{ `{{- end }}`}} {{- end }} - # primary model version (default) + # primary version (default) - name: {{ (index $versions 0).VERSION_NAME }} route: - destination: