From 78959970036ad52054b02a1cea651fcb84c0dd26 Mon Sep 17 00:00:00 2001 From: Akos Eros Date: Fri, 6 Dec 2024 09:40:39 +0100 Subject: [PATCH 1/6] feat: Remove early sync-wave from multiclusterhub No need for manual sync-wave specified. Removing it for clarity. --- templates/multiclusterhub.yaml | 1 - tests/multiclusterhub_test.yaml | 3 --- 2 files changed, 4 deletions(-) diff --git a/templates/multiclusterhub.yaml b/templates/multiclusterhub.yaml index d8fc529..f003b69 100644 --- a/templates/multiclusterhub.yaml +++ b/templates/multiclusterhub.yaml @@ -8,7 +8,6 @@ metadata: name: multiclusterhub namespace: open-cluster-management annotations: - argocd.argoproj.io/sync-wave: "-1" installer.open-cluster-management.io/mce-subscription-spec: '{"source": "{{ default "redhat-operators" .Values.acm.mce_operator.source }}" {{- $channel }} }' spec: {{ .Values.acm.mch_spec | toYaml | indent 2 }} diff --git a/tests/multiclusterhub_test.yaml b/tests/multiclusterhub_test.yaml index f0c4f9c..2262e82 100644 --- a/tests/multiclusterhub_test.yaml +++ b/tests/multiclusterhub_test.yaml @@ -15,9 +15,6 @@ tests: apiVersion: operator.open-cluster-management.io/v1 name: multiclusterhub namespace: open-cluster-management - - equal: - path: metadata.annotations["argocd.argoproj.io/sync-wave"] - value: "-1" - equal: path: metadata.annotations["installer.open-cluster-management.io/mce-subscription-spec"] value: '{"source": "redhat-operators" }' From 0923397a900feba17fdb7d531fbd2dfffe61a0f8 Mon Sep 17 00:00:00 2001 From: Akos Eros Date: Wed, 26 Nov 2025 17:15:11 +0100 Subject: [PATCH 2/6] feat: Pass global deletepattern variable to clustergroup chart This should handle the child app deletion on spoke when the pattern gets deleted. --- templates/_helpers.tpl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/templates/_helpers.tpl b/templates/_helpers.tpl index ed0d518..09fd900 100644 --- a/templates/_helpers.tpl +++ b/templates/_helpers.tpl @@ -56,6 +56,8 @@ Default always defined valueFiles to be included when pushing the cluster wide a value: {{ $.Values.global.privateRepo | quote }} - name: global.experimentalCapabilities value: {{ $.Values.global.experimentalCapabilities }} +- name: global.deletePattern + value: {{ $.Values.global.deletePattern | quote }} {{- end }} {{- /*acm.app.policies.helmparameters */}} {{- define "acm.app.clusterSelector" -}} From 93f224587826de592b312f5485b67362e3930c27 Mon Sep 17 00:00:00 2001 From: Akos Eros Date: Wed, 26 Nov 2025 18:06:52 +0100 Subject: [PATCH 3/6] feat: enable pruning of app of apps (argocd) This should handle the child app deletion on spoke when the pattern gets deleted. --- templates/policies/application-policies.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/templates/policies/application-policies.yaml b/templates/policies/application-policies.yaml index 309b9ed..16afa37 100644 --- a/templates/policies/application-policies.yaml +++ b/templates/policies/application-policies.yaml @@ -129,7 +129,11 @@ spec: namespace: {{ $.Values.global.pattern }}-{{ .name }} syncPolicy: automated: + {{- if eq ($.Values.global.deletePattern | default "0" | int) 1 }} + prune: true + {{- else }} prune: false + {{- end }} selfHeal: true retry: limit: {{ default 20 $.Values.global.options.applicationRetryLimit }} From 95b7a262254ee04859fb9f3accadc41348f64160 Mon Sep 17 00:00:00 2001 From: Akos Eros Date: Fri, 28 Nov 2025 14:20:41 +0100 Subject: [PATCH 4/6] feat: enable pruning of app of apps (acm) This should handle the app of app deletion on spoke when the pattern gets deleted, in the phase where we remove the acm, and the acm policies --- templates/policies/application-policies.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/templates/policies/application-policies.yaml b/templates/policies/application-policies.yaml index 16afa37..1af0f31 100644 --- a/templates/policies/application-policies.yaml +++ b/templates/policies/application-policies.yaml @@ -1,6 +1,7 @@ # TODO: Also create a GitOpsCluster.apps.open-cluster-management.io {{- range .Values.clusterGroup.managedClusterGroups }} {{- $group := . }} +{{- if ne ($.Values.global.deletePattern | default "0" | int) 0 }} apiVersion: policy.open-cluster-management.io/v1 kind: Policy metadata: @@ -18,6 +19,7 @@ spec: metadata: name: {{ .name }}-clustergroup-config spec: + pruneObjectBehavior: DeleteIfCreated remediationAction: enforce severity: medium namespaceSelector: @@ -178,3 +180,4 @@ spec: ) | nindent 2 }} --- {{- end }} +{{- end }} From f84958d9322ced02923cbec49f557fb7249a8650 Mon Sep 17 00:00:00 2001 From: Akos Eros Date: Mon, 12 Jan 2026 21:41:09 +0100 Subject: [PATCH 5/6] feat: refactor deletePattern variable Change variable to string from int (magic number) If acm chart gets deleteSpokeChildApps, it will set, deletePattern to deleteChildApps and pass it to its app of apps (clustergroup chart) --- templates/_helpers.tpl | 9 ++++++++- templates/policies/application-policies.yaml | 5 +++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/templates/_helpers.tpl b/templates/_helpers.tpl index 09fd900..0094d90 100644 --- a/templates/_helpers.tpl +++ b/templates/_helpers.tpl @@ -56,8 +56,15 @@ Default always defined valueFiles to be included when pushing the cluster wide a value: {{ $.Values.global.privateRepo | quote }} - name: global.experimentalCapabilities value: {{ $.Values.global.experimentalCapabilities }} +{{/* +if this chart gets DeleteSpokeChildApps, it will set deletePattern to DeleteChildApps to remove the child apps from spokes +*/}} - name: global.deletePattern - value: {{ $.Values.global.deletePattern | quote }} + {{- if eq $.Values.global.deletePattern "DeleteSpokeChildApps" }} + value: DeleteChildApps + {{- else }} + value: {{ $.Values.global.deletePattern }} + {{- end }} {{- end }} {{- /*acm.app.policies.helmparameters */}} {{- define "acm.app.clusterSelector" -}} diff --git a/templates/policies/application-policies.yaml b/templates/policies/application-policies.yaml index 1af0f31..fa0725d 100644 --- a/templates/policies/application-policies.yaml +++ b/templates/policies/application-policies.yaml @@ -1,7 +1,8 @@ # TODO: Also create a GitOpsCluster.apps.open-cluster-management.io {{- range .Values.clusterGroup.managedClusterGroups }} {{- $group := . }} -{{- if ne ($.Values.global.deletePattern | default "0" | int) 0 }} +{{- if ($.Values.global.deletePattern | eq "DeleteSpoke" ) }} +{{- else }} apiVersion: policy.open-cluster-management.io/v1 kind: Policy metadata: @@ -131,7 +132,7 @@ spec: namespace: {{ $.Values.global.pattern }}-{{ .name }} syncPolicy: automated: - {{- if eq ($.Values.global.deletePattern | default "0" | int) 1 }} + {{- if ($.Values.global.deletePattern | ne "none" ) }} prune: true {{- else }} prune: false From 9648a46a0a14225c2836806dba78f67bf102b860 Mon Sep 17 00:00:00 2001 From: Akos Eros Date: Thu, 5 Feb 2026 11:02:21 +0100 Subject: [PATCH 6/6] feat: add unit tests for deletion logic If acm chart gets deleteSpokeChildApps, it will set, deletePattern to deleteChildApps and pass it to its app of apps (clustergroup chart) --- tests/application_policy_test.yaml | 85 ++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) diff --git a/tests/application_policy_test.yaml b/tests/application_policy_test.yaml index c7c404a..184c578 100644 --- a/tests/application_policy_test.yaml +++ b/tests/application_policy_test.yaml @@ -189,3 +189,88 @@ tests: path: spec.policy-templates[0].objectDefinition.spec.object-templates[0].objectDefinition.spec.sources[1].targetRevision value: "0.1.0" + - it: should render a spoke app of apps with the correct helm parameters (no deletePattern 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: + - hasDocuments: + count: 3 + - documentSelector: + path: metadata.name + value: group-one-clustergroup-policy + lengthEqual: + path: spec.policy-templates[0].objectDefinition.spec.object-templates[0].objectDefinition.spec.sources[1].helm.parameters + count: 19 # 17 (in the helper) +2 (1 override, and 1 clusterGroup.name) + - documentSelector: + path: metadata.name + value: group-one-clustergroup-policy + equal: + path: spec.policy-templates[0].objectDefinition.spec.object-templates[0].objectDefinition.spec.sources[1].helm.parameters[16].name + value: "global.deletePattern" + - documentSelector: + path: metadata.name + value: group-one-clustergroup-policy + equal: + path: spec.policy-templates[0].objectDefinition.spec.object-templates[0].objectDefinition.spec.sources[1].helm.parameters[16].value + value: null + + - it: should render a spoke app of apps with the correct helm parameters (if deletePattern set to DeleteSpokeChildApps) + values: + - ./clusterselector_values.yaml + set: + global: + multiSourceSupport: true + multiSourceRepoUrl: "https://charts.example.com" + multiSourceTargetRevision: "0.1.0" + deletePattern: DeleteSpokeChildApps + main: + multiSourceConfig: + clusterGroupGitRepoUrl: "https://github.com/example/clustergroup-chart" + clusterGroupChartGitRevision: "feature-branch" + asserts: + - hasDocuments: + count: 3 + - documentSelector: + path: metadata.name + value: group-one-clustergroup-policy + lengthEqual: + path: spec.policy-templates[0].objectDefinition.spec.object-templates[0].objectDefinition.spec.sources[1].helm.parameters + count: 19 # 17 (in the helper) +2 (1 override, and 1 clusterGroup.name) + - documentSelector: + path: metadata.name + value: group-one-clustergroup-policy + equal: + path: spec.policy-templates[0].objectDefinition.spec.object-templates[0].objectDefinition.spec.sources[1].helm.parameters[16].name + value: "global.deletePattern" + - documentSelector: + path: metadata.name + value: group-one-clustergroup-policy + equal: + path: spec.policy-templates[0].objectDefinition.spec.object-templates[0].objectDefinition.spec.sources[1].helm.parameters[16].value + value: "DeleteChildApps" + + - it: should not render a spoke app of apps (if deletePattern set to DeleteSpoke) + values: + - ./clusterselector_values.yaml + set: + global: + multiSourceSupport: true + multiSourceRepoUrl: "https://charts.example.com" + multiSourceTargetRevision: "0.1.0" + deletePattern: DeleteSpoke + main: + multiSourceConfig: + clusterGroupGitRepoUrl: "https://github.com/example/clustergroup-chart" + clusterGroupChartGitRevision: "feature-branch" + asserts: + - hasDocuments: + count: 0