Skip to content

Commit 79968a5

Browse files
Adding new application set with the use of commonLabels and CommonAnnotations
1 parent 03a4a47 commit 79968a5

17 files changed

+230
-61
lines changed

charts/application-sets/Chart.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ type: application
1515
# This is the chart version. This version number should be incremented each time you make changes
1616
# to the chart and its templates, including the app version.
1717
# Versions are expected to follow Semantic Versioning (https://semver.org/)
18-
version: 0.1.0
18+
version: 0.2.0
1919

2020
# This is the version number of the application being deployed. This version number should be
2121
# incremented each time you make changes to the application. Versions are not expected to
2222
# follow Semantic Versioning. They should reflect the version the application is using.
2323
# It is recommended to use it with quotes.
24-
appVersion: "1.0.0"
24+
appVersion: "1.0.0"

charts/application-sets/templates/_application_set.tpl

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,17 @@ Template to generate additional resources configuration
2525
{{- if $chartConfig.additionalResources.helm }}
2626
helm:
2727
releaseName: '{{`{{ .name }}`}}-{{ $chartConfig.additionalResources.helm.releaseName }}'
28+
{{- if or $values.globalValuesObject $chartConfig.additionalResources.helm.valuesObject }}
29+
{{/* Create a fresh copy for this component only */}}
30+
{{- $chartValuesObject := dict }}
31+
{{- if $values.globalValuesObject }}
32+
{{- $chartValuesObject = deepCopy $values.globalValuesObject }}
33+
{{- end }}
2834
{{- if $chartConfig.additionalResources.helm.valuesObject }}
35+
{{- $chartValuesObject = mergeOverwrite $chartValuesObject $chartConfig.additionalResources.helm.valuesObject }}
36+
{{- end }}
2937
valuesObject:
30-
{{- $chartConfig.additionalResources.helm.valuesObject | toYaml | nindent 6 }}
38+
{{- toYaml $chartValuesObject | nindent 12 }}
3139
{{- end }}
3240
ignoreMissingValueFiles: true
3341
valueFiles:
@@ -39,7 +47,6 @@ Template to generate additional resources configuration
3947
{{- end }}
4048
{{- end }}
4149

42-
4350
{{/*
4451
Define the values path for reusability
4552
*/}}
@@ -49,10 +56,22 @@ Define the values path for reusability
4956
{{- $valueFiles := .valueFiles -}}
5057
{{- $chartType := .chartType -}}
5158
{{- $values := .values -}}
59+
{{- $valuesFileName := default "values.yaml" $chartConfig.valuesFileName -}}
60+
{{- $applicationSetGroup := default "" $values.applicationSetGroup -}}
61+
5262
{{- with .valueFiles }}
5363
{{- range . }}
54-
- $values/{{ $values.repoURLGitBasePath }}/{{ . }}/{{ $nameNormalize }}{{ if $chartType }}/{{ $chartType }}{{ end }}/{{ if $chartConfig.valuesFileName }}{{ $chartConfig.valuesFileName }}{{ else }}values.yaml{{ end }}
55-
- $values/{{ $values.repoURLGitBasePath }}/{{ if $values.useValuesFilePrefix }}{{ $values.valuesFilePrefix }}{{ end }}{{ . }}/{{ $nameNormalize }}{{ if $chartType }}/{{ $chartType }}{{ end }}/{{ if $chartConfig.valuesFileName }}{{ $chartConfig.valuesFileName }}{{ else }}values.yaml{{ end }}
64+
{{/* Path with applicationSetGroup if available */}}
65+
{{- if ne $values.repoURLGitBasePath "" }}
66+
- $values/{{$values.repoURLGitBasePath}}
67+
{{- else}}
68+
- $values{{$values.repoURLGitBasePath}}
69+
{{- end }}
70+
{{- if $values.useValuesFilePrefix -}}/{{$values.valuesFilePrefix}}{{- end -}}/{{.}}
71+
{{- if $applicationSetGroup -}}/{{$applicationSetGroup}}{{- end -}}/{{$nameNormalize}}
72+
{{- if $chartType -}}/{{$chartType}}{{- end -}}
73+
{{- if $chartConfig.valuesFileName -}}/{{$chartConfig.valuesFileName}}
74+
{{- else -}}/values.yaml{{- end -}}
5675
{{- end }}
5776
{{- end }}
5877
{{- end }}

