From dd63feb9ac186d69abdff3aac0d1a62051b6a923 Mon Sep 17 00:00:00 2001 From: Michele Baldessari Date: Sun, 12 Jul 2026 19:58:44 +0200 Subject: [PATCH] New value folder structure support When we get the "global.vpNewFolderDir" value set to true we need to switch to the new folder structure. --- templates/_helpers.tpl | 26 ++++++ templates/policies/application-policies.yaml | 4 +- tests/application_policy_test.yaml | 4 +- ...ication_policy_values_folder_dir_test.yaml | 87 +++++++++++++++++++ 4 files changed, 117 insertions(+), 4 deletions(-) create mode 100644 tests/application_policy_values_folder_dir_test.yaml diff --git a/templates/_helpers.tpl b/templates/_helpers.tpl index 79f4b98..05007ae 100644 --- a/templates/_helpers.tpl +++ b/templates/_helpers.tpl @@ -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' @@ -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' @@ -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" -}} @@ -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" -}} diff --git a/templates/policies/application-policies.yaml b/templates/policies/application-policies.yaml index b363cae..e7f3853 100644 --- a/templates/policies/application-policies.yaml +++ b/templates/policies/application-policies.yaml @@ -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 }} @@ -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 }} diff --git a/tests/application_policy_test.yaml b/tests/application_policy_test.yaml index d054242..4b4de1e 100644 --- a/tests/application_policy_test.yaml +++ b/tests/application_policy_test.yaml @@ -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 @@ -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 diff --git a/tests/application_policy_values_folder_dir_test.yaml b/tests/application_policy_values_folder_dir_test.yaml new file mode 100644 index 0000000..ec6f72d --- /dev/null +++ b/tests/application_policy_values_folder_dir_test.yaml @@ -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"