Skip to content

Commit

Permalink
rework merge logic
Browse files Browse the repository at this point in the history
  • Loading branch information
nhudson committed Oct 3, 2024
1 parent 2d18dc3 commit cd451c3
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 22 deletions.
23 changes: 7 additions & 16 deletions charts/tembo-ai/templates/inference-service/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,19 @@ Create the name of the inference-service service account to use
{{- end }}

{{/*
Merge configurations with priority to service-specific configs, handling nested structures
Deepmerge the inference-service default configs and the services sepecific configs
*/}}
{{- define "tembo-ai.inferenceService.mergeConfigs" -}}
{{- $result := dict -}}
{{- range $key, $value := .defaults -}}
{{- define "tembo-ai.inferenceService.deepMerge" -}}
{{- $result := deepCopy (index . 0) -}}
{{- range $key, $value := index . 1 -}}
{{- if kindIs "map" $value -}}
{{- if hasKey $.service $key -}}
{{- $nested := dict "defaults" $value "service" (index $.service $key) -}}
{{- $_ := set $result $key (fromYaml (include "tembo-ai.mergeConfigs" $nested)) -}}
{{- if hasKey $result $key -}}
{{- $newValue := fromYaml (include "tembo-ai.inferenceService.deepMerge" (list (get $result $key) $value)) -}}
{{- $_ := set $result $key $newValue -}}
{{- else -}}
{{- $_ := set $result $key $value -}}
{{- end -}}
{{- else -}}
{{- if not (hasKey $.service $key) -}}
{{- $_ := set $result $key $value -}}
{{- else -}}
{{- $_ := set $result $key (index $.service $key) -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- range $key, $value := .service -}}
{{- if not (hasKey $result $key) -}}
{{- $_ := set $result $key $value -}}
{{- end -}}
{{- end -}}
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.inferenceService.mergeConfigs" (dict "defaults" $defaults "service" $serviceConfig)) }}
{{- $mergedConfig := fromYaml (include "tembo-ai.inferenceService.deepMerge" (list $defaults $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.inferenceService.mergeConfigs" (dict "defaults" $defaults "service" $serviceConfig)) }}
{{- $mergedConfig := fromYaml (include "tembo-ai.inferenceService.deepMerge" (list $defaults $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.inferenceService.mergeConfigs" (dict "defaults" $defaults "service" $serviceConfig)) }}
{{- $mergedConfig := fromYaml (include "tembo-ai.inferenceService.deepMerge" (list $defaults $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.inferenceService.mergeConfigs" (dict "defaults" $defaults "service" $serviceConfig)) }}
{{- $mergedConfig := fromYaml (include "tembo-ai.inferenceService.deepMerge" (list $defaults $serviceConfig)) }}
{{- if and (default false $mergedConfig.enabled) (default true $mergedConfig.serviceAccount.create) }}
---
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.inferenceService.mergeConfigs" (dict "defaults" $defaults "service" $serviceConfig)) }}
{{- $mergedConfig := fromYaml (include "tembo-ai.inferenceService.deepMerge" (list $defaults $serviceConfig)) }}
{{- if (default false $mergedConfig.enabled) }}
---
apiVersion: apps/v1
Expand Down
2 changes: 1 addition & 1 deletion charts/tembo-ai/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,6 @@ inferenceService:
accessMode: ReadWriteOnce
mountPath: /root/.cache/
# Define individual inference services here
services: []
services: {}
# service1:
# enabled: true

0 comments on commit cd451c3

Please sign in to comment.