charts/application-sets/templates/_git_matrix.tpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ generators:
2121
{{- if $chartConfig.selectorMatchLabels }}
2222
{{- toYaml $chartConfig.selectorMatchLabels | nindent 18 }}
2323
{{- end }}
24-
{{- if and $chartConfig.selector $useSelectors }}
24+
{{- if and $chartConfig.selector (eq $useSelectors "true") }}
2525
{{- toYaml $chartConfig.selector | nindent 16 }}
2626
{{- end }}
2727
values:

charts/application-sets/templates/_helpers.tpl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ app.kubernetes.io/instance: {{ .Release.Name }}
3535
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
3636
{{- end }}
3737
app.kubernetes.io/managed-by: {{ .Release.Service }}
38+
{{- if .Values.commonLabels }}
39+
{{- toYaml .Values.commonLabels | nindent 0 }}
40+
{{- end }}
3841
{{- end }}
3942

4043
{{/*
@@ -46,3 +49,16 @@ helm.sh/chart: {{ include "application-sets.chart" . }}
4649
{{ toYaml .Values.annotations }}
4750
{{- end }}
4851
{{- end }}
52+
53+
{{/*
54+
Merge common labels from global and chart-specific configurations
55+
Usage: {{ $mergedLabels := include "application-sets.mergeCommonLabels" (dict "global" .Values.commonLabels "chart" $chartConfig.commonLabels) | fromYaml }}
56+
*/}}
57+
{{- define "application-sets.mergeCommon" -}}
58+
{{- $global := .global | default dict }}
59+
{{- $chart := .chart | default dict }}
60+
{{- $merged := mergeOverwrite $global $chart }}
61+
{{- if $merged }}
62+
{{- toYaml $merged }}
63+
{{- end }}
64+
{{- end }}

charts/application-sets/templates/application-set.yaml

Lines changed: 72 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{{/* First, import and merge all values files based on enabled components */}}
22
{{- $values := .Values }}
3-
{{- $releaseType := .Values.releaseType }}
4-
{{- $useVersionSelectors := .Values.useVersionSelectors}}
5-
{{- $useSelectors:= .Values.useSelectors -}}
3+
{{- $releaseName := .Values.releaseName }}
4+
{{- $useVersionSelectors := .Values.useVersionSelectors | toString }}
5+
{{- $useSelectors := .Values.useSelectors | toString -}}
66
{{- $globalSelectors := .Values.globalSelectors -}}
77
{{- $chartType := .Values.chartType }}
88
{{- $namespace := .Values.namespace }}
@@ -13,9 +13,12 @@
1313
{{- $repoURLGitRevision := .Values.repoURLGitRevision -}}
1414
{{- $repoURLGitBasePath := .Values.repoURLGitBasePath -}}
1515
{{- $valueFiles := .Values.valueFiles -}}
16+
{{- $globalValuesObject := .Values.globalValuesObject | default dict -}}
1617
{{- $valuesFilePrefix := .Values.valuesFilePrefix -}}
1718
{{- $useValuesFilePrefix := (default false .Values.useValuesFilePrefix ) -}}
1819
{{- $argoProjectName := (default "default" .Values.argoProjectName ) -}}
20+
{{- $applyNestedSelectors := default "false" .Values.applyNestedSelectors -}}
21+
{{- $templatePatch := .Values.templatePatch -}}
1922

2023
{{/* Merge values From Default */}}
2124
{{- if .Values.mergeValues -}}
@@ -25,14 +28,15 @@
2528
{{- end -}}
2629

