Skip to content

Commit

Permalink
fix(helm): avoid GitOps diff on matchConditions
Browse files Browse the repository at this point in the history
Signed-off-by: Mathieu Parent <[email protected]>
  • Loading branch information
sathieu committed May 14, 2024
1 parent f81f0ac commit 4989188
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions cmd/build/helmify/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,14 @@ func (ks *kindSet) Write() error {

if name == "validation.gatekeeper.sh" {
matchConditions := " matchConditions: {{ toYaml .Values.validatingWebhookMatchConditions | nindent 4 }}"
replace := fmt.Sprintf(" {{- if ge (int .Capabilities.KubeVersion.Minor) 28 }}\n%s\n {{- end }}", matchConditions)
replace := fmt.Sprintf(" {{- if and .Values.validatingWebhookMatchConditions (ge (int .Capabilities.KubeVersion.Minor) 28) }}\n%s\n {{- end }}", matchConditions)
obj = "{{- if not .Values.disableValidatingWebhook }}\n" + strings.Replace(obj, matchConditions, replace, 1) + end + "\n"
fileName = fmt.Sprintf("gatekeeper-validating-webhook-configuration-%s.yaml", strings.ToLower(kind))
}

if name == "mutation.gatekeeper.sh" {
matchConditions := " matchConditions: {{ toYaml .Values.mutatingWebhookMatchConditions | nindent 4 }}"
replace := fmt.Sprintf(" {{- if ge (int .Capabilities.KubeVersion.Minor) 28 }}\n%s\n {{- end }}", matchConditions)
replace := fmt.Sprintf(" {{- if .Values.mutatingWebhookMatchConditions and (ge (int .Capabilities.KubeVersion.Minor) 28) }}\n%s\n {{- end }}", matchConditions)
obj = "{{- if not .Values.disableMutation }}\n" + strings.Replace(obj, matchConditions, replace, 1) + end + "\n"
fileName = fmt.Sprintf("gatekeeper-mutating-webhook-configuration-%s.yaml", strings.ToLower(kind))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ webhooks:
path: /v1/mutate
{{- end }}
failurePolicy: {{ .Values.mutatingWebhookFailurePolicy }}
{{- if ge (int .Capabilities.KubeVersion.Minor) 28 }}
{{- if .Values.mutatingWebhookMatchConditions and (ge (int .Capabilities.KubeVersion.Minor) 28) }}
matchConditions: {{ toYaml .Values.mutatingWebhookMatchConditions | nindent 4 }}
{{- end }}
matchPolicy: Exact
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ webhooks:
path: /v1/admit
{{- end }}
failurePolicy: {{ .Values.validatingWebhookFailurePolicy }}
{{- if ge (int .Capabilities.KubeVersion.Minor) 28 }}
{{- if and .Values.validatingWebhookMatchConditions (ge (int .Capabilities.KubeVersion.Minor) 28) }}
matchConditions: {{ toYaml .Values.validatingWebhookMatchConditions | nindent 4 }}
{{- end }}
matchPolicy: Exact
Expand All @@ -37,7 +37,7 @@ webhooks:
operator: NotIn
values:
- {{ .Release.Namespace }}

{{- range $key, $value := .Values.validatingWebhookExemptNamespacesLabels}}
- key: {{ $key }}
operator: NotIn
Expand Down

0 comments on commit 4989188

Please sign in to comment.