1+ apiVersion : argoproj.io/v1alpha1
2+ kind : ApplicationSet
3+ metadata :
4+ name : cluster-addons
5+ namespace : argocd
6+ spec :
7+ syncPolicy :
8+ preserveResourcesOnDeletion : false
9+ goTemplate : true
10+ goTemplateOptions :
11+ - missingkey=error
12+ generators :
13+ - matrix :
14+ generators :
15+ - matrix :
16+ generators :
17+ - clusters :
18+ selector :
19+ matchLabels :
20+ fleet_member : hub-cluster
21+ values :
22+ chartName : application-sets
23+ chartRepo : " 12345678910.dkr.ecr.eu-west-2.amazonaws.com"
24+ chartPath : " charts/application-sets"
25+ applicationSetGroup : " addons"
26+ groupRelease : ' {{default "" (index .metadata.labels "addonsRelease")}}'
27+ useSelectors : " false"
28+ useVersionSelectors : " true"
29+ - git :
30+ repoURL : ' {{ .metadata.annotations.fleet_repo_url }}'
31+ revision : ' {{ .metadata.annotations.fleet_repo_revision }}'
32+ files :
33+ - path : " {{ .metadata.annotations.fleet_repo_basepath }}/bootstrap/versions/applicationSets.yaml"
34+ - list :
35+ elementsYaml : |
36+ {{- $releaseTypes := index .releases .values.applicationSetGroup | toJson | fromJson -}}
37+ {{- $result := list -}}
38+ {{- $defaultVersion := dict -}}
39+ {{- /* Defining the Default Version in case we need to fall back */ -}}
40+ {{- range $releaseType := $releaseTypes -}}
41+ {{- if eq $releaseType.type "default" -}}
42+ {{- $defaultVersion = $releaseType -}}
43+ {{- end -}}
44+ {{- end -}}
45+ {{- /* We look for the defined releases */ -}}
46+ {{- range $releaseType := $releaseTypes -}}
47+ {{- /* Case 1: If selectors is true, include all group releases */ -}}
48+ {{- if eq $.values.useSelectors "true" -}}
49+ {{- $result = append $result $releaseType -}}
50+ {{- /* Case 2: If group version Release value exists, only include matching releases */ -}}
51+ {{- else if $.values.groupRelease -}}
52+ {{- if or (not $releaseType.type) (eq $releaseType.type $.values.groupRelease) -}}
53+ {{- $result = append $result $releaseType -}}
54+ {{- end -}}
55+ {{- /* Case 3: Default case - include version if it's the default type */ -}}
56+ {{- else -}}
57+ {{- if eq $releaseType.type "default" -}}
58+ {{- $result = append $result $releaseType -}}
59+ {{- end -}}
60+ {{- end -}}
61+ {{- end -}}
62+ {{- /* If no releases were selected, use default */ -}}
63+ {{- if eq (len $result) 0 -}}
64+ {{- $result = append $result $defaultVersion -}}
65+ {{- end -}}
66+ {{ $result | toJson }}
67+ # ##################################################
68+ # base template (everything common)
69+ # ##################################################
70+ template :
71+ metadata :
72+ name : ' cluster-{{.values.applicationSetGroup}}-{{.name}}-{{.type | lower }}'
73+ spec :
74+ project : default
75+ destination :
76+ namespace : argocd
77+ name : ' {{ .name }}'
78+ # syncPolicy is identical for both variants
79+ syncPolicy :
80+ automated :
81+ selfHeal : false
82+ allowEmpty : true
83+ prune : false
84+ retry :
85+ limit : 100
86+ syncOptions :
87+ - CreateNamespace=true
88+ - ServerSideApply=true
89+ # ##################################################
90+ # conditional sources
91+ # ##################################################
92+ templatePatch : |
93+ spec:
94+ sources:
95+ - ref: values
96+ repoURL: '{{ .metadata.annotations.addons_repo_url }}'
97+ targetRevision: '{{ .metadata.annotations.addons_repo_revision }}'
98+ {{- if eq .use_helm_repo_path "false" }}
99+ - repoURL: '{{default .values.chartRepo .chartRepo }}'
100+ chart: '{{ default .values.chartName .ecrChartName }}'
101+ targetRevision: '{{.version}}'
102+ {{- else }}
103+ - repoURL: '{{ .metadata.annotations.addons_repo_url }}'
104+ path: '{{ .values.chartPath }}'
105+ targetRevision: '{{ .metadata.annotations.addons_repo_revision }}'
106+ {{- end }}
107+ helm:
108+ ignoreMissingValueFiles: true
109+ valuesObject:
110+ useSelectors: false
111+ useVersionSelectors: '{{.values.useVersionSelectors}}'
112+ # Defining the way to group addons This application set will handly Addons and ACK values
113+ mergeValues:
114+ addons:
115+ use: true
116+ ack:
117+ use: true
118+ releaseType: '{{.type | lower }}'
119+ # If we are using version selector we add the version of the releases on the matchlabels
120+ {{- if eq .values.useVersionSelectors "true"}}
121+ releases:
122+ {{.values.applicationSetGroup}}Release: '{{.type | lower}}'
123+ {{- end }}
124+ {{- if eq .values.useSelectors "false"}}
125+ globalSelectors:
126+ fleet_member: hub-cluster
127+ {{- end }}
128+ valueFiles:
129+ - defaults/{{.values.applicationSetGroup}}
130+ - clusters/{{`{{ .nameNormalized }}`}}/{{.values.applicationSetGroup}}
131+ valueFiles:
132+ - $values/{{ .metadata.annotations.addons_repo_basepath }}/bootstrap/defaults/{{.values.applicationSetGroup}}.yaml
133+ - $values/{{ .metadata.annotations.addons_repo_basepath }}/{{ .metadata.labels.tenant }}/defaults/{{ .values.chartName }}/{{.values.applicationSetGroup}}.yaml
134+ - $values/{{ .metadata.annotations.addons_repo_basepath }}/{{ .metadata.labels.tenant }}/clusters/{{ .name }}/{{ .values.chartName }}/{{.values.applicationSetGroup}}.yaml
135+ - $values/{{ .metadata.annotations.addons_repo_basepath }}/{{ .metadata.labels.tenant }}/environments/{{ .metadata.labels.environment }}/{{ .values.chartName }}/{{.values.applicationSetGroup}}.yaml
0 commit comments