Skip to content

Commit 424826e

Browse files
authored
Merge pull request #38 from darkdoc/uninstall_poc
Add changes to support pattern uninstall
2 parents b55cbb4 + 9648a46 commit 424826e

File tree

5 files changed

+102
-4
lines changed

5 files changed

+102
-4
lines changed

templates/_helpers.tpl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,15 @@ 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+
{{/*
60+
if this chart gets DeleteSpokeChildApps, it will set deletePattern to DeleteChildApps to remove the child apps from spokes
61+
*/}}
62+
- name: global.deletePattern
63+
{{- if eq $.Values.global.deletePattern "DeleteSpokeChildApps" }}
64+
value: DeleteChildApps
65+
{{- else }}
66+
value: {{ $.Values.global.deletePattern }}
67+
{{- end }}
5968
{{- end }} {{- /*acm.app.policies.helmparameters */}}
6069

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

templates/multiclusterhub.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ metadata:
88
name: multiclusterhub
99
namespace: open-cluster-management
1010
annotations:
11-
argocd.argoproj.io/sync-wave: "-1"
1211
installer.open-cluster-management.io/mce-subscription-spec: '{"source": "{{ default "redhat-operators" .Values.acm.mce_operator.source }}" {{- $channel }} }'
1312
spec:
1413
{{ .Values.acm.mch_spec | toYaml | indent 2 }}

templates/policies/application-policies.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# TODO: Also create a GitOpsCluster.apps.open-cluster-management.io
22
{{- range .Values.clusterGroup.managedClusterGroups }}
33
{{- $group := . }}
4+
{{- if ($.Values.global.deletePattern | eq "DeleteSpoke" ) }}
5+
{{- else }}
46
apiVersion: policy.open-cluster-management.io/v1
57
kind: Policy
68
metadata:
@@ -18,6 +20,7 @@ spec:
1820
metadata:
1921
name: {{ .name }}-clustergroup-config
2022
spec:
23+
pruneObjectBehavior: DeleteIfCreated
2124
remediationAction: enforce
2225
severity: medium
2326
namespaceSelector:
@@ -129,7 +132,11 @@ spec:
129132
namespace: {{ $.Values.global.pattern }}-{{ .name }}
130133
syncPolicy:
131134
automated:
135+
{{- if ($.Values.global.deletePattern | ne "none" ) }}
136+
prune: true
137+
{{- else }}
132138
prune: false
139+
{{- end }}
133140
selfHeal: true
134141
retry:
135142
limit: {{ default 20 $.Values.global.options.applicationRetryLimit }}
@@ -174,3 +181,4 @@ spec:
174181
) | nindent 2 }}
175182
---
176183
{{- end }}
184+
{{- end }}

tests/application_policy_test.yaml

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,3 +189,88 @@ tests:
189189
path: spec.policy-templates[0].objectDefinition.spec.object-templates[0].objectDefinition.spec.sources[1].targetRevision
190190
value: "0.1.0"
191191

192+
- it: should render a spoke app of apps with the correct helm parameters (no deletePattern set)
193+
values:
194+
- ./clusterselector_values.yaml
195+
set:
196+
global:
197+
multiSourceSupport: true
198+
multiSourceRepoUrl: "https://charts.example.com"
199+
multiSourceTargetRevision: "0.1.0"
200+
main:
201+
multiSourceConfig:
202+
clusterGroupGitRepoUrl: "https://github.com/example/clustergroup-chart"
203+
clusterGroupChartGitRevision: "feature-branch"
204+
asserts:
205+
- hasDocuments:
206+
count: 3
207+
- documentSelector:
208+
path: metadata.name
209+
value: group-one-clustergroup-policy
210+
lengthEqual:
211+
path: spec.policy-templates[0].objectDefinition.spec.object-templates[0].objectDefinition.spec.sources[1].helm.parameters
212+
count: 19 # 17 (in the helper) +2 (1 override, and 1 clusterGroup.name)
213+
- documentSelector:
214+
path: metadata.name
215+
value: group-one-clustergroup-policy
216+
equal:
217+
path: spec.policy-templates[0].objectDefinition.spec.object-templates[0].objectDefinition.spec.sources[1].helm.parameters[16].name
218+
value: "global.deletePattern"
219+
- documentSelector:
220+
path: metadata.name
221+
value: group-one-clustergroup-policy
222+
equal:
223+
path: spec.policy-templates[0].objectDefinition.spec.object-templates[0].objectDefinition.spec.sources[1].helm.parameters[16].value
224+
value: null
225+
226+
- it: should render a spoke app of apps with the correct helm parameters (if deletePattern set to DeleteSpokeChildApps)
227+
values:
228+
- ./clusterselector_values.yaml
229+
set:
230+
global:
231+
multiSourceSupport: true
232+
multiSourceRepoUrl: "https://charts.example.com"
233+
multiSourceTargetRevision: "0.1.0"
234+
deletePattern: DeleteSpokeChildApps
235+
main:
236+
multiSourceConfig:
237+
clusterGroupGitRepoUrl: "https://github.com/example/clustergroup-chart"
238+
clusterGroupChartGitRevision: "feature-branch"
239+
asserts:
240+
- hasDocuments:
241+
count: 3
242+
- documentSelector:
243+
path: metadata.name
244+
value: group-one-clustergroup-policy
245+
lengthEqual:
246+
path: spec.policy-templates[0].objectDefinition.spec.object-templates[0].objectDefinition.spec.sources[1].helm.parameters
247+
count: 19 # 17 (in the helper) +2 (1 override, and 1 clusterGroup.name)
248+
- documentSelector:
249+
path: metadata.name
250+
value: group-one-clustergroup-policy
251+
equal:
252+
path: spec.policy-templates[0].objectDefinition.spec.object-templates[0].objectDefinition.spec.sources[1].helm.parameters[16].name
253+
value: "global.deletePattern"
254+
- documentSelector:
255+
path: metadata.name
256+
value: group-one-clustergroup-policy
257+
equal:
258+
path: spec.policy-templates[0].objectDefinition.spec.object-templates[0].objectDefinition.spec.sources[1].helm.parameters[16].value
259+
value: "DeleteChildApps"
260+
261+
- it: should not render a spoke app of apps (if deletePattern set to DeleteSpoke)
262+
values:
263+
- ./clusterselector_values.yaml
264+
set:
265+
global:
266+
multiSourceSupport: true
267+
multiSourceRepoUrl: "https://charts.example.com"
268+
multiSourceTargetRevision: "0.1.0"
269+
deletePattern: DeleteSpoke
270+
main:
271+
multiSourceConfig:
272+
clusterGroupGitRepoUrl: "https://github.com/example/clustergroup-chart"
273+
clusterGroupChartGitRevision: "feature-branch"
274+
asserts:
275+
- hasDocuments:
276+
count: 0

tests/multiclusterhub_test.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ tests:
1515
apiVersion: operator.open-cluster-management.io/v1
1616
name: multiclusterhub
1717
namespace: open-cluster-management
18-
- equal:
19-
path: metadata.annotations["argocd.argoproj.io/sync-wave"]
20-
value: "-1"
2118
- equal:
2219
path: metadata.annotations["installer.open-cluster-management.io/mce-subscription-spec"]
2320
value: '{"source": "redhat-operators" }'

0 commit comments

Comments
 (0)