From 48f5ec99dabf5852834887878114956730ff9cf5 Mon Sep 17 00:00:00 2001 From: Michael Kalantar Date: Tue, 26 Sep 2023 08:51:41 -0400 Subject: [PATCH 1/3] add strategy none to routing-action Signed-off-by: Michael Kalantar --- CONTRIBUTING.md | 3 +-- abn/service_impl.go | 2 +- charts/routing-actions/Chart.yaml | 2 +- .../templates/_deployment.routemap-bg.tpl | 3 +++ .../templates/_deployment.routemap-none.tpl | 24 +++++++++++++++++++ .../templates/_kserve.routemap-none.tpl | 21 ++++++++++++++++ .../templates/_mm.routemap-none.tpl | 21 ++++++++++++++++ charts/routing-actions/templates/traffic.yaml | 20 ++++++++++++---- controllers/routemaps.go | 13 +++++++++- 9 files changed, 100 insertions(+), 9 deletions(-) create mode 100644 charts/routing-actions/templates/_deployment.routemap-none.tpl create mode 100644 charts/routing-actions/templates/_kserve.routemap-none.tpl create mode 100644 charts/routing-actions/templates/_mm.routemap-none.tpl diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 6a21d5856..e7158f88b 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -118,8 +118,7 @@ IMG=[Docker image name] Build and push Iter8 image to Docker ```shell -make build -docker build -f docker/Dockerfile -t $IMG bin +docker build -f docker/Dockerfile -t $IMG . docker push $IMG ``` diff --git a/abn/service_impl.go b/abn/service_impl.go index 2359e24c3..e87de6c20 100644 --- a/abn/service_impl.go +++ b/abn/service_impl.go @@ -138,7 +138,7 @@ func writeMetricInternal(application, user, metric, valueStr string) error { return fmt.Errorf("no metrics client") } err = MetricsClient.SetMetric( - s.GetNamespace()+"/"+s.GetName(), versionNumber, *v.GetSignature(), + application, versionNumber, *v.GetSignature(), metric, user, transaction, value) diff --git a/charts/routing-actions/Chart.yaml b/charts/routing-actions/Chart.yaml index 2aca0a231..ef27ecfb9 100644 --- a/charts/routing-actions/Chart.yaml +++ b/charts/routing-actions/Chart.yaml @@ -1,6 +1,6 @@ apiVersion: v2 name: routing-actions -version: 0.18.0 +version: 0.18.1 description: Iter8 routing actions type: application keywords: diff --git a/charts/routing-actions/templates/_deployment.routemap-bg.tpl b/charts/routing-actions/templates/_deployment.routemap-bg.tpl index 36b81134a..f9de310b7 100644 --- a/charts/routing-actions/templates/_deployment.routemap-bg.tpl +++ b/charts/routing-actions/templates/_deployment.routemap-bg.tpl @@ -17,6 +17,9 @@ data: - gvrShort: cm name: {{ $v.name }}-weight-config namespace: {{ $v.namespace }} + - gvrShort: svc + name: {{ $v.name }} + namespace: {{ $v.namespace }} - gvrShort: deploy name: {{ $v.name }} namespace: {{ $v.namespace }} diff --git a/charts/routing-actions/templates/_deployment.routemap-none.tpl b/charts/routing-actions/templates/_deployment.routemap-none.tpl new file mode 100644 index 000000000..01a1a475f --- /dev/null +++ b/charts/routing-actions/templates/_deployment.routemap-none.tpl @@ -0,0 +1,24 @@ +{{- define "deployment.routemap-none" }} +{{- $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: svc + name: {{ $v.name }} + namespace: {{ $v.namespace }} + - gvrShort: deploy + name: {{ $v.name }} + namespace: {{ $v.namespace }} + {{- end }} +immutable: true +{{- end }} diff --git a/charts/routing-actions/templates/_kserve.routemap-none.tpl b/charts/routing-actions/templates/_kserve.routemap-none.tpl new file mode 100644 index 000000000..2d64efa69 --- /dev/null +++ b/charts/routing-actions/templates/_kserve.routemap-none.tpl @@ -0,0 +1,21 @@ +{{- define "kserve.routemap-none" }} +{{- $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 }} +immutable: true +{{- end }} diff --git a/charts/routing-actions/templates/_mm.routemap-none.tpl b/charts/routing-actions/templates/_mm.routemap-none.tpl new file mode 100644 index 000000000..e9d233125 --- /dev/null +++ b/charts/routing-actions/templates/_mm.routemap-none.tpl @@ -0,0 +1,21 @@ +{{- define "mm.routemap-none" }} +{{- $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 }} +immutable: true +{{- end }} diff --git a/charts/routing-actions/templates/traffic.yaml b/charts/routing-actions/templates/traffic.yaml index 948e1b389..291ea5f42 100644 --- a/charts/routing-actions/templates/traffic.yaml +++ b/charts/routing-actions/templates/traffic.yaml @@ -11,7 +11,7 @@ {{- end }} {{- /* validate values for strategy */}} -{{- if not (has .Values.strategy (list "blue-green" "canary")) }} +{{- if not (has .Values.strategy (list "blue-green" "canary" "none")) }} {{- printf "Unknown strategy: '%s'" .Values.strategy | fail }} {{- end }} @@ -19,10 +19,13 @@ {{- if eq "initialize" .Values.action }} {{- /* gateway needed for kserve-modelmesh, deployment */}} + {{- if ne "none" .Values.strategy }} {{- if has .Values.appType (list "kserve-modelmesh" "deployment") }} {{ include "initial.gateway" . }} {{- end }} + {{- end }} --- + {{- if ne "none" .Values.strategy }} {{- if eq "deployment" .Values.appType }} {{ include "deployment.virtualservice" . }} {{- else if eq "kserve-modelmesh" .Values.appType }} @@ -34,7 +37,9 @@ {{ include "kserve.virtualservice-canary" . }} {{- end }} {{- end }} + {{- end }} --- + {{- if ne "none" .Values.strategy }} {{- if eq "deployment" .Values.appType }} {{ include "deployment.service" . }} {{- else if eq "kserve-modelmesh" .Values.appType }} @@ -42,21 +47,28 @@ {{- else }} {{- /* eq "kserve" .Values.appType */}} {{ include "kserve.service" . }} {{- end }} + {{- end }} --- {{- if eq "deployment" .Values.appType }} - {{- if eq "blue-green" .Values.strategy }} + {{- if eq "none" .Values.strategy }} + {{ include "deployment.routemap-none" . }} + {{- else if eq "blue-green" .Values.strategy }} {{ include "deployment.routemap-bluegreen" . }} {{- else }} {{- /* eq "canary" .Values.strategy */}} {{ include "deployment.routemap-canary" . }} {{- end }} {{- else if eq "kserve-modelmesh" .Values.appType }} - {{- if eq "blue-green" .Values.strategy }} + {{- if eq "none" .Values.strategy }} + {{ include "mm.routemap-none" . }} + {{- else if eq "blue-green" .Values.strategy }} {{ include "mm.routemap-bluegreen" . }} {{- else }} {{- /* eq "canary" .Values.strategy */}} {{ include "mm.routemap-canary" . }} {{- end }} {{- else }} {{- /* eq "kserve" .Values.appType */}} - {{- if eq "blue-green" .Values.strategy }} + {{- if eq "none" .Values.strategy }} + {{ include "kserve.routemap-none" . }} + {{- else if eq "blue-green" .Values.strategy }} {{ include "kserve.routemap-bluegreen" . }} {{- else }} {{- /* eq "canary" .Values.strategy */}} {{ include "kserve.routemap-canary" . }} diff --git a/controllers/routemaps.go b/controllers/routemaps.go index c00114cb0..4060782ca 100644 --- a/controllers/routemaps.go +++ b/controllers/routemaps.go @@ -1,6 +1,8 @@ package controllers import ( + "reflect" + "github.com/iter8-tools/iter8/base/log" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" @@ -53,8 +55,17 @@ func (s *routemaps) GetRoutemapFromNamespaceName(namespace string, name string) rmByName, ok := s.nsRoutemap[namespace] if ok { - return rmByName[name] + s := rmByName[name] + if s == nil || reflect.ValueOf(s).IsNil() { + // try concatenating "-routemap" to name + s = rmByName[name+"-routemap"] + if s == nil || reflect.ValueOf(s).IsNil() { + return nil + } + } + return s } + return nil } From 7c42911cf5a917e54f875775e69ca14cc9d3f018 Mon Sep 17 00:00:00 2001 From: Michael Kalantar Date: Tue, 26 Sep 2023 11:18:15 -0400 Subject: [PATCH 2/3] allow null strategy Signed-off-by: Michael Kalantar --- charts/routing-actions/templates/traffic.yaml | 46 +++++++++++-------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/charts/routing-actions/templates/traffic.yaml b/charts/routing-actions/templates/traffic.yaml index 291ea5f42..6080253e6 100644 --- a/charts/routing-actions/templates/traffic.yaml +++ b/charts/routing-actions/templates/traffic.yaml @@ -10,36 +10,42 @@ {{- printf "Unknown appType: '%s'" .Values.appType | fail }} {{- end }} +{{- /* set default strategy */}} +{{- $strategy := "none" }} +{{- if .Values.strategy }} +{{- $strategy := .Values.strategy }} +{{- end }} + {{- /* validate values for strategy */}} -{{- if not (has .Values.strategy (list "blue-green" "canary" "none")) }} - {{- printf "Unknown strategy: '%s'" .Values.strategy | fail }} +{{- if not (has $strategy (list "blue-green" "canary" "none")) }} + {{- printf "Unknown strategy: '%s'" $strategy | fail }} {{- end }} {{- /* handle initialize */}} {{- if eq "initialize" .Values.action }} {{- /* gateway needed for kserve-modelmesh, deployment */}} - {{- if ne "none" .Values.strategy }} + {{- if ne "none" $strategy }} {{- if has .Values.appType (list "kserve-modelmesh" "deployment") }} {{ include "initial.gateway" . }} {{- end }} {{- end }} --- - {{- if ne "none" .Values.strategy }} + {{- if ne "none" $strategy }} {{- if eq "deployment" .Values.appType }} {{ include "deployment.virtualservice" . }} {{- else if eq "kserve-modelmesh" .Values.appType }} {{ include "mm.virtualservice" . }} {{- else }} {{- /* eq "kserve" .Values.appType */}} - {{- if eq "blue-green" .Values.strategy }} + {{- if eq "blue-green" $strategy }} {{ include "kserve.virtualservice-bluegreen" . }} - {{- else }} {{- /* eq "canary" .Values.strategy */}} + {{- else }} {{- /* eq "canary" $strategy */}} {{ include "kserve.virtualservice-canary" . }} {{- end }} {{- end }} {{- end }} --- - {{- if ne "none" .Values.strategy }} + {{- if ne "none" $strategy }} {{- if eq "deployment" .Values.appType }} {{ include "deployment.service" . }} {{- else if eq "kserve-modelmesh" .Values.appType }} @@ -50,37 +56,37 @@ {{- end }} --- {{- if eq "deployment" .Values.appType }} - {{- if eq "none" .Values.strategy }} + {{- if eq "none" $strategy }} {{ include "deployment.routemap-none" . }} - {{- else if eq "blue-green" .Values.strategy }} + {{- else if eq "blue-green" $strategy }} {{ include "deployment.routemap-bluegreen" . }} - {{- else }} {{- /* eq "canary" .Values.strategy */}} + {{- else }} {{- /* eq "canary" $strategy */}} {{ include "deployment.routemap-canary" . }} {{- end }} {{- else if eq "kserve-modelmesh" .Values.appType }} - {{- if eq "none" .Values.strategy }} + {{- if eq "none" $strategy }} {{ include "mm.routemap-none" . }} - {{- else if eq "blue-green" .Values.strategy }} + {{- else if eq "blue-green" $strategy }} {{ include "mm.routemap-bluegreen" . }} - {{- else }} {{- /* eq "canary" .Values.strategy */}} + {{- else }} {{- /* eq "canary" $strategy */}} {{ include "mm.routemap-canary" . }} {{- end }} {{- else }} {{- /* eq "kserve" .Values.appType */}} - {{- if eq "none" .Values.strategy }} + {{- if eq "none" $strategy }} {{ include "kserve.routemap-none" . }} - {{- else if eq "blue-green" .Values.strategy }} + {{- else if eq "blue-green" $strategy }} {{ include "kserve.routemap-bluegreen" . }} - {{- else }} {{- /* eq "canary" .Values.strategy */}} + {{- else }} {{- /* eq "canary" $strategy */}} {{ include "kserve.routemap-canary" . }} {{- end }} {{- end }} --- - {{- if eq "blue-green" .Values.strategy }} + {{- if eq "blue-green" $strategy }} {{- range $i, $v := $versions }} {{ include "create.weight-config" (unset $v "weight") }} --- {{- end }} - {{- else if eq "mirror" .Values.strategy }} + {{- else if eq "mirror" $strategy }} {{- range $i, $v := (rest $versions) }} {{ include "create.weight-config" (unset $v "weight") }} --- @@ -88,12 +94,12 @@ {{- end }} {{- else if eq "modify-weights" .Values.action }} - {{- if eq "blue-green" .Values.strategy }} + {{- if eq "blue-green" $strategy }} {{- range $i, $v := .Values.appVersions }} {{ include "create.weight-config" $v }} --- {{- end }} - {{- else if eq "mirror" .Values.strategy }} + {{- else if eq "mirror" $strategy }} {{- range $i, $v := (rest $versions) }} {{ include "create.weight-config" (set $v "weight" $.Values.mirrorPercentage) }} --- From 73d653e310158b5197d3e9c1882be8f107fb39ab Mon Sep 17 00:00:00 2001 From: Michael Kalantar Date: Tue, 26 Sep 2023 13:56:08 -0400 Subject: [PATCH 3/3] fix comment Signed-off-by: Michael Kalantar --- .../routing-actions/templates/_deployment.routemap-bg.tpl | 4 ++-- charts/routing-actions/templates/traffic.yaml | 7 ++----- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/charts/routing-actions/templates/_deployment.routemap-bg.tpl b/charts/routing-actions/templates/_deployment.routemap-bg.tpl index f9de310b7..120357397 100644 --- a/charts/routing-actions/templates/_deployment.routemap-bg.tpl +++ b/charts/routing-actions/templates/_deployment.routemap-bg.tpl @@ -42,7 +42,7 @@ data: - {{ .Values.appName }}.{{ .Release.Namespace }}.svc.cluster.local http: - route: - # primary model + # primary version - destination: host: {{ (index $versions 0).name }}.{{ .Release.Namespace }}.svc.cluster.local {{- if .Values.appPort }} @@ -56,7 +56,7 @@ data: response: add: app-version: {{ (index $versions 0).name }} - # other models + # other versions {{- range $i, $v := (rest $versions) }} {{ `{{- if gt (index .Weights ` }}{{ print (add1 $i) }}{{ `) 0 }}`}} - destination: diff --git a/charts/routing-actions/templates/traffic.yaml b/charts/routing-actions/templates/traffic.yaml index 6080253e6..341ee21e0 100644 --- a/charts/routing-actions/templates/traffic.yaml +++ b/charts/routing-actions/templates/traffic.yaml @@ -10,11 +10,8 @@ {{- printf "Unknown appType: '%s'" .Values.appType | fail }} {{- end }} -{{- /* set default strategy */}} -{{- $strategy := "none" }} -{{- if .Values.strategy }} -{{- $strategy := .Values.strategy }} -{{- end }} +{{- /* set strategy using default value if needed */}} +{{- $strategy := (.Values.strategy | default "none" ) }} {{- /* validate values for strategy */}} {{- if not (has $strategy (list "blue-green" "canary" "none")) }}