Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix sync policy #35

Merged
merged 3 commits into from
Nov 16, 2024
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
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# clustergroup

![Version: 0.9.3](https://img.shields.io/badge/Version-0.9.3-informational?style=flat-square)
![Version: 0.9.12](https://img.shields.io/badge/Version-0.9.12-informational?style=flat-square)

A Helm chart to create per-clustergroup ArgoCD applications and any required namespaces or subscriptions.

Expand All @@ -25,6 +25,7 @@ This chart is used to set up the basic building blocks in [Validated Patterns](h
| clusterGroup.argoCD.resourceHealthChecks[0].check | string | `"hs = {}\nif obj.status ~= nil then\n if obj.status.phase ~= nil then\n if obj.status.phase == \"Pending\" then\n hs.status = \"Healthy\"\n hs.message = obj.status.phase\n return hs\n elseif obj.status.phase == \"Bound\" then\n hs.status = \"Healthy\"\n hs.message = obj.status.phase\n return hs\n end\n end\nend\nhs.status = \"Progressing\"\nhs.message = \"Waiting for PVC\"\nreturn hs\n"` | |
| clusterGroup.argoCD.resourceHealthChecks[0].kind | string | `"PersistentVolumeClaim"` | |
| clusterGroup.argoCD.resourceTrackingMethod | string | `"label"` | |
| clusterGroup.extraObjects | object | `{}` | |
| clusterGroup.imperative.activeDeadlineSeconds | int | `3600` | |
| clusterGroup.imperative.adminClusterRoleName | string | `"imperative-admin-cluster-role"` | |
| clusterGroup.imperative.adminServiceAccountCreate | bool | `true` | |
Expand Down Expand Up @@ -54,11 +55,10 @@ This chart is used to set up the basic building blocks in [Validated Patterns](h
| clusterGroup.sharedValueFiles | list | `[]` | |
| clusterGroup.subscriptions | object | `{}` | |
| clusterGroup.targetCluster | string | `"in-cluster"` | |
| enabled | string | `"all"` | |
| global.extraValueFiles | list | `[]` | |
| global.options.applicationRetryLimit | int | `20` | |
| global.options.installPlanApproval | string | `"Automatic"` | |
| global.options.syncPolicy | string | `"Automatic"` | |
| global.options.syncPolicy | string | `"Automatic"` | This defines the global syncpolicy. If set to "Manual", no syncPolicy object will be set, if set to "Automatic" syncPolicy will be set to {automated: {}, retry: { limit: global.options.applicationRetryLimit }}, if set to an object it will be passed directly to the syncPolicy field of the application. Each application can override this |
| global.options.useCSV | bool | `true` | |
| global.pattern | string | `"common"` | |
| global.secretStore.backend | string | `"vault"` | |
Expand Down
12 changes: 10 additions & 2 deletions templates/plumbing/applications.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,21 @@ spec:
{{- if .ignoreDifferences }}
ignoreDifferences: {{ .ignoreDifferences | toPrettyJson }}
{{- end }}
{{- if .syncPolicy }}
{{ $syncpolicy := coalesce .syncPolicy $.Values.global.options.syncPolicy }}
{{- if and (kindIs "string" $syncpolicy) (eq ($syncpolicy | lower) "manual") }}
syncPolicy: null
{{- else if and (kindIs "string" $syncpolicy) (eq ($syncpolicy | lower) "automatic") }}
syncPolicy:
automated: {}
retry:
limit: {{ default 20 $.Values.global.options.applicationRetryLimit }}
{{- else if $syncpolicy }}
syncPolicy: {{ .syncPolicy | toPrettyJson }}
{{- else }}
syncPolicy:
automated: {}
retry:
limit: {{ default 20 $.Values.global.applicationRetryLimit }}
limit: {{ default 20 $.Values.global.options.applicationRetryLimit }}
{{- end }}{{- /* .syncPolicy */}}
{{- end }}{{- /* if .disabled */}}
{{- end }}{{- /* range .Values.clusterGroup.applications */}}
113 changes: 113 additions & 0 deletions tests/application_sync_policies_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
suite: Test application syncPolicy
templates:
- templates/plumbing/applications.yaml
release:
name: release-test
tests:
- it: should use the default syncpolicy (automated) with default applicationRetryLimit (20)
values:
- ./application_sync_policies_values.yaml
asserts:
- isKind:
of: Application
- hasDocuments:
count: 2
- isSubset:
path: spec.syncPolicy
content:
automated: {}
retry:
limit: 20

- it: should use the default syncpolicy (automated) with custom global applicationRetryLimit (100)
values:
- ./application_sync_policies_values.yaml
set:
global:
options:
applicationRetryLimit: 100
asserts:
- isSubset:
path: spec.syncPolicy
content:
automated: {}
retry:
limit: 100

- it: should use null on all app if syncpolicy set to manual if set in global
values:
- ./application_sync_policies_values.yaml
set:
global:
options:
syncPolicy: Manual
asserts:
- isKind:
of: Application
- hasDocuments:
count: 2
- isNullOrEmpty:
path: spec.syncPolicy

- it: should use manual only on an app if syncpolicy set to manual in app
values:
- ./application_sync_policies_values.yaml
set:
clusterGroup:
applications:
acm:
syncPolicy: Manual
asserts:
- isKind:
of: Application
- hasDocuments:
count: 2
- documentSelector:
path: metadata.name
value: acm
isNullOrEmpty:
path: spec.syncPolicy
- documentSelector:
path: metadata.name
value: vault
isSubset:
path: spec.syncPolicy
content:
automated: {}
retry:
limit: 20

- it: should use custom set syncpolicy set in app
values:
- ./application_sync_policies_values.yaml
set:
clusterGroup:
applications:
acm:
syncPolicy:
custom:
somethingCustom:
customKey: "customValue"
asserts:
- isKind:
of: Application
- hasDocuments:
count: 2
- documentSelector:
path: metadata.name
value: acm
isSubset:
path: spec.syncPolicy
content:
custom:
somethingCustom:
customKey: "customValue"
- documentSelector:
path: metadata.name
value: vault
isSubset:
path: spec.syncPolicy
content:
automated: {}
retry:
limit: 20
19 changes: 19 additions & 0 deletions tests/application_sync_policies_values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
clusterGroup:
applications:
acm:
name: acm
namespace: open-cluster-management
project: hub
chart: acm
chartVersion: 0.1.*
ignoreDifferences:
- group: internal.open-cluster-management.io
kind: ManagedClusterInfo
jsonPointers:
- /spec/loggingCA
vault:
name: vault
namespace: vault
project: hub
chart: hashicorp-vault
chartVersion: 0.1.*
1 change: 1 addition & 0 deletions values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ global:
targetRevision: main
options:
useCSV: True
# -- This defines the global syncpolicy. If set to "Manual", no syncPolicy object will be set, if set to "Automatic" syncPolicy will be set to {automated: {}, retry: { limit: global.options.applicationRetryLimit }}, if set to an object it will be passed directly to the syncPolicy field of the application. Each application can override this
syncPolicy: Automatic
installPlanApproval: Automatic
applicationRetryLimit: 20
Expand Down