Skip to content

Commit 2fee446

Browse files
committed
Fix clustergroup from git on spokes
This will require pattern-operator 0.0.65 to work
1 parent cbd270f commit 2fee446

3 files changed

Lines changed: 165 additions & 2 deletions

File tree

templates/_helpers.tpl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@ Default always defined valueFiles to be included when pushing the cluster wide a
5656
value: {{ $.Values.global.privateRepo | quote }}
5757
- name: global.experimentalCapabilities
5858
value: {{ $.Values.global.experimentalCapabilities }}
59+
{{- if hasKey $.Values.global "clusterGroupGitRepoUrl" }}
60+
- name: global.clusterGroupGitRepoUrl
61+
value: {{ $.Values.global.clusterGroupGitRepoUrl }}
62+
{{- end }}
63+
{{- if hasKey $.Values.global "clusterGroupChartGitRevision" }}
64+
- name: global.clusterGroupChartGitRevision
65+
value: {{ $.Values.global.clusterGroupChartGitRevision }}
66+
{{- end }}
5967
{{- end }} {{- /*acm.app.policies.helmparameters */}}
6068

6169
{{- define "acm.app.clusterSelector" -}}

templates/policies/application-policies.yaml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,14 @@ spec:
4040
- repoURL: {{ coalesce .repoURL $.Values.global.repoURL }}
4141
targetRevision: {{ coalesce .targetRevision $.Values.global.targetRevision }}
4242
ref: patternref
43-
- repoURL: {{ $.Values.global.multiSourceRepoUrl }}
44-
targetRevision: {{ $.Values.global.multiSourceTargetRevision }}
43+
{{/* If we're using the clustergroup chart from a git repo let's use those */}}
44+
- repoURL: {{ coalesce $.Values.global.clusterGroupGitRepoUrl $.Values.global.multiSourceRepoUrl }}
45+
targetRevision: {{ coalesce $.Values.global.clusterGroupChartGitRevision $.Values.global.multiSourceTargetRevision }}
46+
{{- if hasKey $.Values.global "clusterGroupGitRepoUrl" }}
47+
path: "."
48+
{{- else }}
4549
chart: clustergroup
50+
{{- end }}
4651
helm:
4752
ignoreMissingValueFiles: true
4853
values: |

tests/application_policy_test.yaml

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,153 @@ tests:
8787
path: spec.clusterSelector.matchLabels.clusterGroup
8888
value: group-two
8989

