Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@
Default always defined valueFiles to be included when pushing the cluster wide argo application via acm
*/}}
{{- define "acm.app.policies.valuefiles" -}}
{{- if $.Values.global.vpNewFolderDir }}
- "/values-global.yaml"
- "/variants/{{ $.Values.clusterGroup.name }}/values-{{ .name }}.yaml"
- '/variants/{{ $.Values.clusterGroup.name }}/values-{{ `{{ (lookup "config.openshift.io/v1" "Infrastructure" "" "cluster").spec.platformSpec.type }}` }}.yaml'
- '/variants/{{ $.Values.clusterGroup.name }}/values-{{ `{{ (lookup "config.openshift.io/v1" "Infrastructure" "" "cluster").spec.platformSpec.type }}` }}-{{ `{{ printf "%d.%d" ((semver (index (lookup "config.openshift.io/v1" "ClusterVersion" "" "version").status.history 0).version).Major) ((semver (index (lookup "config.openshift.io/v1" "ClusterVersion" "" "version").status.history 0).version).Minor) }}` }}.yaml'
- '/variants/{{ $.Values.clusterGroup.name }}/values-{{ `{{ (lookup "config.openshift.io/v1" "Infrastructure" "" "cluster").spec.platformSpec.type }}` }}-{{ .name }}.yaml'
# We cannot use $.Values.global.clusterVersion because that gets resolved to the
# hub's cluster version, whereas we want to include the spoke cluster version
- '/variants/{{ $.Values.clusterGroup.name }}/values-{{ `{{ printf "%d.%d" ((semver (index (lookup "config.openshift.io/v1" "ClusterVersion" "" "version").status.history 0).version).Major) ((semver (index (lookup "config.openshift.io/v1" "ClusterVersion" "" "version").status.history 0).version).Minor) }}` }}-{{ .name }}.yaml'
- '/variants/{{ $.Values.clusterGroup.name }}/values-{{ `{{ (split "." (lookup "config.openshift.io/v1" "Ingress" "" "cluster").spec.domain)._1 }}` }}.yaml'
{{- else }}
- "/values-global.yaml"
- "/values-{{ .name }}.yaml"
- '/values-{{ `{{ (lookup "config.openshift.io/v1" "Infrastructure" "" "cluster").spec.platformSpec.type }}` }}.yaml'
Expand All @@ -11,9 +22,21 @@ Default always defined valueFiles to be included when pushing the cluster wide a
# hub's cluster version, whereas we want to include the spoke cluster version
- '/values-{{ `{{ printf "%d.%d" ((semver (index (lookup "config.openshift.io/v1" "ClusterVersion" "" "version").status.history 0).version).Major) ((semver (index (lookup "config.openshift.io/v1" "ClusterVersion" "" "version").status.history 0).version).Minor) }}` }}-{{ .name }}.yaml'
- '/values-{{ `{{ (split "." (lookup "config.openshift.io/v1" "Ingress" "" "cluster").spec.domain)._1 }}` }}.yaml'
{{- end }} {{/* if $.Values.global.vpNewFolderDir */}}
{{- end }} {{- /*acm.app.policies.valuefiles */}}

