From b4a5c1987ba71d25a64f75f7fee3a3533f4f59d3 Mon Sep 17 00:00:00 2001 From: Akos Eros Date: Wed, 8 Oct 2025 16:04:12 +0200 Subject: [PATCH 1/3] feat: add delete global value as top level variable for child charts We want to pass a different value to child charts if we are on the hub, since we want acm to first remove all the child applications before we actually remove acm. Change it to a string, and pass directly to child charts. Acm chart will handle further logic, from clustergroup we only care if we need to render the applications or not. --- templates/_helpers.tpl | 3 +++ templates/plumbing/applications.yaml | 2 +- values.schema.json | 11 ++--------- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/templates/_helpers.tpl b/templates/_helpers.tpl index 4d8a119..555802c 100644 --- a/templates/_helpers.tpl +++ b/templates/_helpers.tpl @@ -32,6 +32,9 @@ Default always defined top-level variables for helm charts value: {{ $.Values.global.privateRepo | quote }} - name: global.experimentalCapabilities value: {{ $.Values.global.experimentalCapabilities | default "" }} +- name: global.deletePattern + value: {{ $.Values.global.deletePattern }} + {{- end }} {{/* clustergroup.globalvaluesparameters */}} diff --git a/templates/plumbing/applications.yaml b/templates/plumbing/applications.yaml index b111e3d..40a0e1f 100644 --- a/templates/plumbing/applications.yaml +++ b/templates/plumbing/applications.yaml @@ -1,4 +1,4 @@ -{{- if ($.Values.global.deletePattern | default "0" | int | ne 1) }} {{- /* When a pattern is deleting applications should be removed */}} +{{- if ($.Values.global.deletePattern | ne "DeleteChildApps") }} {{- /* When a pattern is deleting applications should be removed */}} {{- $namespace := print $.Values.global.pattern "-" $.Values.clusterGroup.name }} {{- range .Values.clusterGroup.applications }} {{- if . }} {{- /* Skip null applications */}} diff --git a/values.schema.json b/values.schema.json index df8e1d3..d3e688c 100644 --- a/values.schema.json +++ b/values.schema.json @@ -198,17 +198,10 @@ "$ref": "#/definitions/GlobalSecretStore" }, "deletePattern": { - "anyOf": [ - { - "type": "integer" - }, - { - "type": "string" - } - ], + "type": "string", "readOnly": true, "description": "Flag set by the patterns operator when a pattern CR is being deleted. When set to 1, the clustergroup chart will not render applications, allowing them to be removed before other resources. This prevents applications from becoming impossible to delete if their operators, webhooks, etc. are destroyed in the wrong order. Defaults to 0 (not deleting).", - "default": 0 + "default": "none" } }, "required": [ From c5243643f11045d4bd07b62db766b095ad5c2dca Mon Sep 17 00:00:00 2001 From: Akos Eros Date: Thu, 5 Feb 2026 09:50:06 +0100 Subject: [PATCH 2/3] feat: change unit tests to match the code changes deletePattern can now only be a string, we only want to remove the apps for a specific phase(DeleteChildApps), all other deletion phase we need the apps to be rendered. --- tests/application_delete_pattern_test.yaml | 42 +++++++++------------- tests/application_multi_source_test.yaml | 6 ++-- 2 files changed, 19 insertions(+), 29 deletions(-) diff --git a/tests/application_delete_pattern_test.yaml b/tests/application_delete_pattern_test.yaml index adf078b..1a02e2a 100644 --- a/tests/application_delete_pattern_test.yaml +++ b/tests/application_delete_pattern_test.yaml @@ -34,10 +34,10 @@ tests: isKind: of: Application - - it: should render applications when deletePattern is 0 + - it: should render applications when deletePattern is none set: global: - deletePattern: 0 + deletePattern: none clusterGroup: applications: acm: @@ -66,10 +66,10 @@ tests: isKind: of: Application - - it: should NOT render applications when deletePattern is 1 + - it: should NOT render applications when deletePattern is DeleteChildApps set: global: - deletePattern: 1 + deletePattern: DeleteChildApps clusterGroup: applications: acm: @@ -88,10 +88,10 @@ tests: - hasDocuments: count: 0 - - it: should NOT render applications when deletePattern is "1" (string) + - it: should render applications when deletePattern is set to a different phase, like DeleteSpokeChildApps set: global: - deletePattern: "1" + deletePattern: DeleteSpokeChildApps clusterGroup: applications: acm: @@ -108,33 +108,23 @@ tests: chartVersion: 0.1.* asserts: - hasDocuments: - count: 0 - - - it: should render applications when deletePattern is "0" (string) - set: - global: - deletePattern: "0" - clusterGroup: - applications: - acm: - name: acm - namespace: open-cluster-management - project: hub - chart: acm - chartVersion: 0.1.* - asserts: - - hasDocuments: - count: 1 + count: 2 - documentSelector: path: metadata.name value: acm isKind: of: Application + - documentSelector: + path: metadata.name + value: vault + isKind: + of: Application + - it: should work correctly with deletePattern when some applications are null set: global: - deletePattern: 0 + deletePattern: none clusterGroup: applications: acm: @@ -164,10 +154,10 @@ tests: isKind: of: Application - - it: should not render any applications even with null apps when deletePattern is 1 + - it: should not render any applications even with null apps when deletePattern is DeleteChildApps set: global: - deletePattern: 1 + deletePattern: DeleteChildApps clusterGroup: applications: acm: diff --git a/tests/application_multi_source_test.yaml b/tests/application_multi_source_test.yaml index 14f305a..3b2d009 100644 --- a/tests/application_multi_source_test.yaml +++ b/tests/application_multi_source_test.yaml @@ -62,7 +62,7 @@ tests: value: acm lengthEqual: path: spec.sources[1].helm.parameters - count: 15 + count: 16 - documentSelector: path: metadata.name value: vault @@ -70,7 +70,7 @@ tests: path: spec.sources[1].repoURL value: https://charts.validatedpatterns.io - - it: should render a multisource applications and its extraparameters + - it: should render a multisource applications and its 2 extraparameters set: global: repoURL: https://github.com/validatedpatterns/multicloud-gitops @@ -96,4 +96,4 @@ tests: value: acm lengthEqual: path: spec.sources[1].helm.parameters - count: 17 + count: 18 From f0f1d8c7cf0a43ffb6df27c17f952000a24ae6a9 Mon Sep 17 00:00:00 2001 From: Akos Eros Date: Thu, 5 Feb 2026 10:08:51 +0100 Subject: [PATCH 3/3] feat: fix schema deletePattern can now only be a string, we only want to remove the apps for a specific phase(DeleteChildApps), all other deletion phase we need the apps to be rendered. --- values.schema.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/values.schema.json b/values.schema.json index d3e688c..ba2ea16 100644 --- a/values.schema.json +++ b/values.schema.json @@ -200,7 +200,7 @@ "deletePattern": { "type": "string", "readOnly": true, - "description": "Flag set by the patterns operator when a pattern CR is being deleted. When set to 1, the clustergroup chart will not render applications, allowing them to be removed before other resources. This prevents applications from becoming impossible to delete if their operators, webhooks, etc. are destroyed in the wrong order. Defaults to 0 (not deleting).", + "description": "Flag set by the patterns operator when a pattern CR is being deleted. When set to DeleteChildApps, the clustergroup chart will not render applications, allowing them to be removed before other resources. This prevents applications from becoming impossible to delete if their operators, webhooks, etc. are destroyed in the wrong order. Defaults to none (not deleting).", "default": "none" } },