Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +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
{{- if eq $.Values.global.deletePattern "DeleteSpokeChildApps" }}
value: DeleteChildApps
{{- else }}
value: {{ $.Values.global.deletePattern }}
{{- end }}
{{- end }} {{- /*acm.app.policies.helmparameters */}}

{{- define "acm.app.clusterSelector" -}}
Expand Down
1 change: 0 additions & 1 deletion templates/multiclusterhub.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
8 changes: 8 additions & 0 deletions templates/policies/application-policies.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# TODO: Also create a GitOpsCluster.apps.open-cluster-management.io
{{- range .Values.clusterGroup.managedClusterGroups }}
{{- $group := . }}
{{- if ($.Values.global.deletePattern | eq "DeleteSpoke" ) }}
{{- else }}
apiVersion: policy.open-cluster-management.io/v1
kind: Policy
metadata:
Expand All @@ -18,6 +20,7 @@ spec:
metadata:
name: {{ .name }}-clustergroup-config
spec:
pruneObjectBehavior: DeleteIfCreated
remediationAction: enforce
severity: medium
namespaceSelector:
Expand Down Expand Up @@ -129,7 +132,11 @@ spec:
namespace: {{ $.Values.global.pattern }}-{{ .name }}
syncPolicy:
automated:
{{- if ($.Values.global.deletePattern | ne "none" ) }}
prune: true
{{- else }}
prune: false
{{- end }}
selfHeal: true
retry:
limit: {{ default 20 $.Values.global.options.applicationRetryLimit }}
Expand Down Expand Up @@ -174,3 +181,4 @@ spec:
) | nindent 2 }}
---
{{- end }}
{{- end }}
85 changes: 85 additions & 0 deletions tests/application_policy_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 0 additions & 3 deletions tests/multiclusterhub_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }'
Expand Down