{{- define "acm.app.policies.multisourcevaluefiles" -}}
{{- if $.Values.global.vpNewFolderDir }}
- "$patternref/values-global.yaml"
- "$patternref/variants/{{ $.Values.clusterGroup.name }}/values-{{ .name }}.yaml"
- '$patternref/variants/{{ $.Values.clusterGroup.name }}/values-{{ `{{ (lookup "config.openshift.io/v1" "Infrastructure" "" "cluster").spec.platformSpec.type }}` }}.yaml'
- '$patternref/variants/{{ $.Values.clusterGroup.name }}/values-{{ `{{ (lookup "config.openshift.io/v1" "Infrastructure" "" "cluster").spec.platformSpec.type }}` }}-{{ `{{ printf "%d.%d" ((semver (index (lookup "config.openshift.io/v1" "ClusterVersion" "" "version").status.history 0).version).Major) ((semver (index (lookup "config.openshift.io/v1" "ClusterVersion" "" "version").status.history 0).version).Minor) }}` }}.yaml'
- '$patternref/variants/{{ $.Values.clusterGroup.name }}/values-{{ `{{ (lookup "config.openshift.io/v1" "Infrastructure" "" "cluster").spec.platformSpec.type }}` }}-{{ .name }}.yaml'
# We cannot use $.Values.global.clusterVersion because that gets resolved to the
# hub's cluster version, whereas we want to include the spoke cluster version
- '$patternref/variants/{{ $.Values.clusterGroup.name }}/values-{{ `{{ printf "%d.%d" ((semver (index (lookup "config.openshift.io/v1" "ClusterVersion" "" "version").status.history 0).version).Major) ((semver (index (lookup "config.openshift.io/v1" "ClusterVersion" "" "version").status.history 0).version).Minor) }}` }}-{{ .name }}.yaml'
- '$patternref/variants/{{ $.Values.clusterGroup.name }}/values-{{ `{{ (split "." (lookup "config.openshift.io/v1" "Ingress" "" "cluster").spec.domain)._1 }}` }}.yaml'
{{- else }}
- "$patternref/values-global.yaml"
- "$patternref/values-{{ .name }}.yaml"
- '$patternref/values-{{ `{{ (lookup "config.openshift.io/v1" "Infrastructure" "" "cluster").spec.platformSpec.type }}` }}.yaml'
Expand All @@ -23,6 +46,7 @@ Default always defined valueFiles to be included when pushing the cluster wide a
# hub's cluster version, whereas we want to include the spoke cluster version
- '$patternref/values-{{ `{{ printf "%d.%d" ((semver (index (lookup "config.openshift.io/v1" "ClusterVersion" "" "version").status.history 0).version).Major) ((semver (index (lookup "config.openshift.io/v1" "ClusterVersion" "" "version").status.history 0).version).Minor) }}` }}-{{ .name }}.yaml'
- '$patternref/values-{{ `{{ (split "." (lookup "config.openshift.io/v1" "Ingress" "" "cluster").spec.domain)._1 }}` }}.yaml'
{{- end }} {{/* if $.Values.global.vpNewFolderDir */}}
{{- end }} {{- /*acm.app.policies.multisourcevaluefiles */}}

{{- define "acm.app.policies.helmparameters" -}}
Expand Down Expand Up @@ -71,6 +95,8 @@ if this chart gets DeleteSpokeChildApps, it will set deletePattern to DeleteChil
value: {{ $.Values.global.gitOpsSubNamespace }}
- name: global.vpArgoNamespace
value: {{ $.Values.global.vpArgoNamespace }}
- name: global.vpNewFolderDir
value: {{ $.Values.global.vpNewFolderDir | quote | default "false" }}
{{- end }} {{- /*acm.app.policies.helmparameters */}}

