From bf13530586a447220caccf71fae506350b47fd75 Mon Sep 17 00:00:00 2001 From: Michael Kalantar Date: Tue, 26 Sep 2023 16:55:19 -0400 Subject: [PATCH] add strategy none to routing-action (#1645) * add strategy none to routing-action Signed-off-by: Michael Kalantar * allow null strategy Signed-off-by: Michael Kalantar * fix comment Signed-off-by: Michael Kalantar --------- Signed-off-by: Michael Kalantar --- CONTRIBUTING.md | 3 +- abn/service_impl.go | 2 +- charts/routing-actions/Chart.yaml | 2 +- .../templates/_deployment.routemap-bg.tpl | 7 ++- .../templates/_deployment.routemap-none.tpl | 24 +++++++++++ .../templates/_kserve.routemap-none.tpl | 21 +++++++++ .../templates/_mm.routemap-none.tpl | 21 +++++++++ charts/routing-actions/templates/traffic.yaml | 43 +++++++++++++------ controllers/routemaps.go | 13 +++++- 9 files changed, 115 insertions(+), 21 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..120357397 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 }} @@ -39,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 }} @@ -53,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/_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..341ee21e0 100644 --- a/charts/routing-actions/templates/traffic.yaml +++ b/charts/routing-actions/templates/traffic.yaml @@ -10,31 +10,39 @@ {{- printf "Unknown appType: '%s'" .Values.appType | fail }} {{- end }} +{{- /* set strategy using default value if needed */}} +{{- $strategy := (.Values.strategy | default "none" ) }} + {{- /* validate values for strategy */}} -{{- if not (has .Values.strategy (list "blue-green" "canary")) }} - {{- 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" $strategy }} {{- if has .Values.appType (list "kserve-modelmesh" "deployment") }} {{ include "initial.gateway" . }} {{- end }} + {{- end }} --- + {{- 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" $strategy }} {{- if eq "deployment" .Values.appType }} {{ include "deployment.service" . }} {{- else if eq "kserve-modelmesh" .Values.appType }} @@ -42,33 +50,40 @@ {{- else }} {{- /* eq "kserve" .Values.appType */}} {{ include "kserve.service" . }} {{- end }} + {{- end }} --- {{- if eq "deployment" .Values.appType }} - {{- if eq "blue-green" .Values.strategy }} + {{- if eq "none" $strategy }} + {{ include "deployment.routemap-none" . }} + {{- 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 "blue-green" .Values.strategy }} + {{- if eq "none" $strategy }} + {{ include "mm.routemap-none" . }} + {{- 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 "blue-green" .Values.strategy }} + {{- if eq "none" $strategy }} + {{ include "kserve.routemap-none" . }} + {{- 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") }} --- @@ -76,12 +91,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) }} --- 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 }