2730
{{- range $chartName, $chartConfig := .Values }}
31+
{{- $mergedValuesObject := dict }}
2832
{{- if and (kindIs "map" $chartConfig) (hasKey $chartConfig "enabled") }}
29-
{{- if eq (toString $chartConfig.enabled) "true" }}
33+
{{- if eq ($chartConfig.enabled | toString) "true" }}
3034
{{- $nameNormalize := printf "%s" $chartName | replace "_" "-" | trunc 63 | trimSuffix "-" -}}
3135
apiVersion: argoproj.io/v1alpha1
3236
kind: ApplicationSet
3337
metadata:
34-
{{- if $releaseType }}
35-
name: '{{ $nameNormalize }}-{{$releaseType}}'
38+
{{- if $releaseName }}
39+
name: '{{ $nameNormalize }}-{{$releaseName}}'
3640
{{- else }}
3741
name: {{ $nameNormalize }}
3842
{{- end }}
@@ -45,18 +49,44 @@ metadata:
4549
{{- if $chartConfig.labelsAppSet }}{{- toYaml $chartConfig.labelsAppSet | nindent 4 }}{{- end }}
4650
spec:
4751
goTemplate: true
52+
{{- if $chartConfig.syncPolicyAppSet }}
53+
syncPolicy:
54+
{{- toYaml $chartConfig.syncPolicyAppSet | nindent 4 }}
55+
{{- else }}
56+
syncPolicy:
57+
{{- toYaml $syncPolicyAppSet | nindent 4 }}
58+
{{- end }}
4859
{{- if $chartConfig.goTemplateOptions }}
4960
goTemplateOptions:
5061
{{ toYaml $chartConfig.goTemplateOptions | nindent 2 }}
5162
{{- else }}
5263
goTemplateOptions: {{ default (list "missingkey=error") $goTemplateOptions }}
5364
{{- end }}
54-
{{- if $chartConfig.syncPolicyAppSet }}
55-
syncPolicy:
56-
{{- toYaml $chartConfig.syncPolicyAppSet | nindent 4 }}
65+
{{- if $chartConfig.ignoreApplicationDifferences }}
66+
ignoreApplicationDifferences:
67+
{{- toYaml $chartConfig.ignoreApplicationDifferences | nindent 2 }}
68+
{{- end }}
69+
{{- if $chartConfig.preservedFields }}
70+
preservedFields:
71+
{{- toYaml $chartConfig.preservedFields | nindent 4 }}
72+
{{- end }}
73+
{{- if $chartConfig.strategy }}
74+
strategy:
75+
{{- toYaml $chartConfig.strategy | nindent 4 }}
76+
{{- end }}
77+
{{- if $chartConfig.templatePatch }}
78+
templatePatch: {{- $chartConfig.templatePatch | toYaml | indent 1 }}
5779
{{- else }}
58-
syncPolicy:
59-
{{- toYaml $syncPolicyAppSet | nindent 4 }}
80+
{{- if $templatePatch }}
81+
templatePatch: {{- $templatePatch | toYaml | indent 1 }}
82+
{{- end }}
83+
{{- end }}
84+
{{- if $applyNestedSelectors }}
85+
applyNestedSelectors: {{ $applyNestedSelectors }}
86+
{{- else }}
87+
{{- if $chartConfig.applyNestedSelectors }}
88+
applyNestedSelectors: {{ $chartConfig.applyNestedSelectors }}
89+
{{- end }}
6090
{{- end }}
6191
{{- if $chartConfig.gitMatrix }}
6292
{{ include "application-sets.git-matrix" (dict
@@ -74,7 +104,7 @@ spec:
74104
- clusters:
75105
selector:
76106
matchLabels:
77-
{{- if eq (toString $useVersionSelectors) "true" }}
107+
{{- if eq $useVersionSelectors "true" }}
78108
{{- if $values.releases }}
79109
{{- range $releaseName, $release := $values.releases}}
80110
{{ $releaseName }}: {{ $release }}
@@ -88,20 +118,20 @@ spec:
88118
{{- if $chartConfig.selectorMatchLabels }}
89119
{{- toYaml $chartConfig.selectorMatchLabels | nindent 18 }}
90120
{{- end }}
91-
{{- if and $chartConfig.selector $useSelectors }}
121+
{{- if and $chartConfig.selector (eq $useSelectors "true") }}
92122
{{- toYaml $chartConfig.selector | nindent 16 }}
93123
{{- end }}
94124
{{- if not $chartConfig.resourceGroup }}
95125
values:
96-
addonChart: {{ $chartConfig.chartName | default $nameNormalize | quote }}
126+
chart: {{ $chartConfig.chartName | default $nameNormalize | quote }}
97127
{{- if $chartConfig.defaultVersion }}
98-
addonChartVersion: {{ $chartConfig.defaultVersion | quote }}
128+
chartVersion: {{ $chartConfig.defaultVersion | quote }}
99129
{{- end }}
100130
{{- if $chartConfig.chartRepository }}
101-
addonChartRepository: {{ $chartConfig.chartRepository | quote }}
131+
chartRepository: {{ $chartConfig.chartRepository | quote }}
102132
{{- end }}
103133
{{- if $chartConfig.chartNamespace }}
104-
addonChartRepositoryNamespace: {{ $chartConfig.chartNamespace | quote }}
134+
chartRepositoryNamespace: {{ $chartConfig.chartNamespace | quote }}
105135
chart: {{ printf "%s/%s" $chartConfig.chartNamespace ($chartConfig.chartName | default $nameNormalize) | quote }}
106136
{{- else }}
107137
chart: {{ $chartConfig.chartName | default $nameNormalize | quote }}
@@ -114,24 +144,33 @@ spec:
114144
matchLabels:
115145
{{- toYaml .selector | nindent 18 }}
116146
values:
117-
addonChartVersion: {{ .chartVersion | default $chartConfig.defaultVersion | quote }}
147+
chartVersion: {{ .chartVersion | default $chartConfig.defaultVersion | quote }}
118148
{{- end }}
119149
{{- end }}
120150
{{- end }}
121151
template:
122152
metadata:
123153
{{- if $chartConfig.appSetName }}
124-
name: '{{$releaseType}}-{{ $chartConfig.appSetName }}-{{`{{ .values.addonChartVersion }}`}}'
154+
name: '{{$releaseName}}-{{ $chartConfig.appSetName }}-{{`{{ .values.chartVersion }}`}}'
125155
{{- else }}
126-
name: '{{$releaseType}}-{{`{{ .name | trunc 30 }}`}}-{{ $nameNormalize | trunc 20 }}-{{`{{ .values.addonChartVersion }}`}}'
156+
name: '{{$releaseName}}-{{`{{ .name | trunc 30 }}`}}-{{ $nameNormalize | trunc 20 }}-{{`{{ .values.chartVersion }}`}}'
127157
{{- end }}
158+
annotations:
159+
{{- include "application-sets.annotations" $ | nindent 8 }}
160+
{{- if $chartConfig.annotationsApp }}{{- toYaml $chartConfig.annotationsApp | nindent 8 }}{{- end }}
161+
labels:
162+
{{- include "application-sets.labels" $ | nindent 8 }}
163+
{{- if $chartConfig.labelsApp }}{{- toYaml $chartConfig.labelsApp | nindent 8 }}{{- end }}
164+
component: '{{ $nameNormalize }}'
165+
environment: '{{`{{.metadata.labels.environment}}`}}'
166+
cluster: '{{`{{.name}}`}}'
128167
spec:
129168
project: {{ $argoProjectName }}
130169
sources:
131170
- repoURL: {{ $repoURLGit | squote}}
132171
targetRevision: {{ $repoURLGitRevision | squote }}
133172
ref: values
134-
{{- if eq (toString $chartConfig.enableAckPodIdentity) "true" }}
173+
{{- if eq ($chartConfig.enableAckPodIdentity | toString) "true" }}
135174
{{ include "application-sets.pod-identity" (dict
136175
"chartName" ($chartConfig.chartName | default $nameNormalize)
137176
"valueFiles" $valueFiles
@@ -142,17 +181,25 @@ spec:
142181
path: {{$chartConfig.path | squote }}
143182
targetRevision: {{ $repoURLGitRevision | squote }}
144183
{{- else }}
145-
- repoURL: '{{`{{ .values.addonChartRepository }}`}}'
184+
- repoURL: '{{`{{ .values.chartRepository }}`}}'
146185
chart: '{{`{{ .values.chart }}`}}'
147-
targetRevision: '{{`{{.values.addonChartVersion }}`}}'
186+
targetRevision: '{{`{{.values.chartVersion }}`}}'
148187
{{- end }}
149188
{{- if ne (default "" $chartConfig.type) "manifest" }}
150189
helm:
151-
releaseName: {{ default "{{ .values.addonChart }}" $chartConfig.releaseName | squote }}
190+
releaseName: {{ default "{{ .values.chart }}" $chartConfig.releaseName | squote }}
152191
ignoreMissingValueFiles: true
192+
{{- if or $globalValuesObject $chartConfig.valuesObject }}
193+
{{/* Create a fresh copy for this component only */}}
194+
{{- $chartValuesObject := dict }}
195+
{{- if $globalValuesObject }}
196+
{{- $chartValuesObject = deepCopy $globalValuesObject }}
197+
{{- end }}
153198
{{- if $chartConfig.valuesObject }}
199+
{{- $chartValuesObject = mergeOverwrite $chartValuesObject $chartConfig.valuesObject }}
200+
{{- end }}
154201
valuesObject:
155-
{{- $chartConfig.valuesObject | toYaml | nindent 12 }}
202+
{{- toYaml $chartValuesObject | nindent 12 }}
156203
{{- end }}
157204
{{- if $valueFiles }}
158205
valueFiles:
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Test values for globalValuesObject functionality
2+
globalValuesObject:
3+
commonLabels:
4+
app.kubernetes.io/part-of: "eks-fleet-management"
5+
managed-by: "gitops-fleet-management"
6+
team: "platform"
7+
global-test: "true"
8+
commonAnnotations:
9+
managed-by: "gitops-fleet-management"
10+
global-annotation: "test-value"
11+
12+
# Enable merging from component files
13+
mergeValues:
14+
test:
15+
use: true
16+
17+
# Test components to verify globalValuesObject merging in the values/test.yaml
18+
# Common configuration
19+
syncPolicy:
20+
automated:
21+
selfHeal: true
22+
allowEmpty: true
23+
prune: true
24+
25+
repoURLGit: "https://github.com/test/repo.git"
26+
repoURLGitRevision: "main"
27+
repoURLGitBasePath: "test-path"
28+
valueFiles:
29+
- "defaults"
30+
- "environments/test"
Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
# Common labels to be applied to all ApplicationSet-generated Applications and resources
2+
globalValuesObject:
3+
commonLabels:
4+
app.kubernetes.io/part-of: "eks-fleet-management"
5+
managed-by: "eks-fleet-management"
6+
team: "platform"
7+
commonAnnotations:
8+
managed-by: "eks-fleet-management"
9+
110
syncPolicy:
211
automated:
312
selfHeal: false
@@ -11,22 +20,22 @@ syncPolicy:
1120
maxDuration: 10m # the maximum amount of time allowed for the backoff strategy
1221
syncOptions:
1322
- CreateNamespace=true
14-
- ServerSideApply=true # Big CRDs.
23+
- ServerSideApply=true # Big CRDs.
1524
syncPolicyAppSet:
1625
preserveResourcesOnDeletion: true
17-
repoURLGit: '{{.metadata.annotations.addons_repo_url}}'
18-
repoURLGitRevision: '{{.metadata.annotations.addons_repo_revision}}'
19-
repoURLGitBasePath: '{{.metadata.annotations.addons_repo_basepath}}'
20-
useValuesFilePrefix: true
21-
valuesFilePrefix: '{{.metadata.labels.tenant}}/'
2226
ackPodIdentity:
2327
path: "charts/pod-identity"
2428
# If we Define the Merge we will use the values files included in the folder values. That will enable us to have default helm charts
25-
useSelectors: false
26-
useVersionSelectors: true
27-
# mergeValues:
28-
# fleetBootstrap:
29-
# use: true
29+
useSelectors: "false"
30+
useVersionSelectors: "true"
3031
# globalSelectors:
3132
# fleet_member: spoke
3233
# use_remote_argo: "true"
34+
# Default Values files that will apply to all applciationSets
35+
repoURLGit: "{{.metadata.annotations.addons_repo_url}}"
36+
repoURLGitRevision: "{{.metadata.annotations.addons_repo_revision}}"
37+
repoURLGitBasePath: "{{.metadata.annotations.addons_repo_basepath}}"
38+
valueFiles:
39+
- "{{if .metadata.labels.tenant}}{{.metadata.labels.tenant}}{{end}}/defaults"
40+
- "{{if .metadata.labels.tenant}}{{.metadata.labels.tenant}}{{end}}/environments/{{.metadata.labels.environment}}/defaults"
41+
- "{{if .metadata.labels.tenant}}{{.metadata.labels.tenant}}{{end}}/environments/{{.metadata.labels.environment}}/clusters/{{.name}}"

charts/fleet-secret/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ type: application
1515
# This is the chart version. This version number should be incremented each time you make changes
1616
# to the chart and its templates, including the app version.
1717
# Versions are expected to follow Semantic Versioning (https://semver.org/)
18-
version: 0.1.0
18+
version: 0.2.0
1919

2020
# This is the version number of the application being deployed. This version number should be
2121
# incremented each time you make changes to the application. Versions are not expected to
-27.6 KB
Binary file not shown.
-8.81 KB
Binary file not shown.

0 commit comments

Comments
 (0)