90+
# Tests for clusterGroupGitRepoUrl and clusterGroupChartGitRevision
91+
- it: Should use chart clustergroup when clusterGroupGitRepoUrl is not set
92+
values:
93+
- ./clusterselector_values.yaml
94+
set:
95+
global:
96+
multiSourceSupport: true
97+
multiSourceRepoUrl: "https://charts.example.com"
98+
multiSourceTargetRevision: "0.1.0"
99+
asserts:
100+
- documentSelector:
101+
path: metadata.name
102+
value: group-one-clustergroup-policy
103+
equal:
104+
path: spec.policy-templates[0].objectDefinition.spec.object-templates[0].objectDefinition.spec.sources[1].chart
105+
value: clustergroup
106+
- documentSelector:
107+
path: metadata.name
108+
value: group-one-clustergroup-policy
109+
equal:
110+
path: spec.policy-templates[0].objectDefinition.spec.object-templates[0].objectDefinition.spec.sources[1].repoURL
111+
value: "https://charts.example.com"
112+
- documentSelector:
113+
path: metadata.name
114+
value: group-one-clustergroup-policy
115+
equal:
116+
path: spec.policy-templates[0].objectDefinition.spec.object-templates[0].objectDefinition.spec.sources[1].targetRevision
117+
value: "0.1.0"
118+
- documentSelector:
119+
path: metadata.name
120+
value: group-one-clustergroup-policy
121+
isNull:
122+
path: spec.policy-templates[0].objectDefinition.spec.object-templates[0].objectDefinition.spec.sources[1].path
123+
124+
- it: Should use path when clusterGroupGitRepoUrl is set
125+
values:
126+
- ./clusterselector_values.yaml
127+
set:
128+
global:
129+
multiSourceSupport: true
130+
multiSourceRepoUrl: "https://charts.example.com"
131+
multiSourceTargetRevision: "0.1.0"
132+
clusterGroupGitRepoUrl: "https://github.com/example/clustergroup-chart"
133+
clusterGroupChartGitRevision: "feature-branch"
134+
asserts:
135+
- documentSelector:
136+
path: metadata.name
137+
value: group-one-clustergroup-policy
138+
equal:
139+
path: spec.policy-templates[0].objectDefinition.spec.object-templates[0].objectDefinition.spec.sources[1].path
140+
value: "."
141+
- documentSelector:
142+
path: metadata.name
143+
value: group-one-clustergroup-policy
144+
equal:
145+
path: spec.policy-templates[0].objectDefinition.spec.object-templates[0].objectDefinition.spec.sources[1].repoURL
146+
value: "https://github.com/example/clustergroup-chart"
147+
- documentSelector:
148+
path: metadata.name
149+
value: group-one-clustergroup-policy
150+
equal:
151+
path: spec.policy-templates[0].objectDefinition.spec.object-templates[0].objectDefinition.spec.sources[1].targetRevision
152+
value: "feature-branch"
153+
- documentSelector:
154+
path: metadata.name
155+
value: group-one-clustergroup-policy
156+
isNull:
157+
path: spec.policy-templates[0].objectDefinition.spec.object-templates[0].objectDefinition.spec.sources[1].chart
158+
159+
- it: Should pass clusterGroupGitRepoUrl as helm parameter when set
160+
values:
161+
- ./clusterselector_values.yaml
162+
set:
163+
global:
164+
multiSourceSupport: true
165+
multiSourceRepoUrl: "https://charts.example.com"
166+
multiSourceTargetRevision: "0.1.0"
167+
clusterGroupGitRepoUrl: "https://github.com/example/clustergroup-chart"
168+
clusterGroupChartGitRevision: "feature-branch"
169+
asserts:
170+
- documentSelector:
171+
path: metadata.name
172+
value: group-one-clustergroup-policy
173+
contains:
174+
path: spec.policy-templates[0].objectDefinition.spec.object-templates[0].objectDefinition.spec.sources[1].helm.parameters
175+
content:
176+
name: global.clusterGroupGitRepoUrl
177+
value: "https://github.com/example/clustergroup-chart"
178+
- documentSelector:
179+
path: metadata.name
180+
value: group-one-clustergroup-policy
181+
contains:
182+
path: spec.policy-templates[0].objectDefinition.spec.object-templates[0].objectDefinition.spec.sources[1].helm.parameters
183+
content:
184+
name: global.clusterGroupChartGitRevision
185+
value: "feature-branch"
186+
187+
- it: Should not pass clusterGroupGitRepoUrl helm parameter when not set
188+
values:
189+
- ./clusterselector_values.yaml
190+
set:
191+
global:
192+
multiSourceSupport: true
193+
multiSourceRepoUrl: "https://charts.example.com"
194+
multiSourceTargetRevision: "0.1.0"
195+
asserts:
196+
- documentSelector:
197+
path: metadata.name
198+
value: group-one-clustergroup-policy
199+
notContains:
200+
path: spec.policy-templates[0].objectDefinition.spec.object-templates[0].objectDefinition.spec.sources[1].helm.parameters
201+
content:
202+
name: global.clusterGroupGitRepoUrl
203+
- documentSelector:
204+
path: metadata.name
205+
value: group-one-clustergroup-policy
206+
notContains:
207+
path: spec.policy-templates[0].objectDefinition.spec.object-templates[0].objectDefinition.spec.sources[1].helm.parameters
208+
content:
209+
name: global.clusterGroupChartGitRevision
210+
211+
- it: Should use clusterGroupGitRepoUrl with fallback to multiSourceTargetRevision when only clusterGroupGitRepoUrl is set
212+
values:
213+
- ./clusterselector_values.yaml
214+
set:
215+
global:
216+
multiSourceSupport: true
217+
multiSourceRepoUrl: "https://charts.example.com"
218+
multiSourceTargetRevision: "0.1.0"
219+
clusterGroupGitRepoUrl: "https://github.com/example/clustergroup-chart"
220+
asserts:
221+
- documentSelector:
222+
path: metadata.name
223+
value: group-one-clustergroup-policy
224+
equal:
225+
path: spec.policy-templates[0].objectDefinition.spec.object-templates[0].objectDefinition.spec.sources[1].path
226+
value: "."
227+
- documentSelector:
228+
path: metadata.name
229+
value: group-one-clustergroup-policy
230+
equal:
231+
path: spec.policy-templates[0].objectDefinition.spec.object-templates[0].objectDefinition.spec.sources[1].repoURL
232+
value: "https://github.com/example/clustergroup-chart"
233+
- documentSelector:
234+
path: metadata.name
235+
value: group-one-clustergroup-policy
236+
equal:
237+
path: spec.policy-templates[0].objectDefinition.spec.object-templates[0].objectDefinition.spec.sources[1].targetRevision
238+
value: "0.1.0"
239+

0 commit comments

Comments
 (0)