Skip to content

Commit

Permalink
add strategy none to routing-action (#1645)
Browse files Browse the repository at this point in the history
* add strategy none to routing-action

Signed-off-by: Michael Kalantar <[email protected]>

* allow null strategy

Signed-off-by: Michael Kalantar <[email protected]>

* fix comment

Signed-off-by: Michael Kalantar <[email protected]>

---------

Signed-off-by: Michael Kalantar <[email protected]>
  • Loading branch information
kalantar authored Sep 26, 2023
1 parent 9c96a83 commit bf13530
Show file tree
Hide file tree
Showing 9 changed files with 115 additions and 21 deletions.
3 changes: 1 addition & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

Expand Down
2 changes: 1 addition & 1 deletion abn/service_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion charts/routing-actions/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
apiVersion: v2
name: routing-actions
version: 0.18.0
version: 0.18.1
description: Iter8 routing actions
type: application
keywords:
Expand Down
7 changes: 5 additions & 2 deletions charts/routing-actions/templates/_deployment.routemap-bg.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand All @@ -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 }}
Expand All @@ -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:
Expand Down
24 changes: 24 additions & 0 deletions charts/routing-actions/templates/_deployment.routemap-none.tpl
Original file line number Diff line number Diff line change
@@ -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 }}
21 changes: 21 additions & 0 deletions charts/routing-actions/templates/_kserve.routemap-none.tpl
Original file line number Diff line number Diff line change
@@ -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 }}
21 changes: 21 additions & 0 deletions charts/routing-actions/templates/_mm.routemap-none.tpl
Original file line number Diff line number Diff line change
@@ -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 }}
43 changes: 29 additions & 14 deletions charts/routing-actions/templates/traffic.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,78 +10,93 @@
{{- 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 }}
{{ include "mm.serviceentry" . }}
{{- 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") }}
---
{{- end }}
{{- 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) }}
---
Expand Down
13 changes: 12 additions & 1 deletion controllers/routemaps.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit bf13530

Please sign in to comment.