Skip to content

Commit

Permalink
Update to gloo.util.mergeOverwriteWithOmit
Browse files Browse the repository at this point in the history
  • Loading branch information
davidjumani committed Nov 13, 2023
1 parent ddc6774 commit c388adb
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
{{- $settings := .Values.settings }}
{{- $isUpgrade := .Values.gateway.upgrade }}
{{- $gatewayProxy := .Values.gatewayProxies.gatewayProxy -}}
{{- $spec := include "gloo.util.overwriteWithOmit" (list $gatewaySpec $gatewayProxy $gatewaySpec.omitKeys) | fromJson }}
{{- $spec := include "gloo.util.mergeOverwriteWithOmit" (list $gatewaySpec $gatewayProxy) | fromJson }}
{{- $ports := list }}
{{- if not (empty $spec.podTemplate) }}
{{- $ports = (list $spec.podTemplate.httpPort $spec.podTemplate.httpsPort $spec.podTemplate.extraPorts) }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{{- $gatewaySpec := (index . 2) }}
{{- with (first .) }}
{{- $gatewayProxy := .Values.gatewayProxies.gatewayProxy -}}
{{- $spec := include "gloo.util.overwriteWithOmit" (list $gatewaySpec $gatewayProxy $gatewaySpec.omitKeys) | fromJson }}
{{- $spec := include "gloo.util.mergeOverwriteWithOmit" (list $gatewaySpec $gatewayProxy) | fromJson }}
{{- if $spec.kind.deployment }}
{{- if $spec.horizontalPodAutoscaler }}
apiVersion: {{ $spec.horizontalPodAutoscaler.apiVersion }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{{- $gatewaySpec := (index . 2) }}
{{- with (first .) }}
{{- $gatewayProxy := .Values.gatewayProxies.gatewayProxy -}}
{{- $spec := include "gloo.util.overwriteWithOmit" (list $gatewaySpec $gatewayProxy $gatewaySpec.omitKeys) | fromJson }}
{{- $spec := include "gloo.util.mergeOverwriteWithOmit" (list $gatewaySpec $gatewayProxy) | fromJson }}
{{- if $spec.kind.deployment}}
{{- if $spec.podDisruptionBudget }}
apiVersion: policy/v1
Expand Down
2 changes: 1 addition & 1 deletion install/helm/gloo/templates/9-gateway-proxy-configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
{{- with (first .) }}
{{- $global := .Values.global }}
{{- $gatewayProxy := .Values.gatewayProxies.gatewayProxy -}}
{{- $spec := include "gloo.util.overwriteWithOmit" (list $gatewaySpec $gatewayProxy $gatewaySpec.omitKeys) | fromJson }}
{{- $spec := include "gloo.util.mergeOverwriteWithOmit" (list $gatewaySpec $gatewayProxy) | fromJson }}
{{- if not $spec.disabled }}
{{- $statsConfig := coalesce $spec.stats $global.glooStats }}
# config_map
Expand Down
2 changes: 1 addition & 1 deletion install/helm/gloo/templates/_8-default-gateways.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ spec:
{{- define "gloo.customResources.defaultGateways" -}}
{{- $gatewayProxy := .Values.gatewayProxies.gatewayProxy }}
{{- range $name, $gatewaySpec := .Values.gatewayProxies }}
{{- $spec := include "gloo.util.overwriteWithOmit" (list $gatewaySpec $gatewayProxy $gatewaySpec.omitKeys) | fromJson }}
{{- $spec := include "gloo.util.mergeOverwriteWithOmit" (list $gatewaySpec $gatewayProxy) | fromJson }}
{{- $gatewaySettings := $spec.gatewaySettings }}
{{- if and $spec.gatewaySettings (not $gatewaySpec.disabled) }}
{{- $ctx := (list $ $name $spec) }}
Expand Down
23 changes: 17 additions & 6 deletions install/helm/gloo/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
{{/* vim: set filetype=mustache: */}}

{{- /*
There can be cases when we do not want to overwrite an empty value on a resource when merged.
Eg. To generate a proxy config, we mergeOverwrite it with the default gateway-proxy config.
If we want to preserve the empty value of the gateway and not have them overwritten, we set it to `gloo.omitOverwrite`
and call `gloo.util.mergeOverwriteWithOmit` when merging. This sets all fields with values equal to this back to empty after the overwrite
*/ -}}
{{- define "gloo.omitOverwrite" -}}
DO-NOT-OVERWRITE
{{- end -}}

{{- define "gloo.roleKind" -}}
{{- if .Values.global.glooRbac.namespaced -}}
Role
Expand Down Expand Up @@ -226,13 +236,14 @@ Otherwise it will generate ["Create", "Update", "Delete"]
{{ toJson $operations -}}
{{- end -}}
{{- define "gloo.util.overwriteWithOmit" -}}
{{- define "gloo.util.mergeOverwriteWithOmit" -}}
{{- $resource := first . -}}
{{- $overwrite := index . 1 -}}
{{- $result := deepCopy $resource | mergeOverwrite (deepCopy $overwrite) -}}
{{- $omitKeys := index . 2 | default list -}}
{{- range $key := $omitKeys }}
{{- $_ := unset $result $key }}
{{- end }}
{{ $result | toJson }}
{{- range $key, $value := $result }}
{{- if eq (toString $value) "gloo.omitOverwrite" -}}
{{- $_ := unset $result $key }}
{{- end -}}
{{- end -}}
{{ toJson $result }}
{{- end -}}

0 comments on commit c388adb

Please sign in to comment.