diff --git a/templates/policies/application-policies.yaml b/templates/policies/application-policies.yaml index 4a7ef22..309b9ed 100644 --- a/templates/policies/application-policies.yaml +++ b/templates/policies/application-policies.yaml @@ -40,9 +40,22 @@ spec: - repoURL: {{ coalesce .repoURL $.Values.global.repoURL }} targetRevision: {{ coalesce .targetRevision $.Values.global.targetRevision }} ref: patternref - - repoURL: {{ $.Values.global.multiSourceRepoUrl }} - targetRevision: {{ $.Values.global.multiSourceTargetRevision }} + {{/* If we're using the clustergroup chart from a git repo let's use those */}} + {{- $clusterGroupGitRepoUrl := "" }} + {{- if and $.Values.main $.Values.main.multiSourceConfig }} + {{- $clusterGroupGitRepoUrl = $.Values.main.multiSourceConfig.clusterGroupGitRepoUrl }} + {{- end }} + {{- $clusterGroupChartGitRevision := "" }} + {{- if and $.Values.main $.Values.main.multiSourceConfig }} + {{- $clusterGroupChartGitRevision = $.Values.main.multiSourceConfig.clusterGroupChartGitRevision }} + {{- end }} + - repoURL: {{ coalesce $clusterGroupGitRepoUrl $.Values.global.multiSourceRepoUrl }} + targetRevision: {{ coalesce $clusterGroupChartGitRevision $.Values.global.multiSourceTargetRevision }} + {{- if and $.Values.main $.Values.main.multiSourceConfig (hasKey $.Values.main.multiSourceConfig "clusterGroupGitRepoUrl") }} + path: "." + {{- else }} chart: clustergroup + {{- end }} helm: ignoreMissingValueFiles: true values: | diff --git a/tests/application_policy_test.yaml b/tests/application_policy_test.yaml index 7b3711a..c7c404a 100644 --- a/tests/application_policy_test.yaml +++ b/tests/application_policy_test.yaml @@ -87,3 +87,105 @@ tests: path: spec.clusterSelector.matchLabels.clusterGroup value: group-two + # Tests for clusterGroupGitRepoUrl and clusterGroupChartGitRevision + - it: Should use chart clustergroup when clusterGroupGitRepoUrl is not set + 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 + equal: + path: spec.policy-templates[0].objectDefinition.spec.object-templates[0].objectDefinition.spec.sources[1].chart + value: clustergroup + - documentSelector: + path: metadata.name + value: group-one-clustergroup-policy + equal: + path: spec.policy-templates[0].objectDefinition.spec.object-templates[0].objectDefinition.spec.sources[1].repoURL + value: "https://charts.example.com" + - documentSelector: + path: metadata.name + value: group-one-clustergroup-policy + equal: + path: spec.policy-templates[0].objectDefinition.spec.object-templates[0].objectDefinition.spec.sources[1].targetRevision + value: "0.1.0" + - documentSelector: + path: metadata.name + value: group-one-clustergroup-policy + isNull: + path: spec.policy-templates[0].objectDefinition.spec.object-templates[0].objectDefinition.spec.sources[1].path + + - it: Should use path when clusterGroupGitRepoUrl is set + values: + - ./clusterselector_values.yaml + set: + global: + multiSourceSupport: true + multiSourceRepoUrl: "https://charts.example.com" + multiSourceTargetRevision: "0.1.0" + main: + multiSourceConfig: + clusterGroupGitRepoUrl: "https://github.com/example/clustergroup-chart" + clusterGroupChartGitRevision: "feature-branch" + asserts: + - documentSelector: + path: metadata.name + value: group-one-clustergroup-policy + equal: + path: spec.policy-templates[0].objectDefinition.spec.object-templates[0].objectDefinition.spec.sources[1].path + value: "." + - documentSelector: + path: metadata.name + value: group-one-clustergroup-policy + equal: + path: spec.policy-templates[0].objectDefinition.spec.object-templates[0].objectDefinition.spec.sources[1].repoURL + value: "https://github.com/example/clustergroup-chart" + - documentSelector: + path: metadata.name + value: group-one-clustergroup-policy + equal: + path: spec.policy-templates[0].objectDefinition.spec.object-templates[0].objectDefinition.spec.sources[1].targetRevision + value: "feature-branch" + - documentSelector: + path: metadata.name + value: group-one-clustergroup-policy + isNull: + path: spec.policy-templates[0].objectDefinition.spec.object-templates[0].objectDefinition.spec.sources[1].chart + + - it: Should use clusterGroupGitRepoUrl with fallback to multiSourceTargetRevision when only clusterGroupGitRepoUrl is set + values: + - ./clusterselector_values.yaml + set: + global: + multiSourceSupport: true + multiSourceRepoUrl: "https://charts.example.com" + multiSourceTargetRevision: "0.1.0" + main: + multiSourceConfig: + clusterGroupGitRepoUrl: "https://github.com/example/clustergroup-chart" + asserts: + - documentSelector: + path: metadata.name + value: group-one-clustergroup-policy + equal: + path: spec.policy-templates[0].objectDefinition.spec.object-templates[0].objectDefinition.spec.sources[1].path + value: "." + - documentSelector: + path: metadata.name + value: group-one-clustergroup-policy + equal: + path: spec.policy-templates[0].objectDefinition.spec.object-templates[0].objectDefinition.spec.sources[1].repoURL + value: "https://github.com/example/clustergroup-chart" + - documentSelector: + path: metadata.name + value: group-one-clustergroup-policy + equal: + path: spec.policy-templates[0].objectDefinition.spec.object-templates[0].objectDefinition.spec.sources[1].targetRevision + value: "0.1.0" +