Skip to content

Commit

Permalink
code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
nhudson committed Oct 2, 2024
1 parent cd9dc67 commit 2d18dc3
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 38 deletions.
9 changes: 8 additions & 1 deletion charts/tembo-ai/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,16 @@
Expand the name of the chart.
*/}}
{{- define "tembo-ai.name" -}}
{{- default $.Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Define the namespace to use across the inference-service templates
*/}}
{{- define "tembo-ai.namespace" -}}
{{- default .Release.Namespace .Values.namespace }}
{{- end -}}

{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
Expand Down
31 changes: 1 addition & 30 deletions charts/tembo-ai/templates/inference-service/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -20,39 +20,10 @@ Create the name of the inference-service service account to use
{{- include "tembo-ai.fullname" . }}-service
{{- end }}

{{/*
Define the namespace to use across the inference-service templates
*/}}
{{- define "tembo-ai.namespace" -}}
{{- default .Release.Namespace .Values.namespace }}
{{- end -}}

{{/*
Define the image configuration with override options
*/}}
{{- define "tembo-ai.inferenceService.imageConfig" -}}
{{- $defaultConfig := .defaultConfig -}}
{{- $serviceConfig := .serviceConfig -}}
{{- $result := dict -}}
{{- range $key, $value := $defaultConfig -}}
{{- if hasKey $serviceConfig $key -}}
{{- $_ := set $result $key (index $serviceConfig $key) -}}
{{- else -}}
{{- $_ := set $result $key $value -}}
{{- end -}}
{{- end -}}
{{- range $key, $value := $serviceConfig -}}
{{- if not (hasKey $result $key) -}}
{{- $_ := set $result $key $value -}}
{{- end -}}
{{- end -}}
{{- $result | toYaml -}}
{{- end -}}

{{/*
Merge configurations with priority to service-specific configs, handling nested structures
*/}}
{{- define "tembo-ai.mergeConfigs" -}}
{{- define "tembo-ai.inferenceService.mergeConfigs" -}}
{{- $result := dict -}}
{{- range $key, $value := .defaults -}}
{{- if kindIs "map" $value -}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{{- if .Values.inferenceService.services }}
{{- $defaults := .Values.inferenceService.defaults }}
{{- range $serviceName, $serviceConfig := .Values.inferenceService.services }}
{{- $mergedConfig := fromYaml (include "tembo-ai.mergeConfigs" (dict "defaults" $defaults "service" $serviceConfig)) }}
{{- $mergedConfig := fromYaml (include "tembo-ai.inferenceService.mergeConfigs" (dict "defaults" $defaults "service" $serviceConfig)) }}
{{- if and (default false $mergedConfig.enabled) $mergedConfig.externalSecrets.secretName }}
---
apiVersion: external-secrets.io/v1beta1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{{- $defaults := .Values.inferenceService.defaults }}
{{- $releaseName := default "release-name" .Release.Name }}
{{- range $serviceName, $serviceConfig := .Values.inferenceService.services }}
{{- $mergedConfig := fromYaml (include "tembo-ai.mergeConfigs" (dict "defaults" $defaults "service" $serviceConfig)) }}
{{- $mergedConfig := fromYaml (include "tembo-ai.inferenceService.mergeConfigs" (dict "defaults" $defaults "service" $serviceConfig)) }}
{{- if and (default false $mergedConfig.enabled) (default false $mergedConfig.podMonitor.enabled) }}
---
apiVersion: monitoring.coreos.com/v1
Expand Down
2 changes: 1 addition & 1 deletion charts/tembo-ai/templates/inference-service/service.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{{- if .Values.inferenceService.services }}
{{- $defaults := .Values.inferenceService.defaults }}
{{- range $serviceName, $serviceConfig := .Values.inferenceService.services }}
{{- $mergedConfig := fromYaml (include "tembo-ai.mergeConfigs" (dict "defaults" $defaults "service" $serviceConfig)) }}
{{- $mergedConfig := fromYaml (include "tembo-ai.inferenceService.mergeConfigs" (dict "defaults" $defaults "service" $serviceConfig)) }}
{{- if and (default false $mergedConfig.enabled) (default true $mergedConfig.service.enabled) }}
---
apiVersion: v1
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{{- if .Values.inferenceService.services }}
{{- $defaults := .Values.inferenceService.defaults }}
{{- range $serviceName, $serviceConfig := .Values.inferenceService.services }}
{{- $mergedConfig := fromYaml (include "tembo-ai.mergeConfigs" (dict "defaults" $defaults "service" $serviceConfig)) }}
{{- $mergedConfig := fromYaml (include "tembo-ai.inferenceService.mergeConfigs" (dict "defaults" $defaults "service" $serviceConfig)) }}
{{- if and (default false $mergedConfig.enabled) (default true $mergedConfig.serviceAccount.create) }}
---
apiVersion: v1
Expand Down
5 changes: 2 additions & 3 deletions charts/tembo-ai/templates/inference-service/statefulset.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{{- if .Values.inferenceService.services }}
{{- $defaults := .Values.inferenceService.defaults }}
{{- range $serviceName, $serviceConfig := .Values.inferenceService.services }}
{{- $mergedConfig := fromYaml (include "tembo-ai.mergeConfigs" (dict "defaults" $defaults "service" $serviceConfig)) }}
{{- $imageConfig := fromYaml (include "tembo-ai.inferenceService.imageConfig" (dict "defaultConfig" $.Values.inferenceService.defaults.image "serviceConfig" $serviceConfig.image)) }}
{{- $mergedConfig := fromYaml (include "tembo-ai.inferenceService.mergeConfigs" (dict "defaults" $defaults "service" $serviceConfig)) }}
{{- if (default false $mergedConfig.enabled) }}
---
apiVersion: apps/v1
Expand Down Expand Up @@ -41,7 +40,7 @@ spec:
- name: inference-service
securityContext:
{{- toYaml $mergedConfig.securityContext | nindent 12 }}
image: "{{ $imageConfig.repository }}:{{ $imageConfig.tag }}"
image: "{{ $mergedConfig.image.repository }}:{{ $mergedConfig.image.tag }}"
imagePullPolicy: {{ $mergedConfig.image.pullPolicy }}
ports:
- name: http
Expand Down

0 comments on commit 2d18dc3

Please sign in to comment.