Skip to content

Commit

Permalink
helper for metadata
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Kalantar <kalantar@us.ibm.com>
  • Loading branch information
kalantar committed Oct 6, 2023
1 parent a82101e commit 36aed89
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 67 deletions.
14 changes: 2 additions & 12 deletions charts/release/templates/_deployment-istio.version.deployment.tpl
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
{{- define "env.deployment-istio.version.deployment" }}

{{- /* compute labels */}}
{{- $labels := include "application.version.labels" . | mustFromJson }}

{{- /* compute annotations */}}
{{- $annotations := include "application.version.annotations" . | mustFromJson }}

{{- /* compose into metadata */}}
{{- $metadata := (dict) }}
{{- $metadata := set $metadata "name" .VERSION_NAME }}
{{- $metadata := set $metadata "namespace" .VERSION_NAMESPACE }}
{{- $metadata := set $metadata "labels" $labels }}
{{- $metadata := set $metadata "annotations" $annotations }}
{{- /* compute basic metadata */}}
{{- $metadata := include "application.version.metadata" . | mustFromJson }}

apiVersion: apps/v1
kind: Deployment
Expand Down
14 changes: 2 additions & 12 deletions charts/release/templates/_deployment-istio.version.service.tpl
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
{{- define "env.deployment-istio.version.service" }}

{{- /* compute labels */}}
{{- $labels := include "application.version.labels" . | mustFromJson }}

{{- /* compute annotations */}}
{{- $annotations := include "application.version.annotations" . | mustFromJson }}

{{- /* compose into metadata */}}
{{- $metadata := (dict) }}
{{- $metadata := set $metadata "name" .VERSION_NAME }}
{{- $metadata := set $metadata "namespace" .VERSION_NAMESPACE }}
{{- $metadata := set $metadata "labels" $labels }}
{{- $metadata := set $metadata "annotations" $annotations }}
{{- /* compute basic metadata */}}
{{- $metadata := include "application.version.metadata" . | mustFromJson }}

apiVersion: v1
kind: Service
Expand Down
33 changes: 16 additions & 17 deletions charts/release/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
{{- define "release.labels" -}}
labels:
helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
{{- end -}}

{{- define "application.name" -}}
{{- if (and .Values.application .Values.application.metadata .Values.application.metadata.name) -}}
{{ .Values.application.metadata.name -}}
Expand Down Expand Up @@ -43,6 +38,19 @@
{{- mustToJson $annotations }}
{{- end -}} {{- /* define "application.version.annotations" */}}

{{- define "application.version.metadata" -}}
{{- $labels := (include "application.version.labels" . | mustFromJson) }}
{{- $annotations := (include "application.version.annotations" . | mustFromJson) }}
{{- /* compose into metadata */}}
{{- $metadata := (dict) }}
{{- $metadata := set $metadata "name" .VERSION_NAME }}
{{- $metadata := set $metadata "namespace" .VERSION_NAMESPACE }}
{{- $metadata := set $metadata "labels" $labels }}
{{- $metadata := set $metadata "annotations" $annotations }}
{{- /* return as JSON */}}
{{- mustToJson $metadata }}
{{- end -}} {{- /* define "application.version.metadata" */}}

{{- define "routemap.metadata" }}
metadata:
name: {{ template "application.name" . }}-routemap
Expand All @@ -60,14 +68,8 @@ metadata:
{{- $metadata := merge $metadata .Values.application.metadata }}
{{- end }} {{- /* if .Values.application.metadata */}}

{{- $APP_NAME := .Release.Name }}
{{- if $metadata.name }}
{{- $APP_NAME := $metadata.name }}
{{- end }}
{{- $APP_NAMESPACE := .Release.Namespace }}
{{- if $metadata.namespace }}
{{- $APP_NAMESPACE := $metadata.namespace }}
{{- end }}
{{- $APP_NAME := (include "application.name" .) }}
{{- $APP_NAMESPACE := (include "application.namespace" .) }}

{{- $defaultMatch := ternary (list (dict "headers" (dict "traffic" (dict "exact" "test")))) (dict) (eq .Values.application.strategy "canary") }}

Expand Down Expand Up @@ -101,10 +103,7 @@ metadata:
{{- end }} {{- /* define "normalize.versions" */}}

{{- define "kserve.host" -}}
{{- $APP_NAMESPACE := .Release.Namespace -}}
{{- if (and .Values.application .Values.application.metadata) -}}
{{- $APP_NAMESPACE := .Values.application.metadata.namespace -}}
{{- end -}}
{{- $APP_NAMESPACE := (include "application.namespace" .) }}
{{- if eq "kserve-0.10" .Values.environment -}}
predictor-default.{{ $APP_NAMESPACE }}.svc.cluster.local
{{- else }} {{- /* kserve-0.11 or kserve */ -}}
Expand Down
17 changes: 4 additions & 13 deletions charts/release/templates/_kserve.version.isvc.tpl
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
{{- define "env.kserve.version.isvc" }}

{{- /* compute labels */}}
{{- $labels := include "application.version.labels" . | mustFromJson }}

{{- /* compute annotations */}}
{{- $annotations := include "application.version.annotations" . | mustFromJson }}
{{- $annotations := merge (dict "serving.kserve.io/deploymentMode" "ModelMesh") $annotations }}

{{- /* compose into metadata */}}
{{- $metadata := (dict) }}
{{- $metadata := set $metadata "name" .VERSION_NAME }}
{{- $metadata := set $metadata "namespace" .VERSION_NAMESPACE }}
{{- $metadata := set $metadata "labels" $labels }}
{{- $metadata := set $metadata "annotations" $annotations }}
{{- /* 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
Expand Down
17 changes: 4 additions & 13 deletions charts/release/templates/_mm-istio.version.isvc.tpl
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
{{- define "env.mm-istio.version.isvc" }}

{{- /* compute labels */}}
{{- $labels := include "application.version.labels" . | mustFromJson }}

{{- /* compute annotations */}}
{{- $annotations := include "application.version.annotations" . | mustFromJson }}
{{- $annotations := merge (dict "serving.kserve.io/deploymentMode" "ModelMesh") $annotations }}

{{- /* compose into metadata */}}
{{- $metadata := (dict) }}
{{- $metadata := set $metadata "name" .VERSION_NAME }}
{{- $metadata := set $metadata "namespace" .VERSION_NAMESPACE }}
{{- $metadata := set $metadata "labels" $labels }}
{{- $metadata := set $metadata "annotations" $annotations }}
{{- /* 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
Expand Down

0 comments on commit 36aed89

Please sign in to comment.