{{- define "acm.app.clusterSelector" -}}
Expand Down
4 changes: 2 additions & 2 deletions templates/policies/application-policies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ spec:
{{ $k }}: {{ printf "%s" $v | quote }}
{{- end }}
valueFiles:
{{- include "acm.app.policies.multisourcevaluefiles" . | nindent 24 }}
{{- include "acm.app.policies.multisourcevaluefiles" (merge (dict "Values" $.Values) .) | nindent 24 }}
{{- range $valueFile := .extraValueFiles }}
- {{ $valueFile | quote }}
{{- end }}
Expand Down Expand Up @@ -131,7 +131,7 @@ spec:
{{ $k }}: {{ printf "%s" $v | quote }}
{{- end }}
valueFiles:
{{- include "acm.app.policies.valuefiles" . | nindent 22 }}
{{- include "acm.app.policies.valuefiles" (merge (dict "Values" $.Values) .) | nindent 22 }}
{{- range $valueFile := .extraValueFiles }}
- {{ $valueFile | quote }}
{{- end }}
Expand Down
4 changes: 2 additions & 2 deletions tests/application_policy_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ tests:
value: group-one-clustergroup-policy
lengthEqual:
path: spec.policy-templates[0].objectDefinition.spec.object-templates[1].objectDefinition.spec.sources[1].helm.parameters
count: 21 # 18 (in the helper) +3 (1 override, and 1 clusterGroup.name)
count: 22 # 19 (in the helper) +3 (1 override, and 1 clusterGroup.name)
- documentSelector:
path: metadata.name
value: group-one-clustergroup-policy
Expand Down Expand Up @@ -303,7 +303,7 @@ tests:
value: group-one-clustergroup-policy
lengthEqual:
path: spec.policy-templates[0].objectDefinition.spec.object-templates[1].objectDefinition.spec.sources[1].helm.parameters
count: 21 # 18 (in the helper) +3 (1 override, and 1 clusterGroup.name)
count: 22 # 19 (in the helper) +3 (1 override, and 1 clusterGroup.name)
- documentSelector:
path: metadata.name
value: group-one-clustergroup-policy
Expand Down
87 changes: 87 additions & 0 deletions tests/application_policy_values_folder_dir_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
suite: Test vpNewFolderDir valueFiles layout in application policies
templates:
- templates/policies/application-policies.yaml
release:
name: release-test
tests:
- it: should use flat value file paths when vpNewFolderDir is not set (single-source)
values:
- ./clusterselector_values.yaml
asserts:
- documentSelector:
path: metadata.name
value: group-one-clustergroup-policy
contains:
path: spec.policy-templates[0].objectDefinition.spec.object-templates[1].objectDefinition.spec.source.helm.valueFiles
content: "/values-global.yaml"
- documentSelector:
path: metadata.name
value: group-one-clustergroup-policy
contains:
path: spec.policy-templates[0].objectDefinition.spec.object-templates[1].objectDefinition.spec.source.helm.valueFiles
content: "/values-group-one.yaml"

- it: should use variants directory paths when vpNewFolderDir is true (single-source)
values:
- ./clusterselector_values.yaml
set:
global:
vpNewFolderDir: true
asserts:
- documentSelector:
path: metadata.name
value: group-one-clustergroup-policy
contains:
path: spec.policy-templates[0].objectDefinition.spec.object-templates[1].objectDefinition.spec.source.helm.valueFiles
content: "/values-global.yaml"
- documentSelector:
path: metadata.name
value: group-one-clustergroup-policy
contains:
path: spec.policy-templates[0].objectDefinition.spec.object-templates[1].objectDefinition.spec.source.helm.valueFiles
content: "/variants/hub/values-group-one.yaml"

- it: should use flat value file paths when vpNewFolderDir is not set (multi-source)
values:
- ./clusterselector_values.yaml
set:
global:
multiSourceSupport: true
multiSourceRepoUrl: "https://charts.example.com"
multiSourceTargetRevision: "0.1.0"
asserts:
- documentSelector:
path: metadata.name
value: group-one-clustergroup-policy
contains:
path: spec.policy-templates[0].objectDefinition.spec.object-templates[1].objectDefinition.spec.sources[1].helm.valueFiles
content: "$patternref/values-global.yaml"
- documentSelector:
path: metadata.name
value: group-one-clustergroup-policy
contains:
path: spec.policy-templates[0].objectDefinition.spec.object-templates[1].objectDefinition.spec.sources[1].helm.valueFiles
content: "$patternref/values-group-one.yaml"

- it: should use variants directory paths when vpNewFolderDir is true (multi-source)
values:
- ./clusterselector_values.yaml
set:
global:
multiSourceSupport: true
multiSourceRepoUrl: "https://charts.example.com"
multiSourceTargetRevision: "0.1.0"
vpNewFolderDir: true
asserts:
- documentSelector:
path: metadata.name
value: group-one-clustergroup-policy
contains:
path: spec.policy-templates[0].objectDefinition.spec.object-templates[1].objectDefinition.spec.sources[1].helm.valueFiles
content: "$patternref/values-global.yaml"
- documentSelector:
path: metadata.name
value: group-one-clustergroup-policy
contains:
path: spec.policy-templates[0].objectDefinition.spec.object-templates[1].objectDefinition.spec.sources[1].helm.valueFiles
content: "$patternref/variants/hub/values-group-one.yaml"