/
configmap.go
670 lines (578 loc) · 22.5 KB
/
configmap.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
// Copyright 2019 ArgoCD Operator Developers
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package argocd
import (
"context"
"fmt"
"reflect"
"gopkg.in/yaml.v2"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
argoproj "github.com/argoproj-labs/argocd-operator/api/v1beta1"
"github.com/argoproj-labs/argocd-operator/common"
"github.com/argoproj-labs/argocd-operator/controllers/argoutil"
)
// createRBACConfigMap will create the Argo CD RBAC ConfigMap resource.
func (r *ReconcileArgoCD) createRBACConfigMap(cm *corev1.ConfigMap, cr *argoproj.ArgoCD) error {
data := make(map[string]string)
data[common.ArgoCDKeyRBACPolicyCSV] = getRBACPolicy(cr)
data[common.ArgoCDKeyRBACPolicyDefault] = getRBACDefaultPolicy(cr)
data[common.ArgoCDKeyRBACScopes] = getRBACScopes(cr)
cm.Data = data
if err := controllerutil.SetControllerReference(cr, cm, r.Scheme); err != nil {
return err
}
return r.Client.Create(context.TODO(), cm)
}
// getApplicationInstanceLabelKey will return the application instance label key for the given ArgoCD.
func getApplicationInstanceLabelKey(cr *argoproj.ArgoCD) string {
key := common.ArgoCDDefaultApplicationInstanceLabelKey
if len(cr.Spec.ApplicationInstanceLabelKey) > 0 {
key = cr.Spec.ApplicationInstanceLabelKey
}
return key
}
// getCAConfigMapName will return the CA ConfigMap name for the given ArgoCD.
func getCAConfigMapName(cr *argoproj.ArgoCD) string {
if len(cr.Spec.TLS.CA.ConfigMapName) > 0 {
return cr.Spec.TLS.CA.ConfigMapName
}
return nameWithSuffix(common.ArgoCDCASuffix, cr)
}
// getSCMRootCAConfigMapName will return the SCMRootCA ConfigMap name for the given ArgoCD ApplicationSet Controller.
func getSCMRootCAConfigMapName(cr *argoproj.ArgoCD) string {
if cr.Spec.ApplicationSet.SCMRootCAConfigMap != "" && len(cr.Spec.ApplicationSet.SCMRootCAConfigMap) > 0 {
return cr.Spec.ApplicationSet.SCMRootCAConfigMap
}
return ""
}
// getConfigManagementPlugins will return the config management plugins for the given ArgoCD.
func getConfigManagementPlugins(cr *argoproj.ArgoCD) string {
plugins := common.ArgoCDDefaultConfigManagementPlugins
if len(cr.Spec.ConfigManagementPlugins) > 0 {
plugins = cr.Spec.ConfigManagementPlugins
}
return plugins
}
// getGATrackingID will return the google analytics tracking ID for the given Argo CD.
func getGATrackingID(cr *argoproj.ArgoCD) string {
id := common.ArgoCDDefaultGATrackingID
if len(cr.Spec.GATrackingID) > 0 {
id = cr.Spec.GATrackingID
}
return id
}
// getHelpChatURL will return the help chat URL for the given Argo CD.
func getHelpChatURL(cr *argoproj.ArgoCD) string {
url := common.ArgoCDDefaultHelpChatURL
if len(cr.Spec.HelpChatURL) > 0 {
url = cr.Spec.HelpChatURL
}
return url
}
// getHelpChatText will return the help chat text for the given Argo CD.
func getHelpChatText(cr *argoproj.ArgoCD) string {
text := common.ArgoCDDefaultHelpChatText
if len(cr.Spec.HelpChatText) > 0 {
text = cr.Spec.HelpChatText
}
return text
}
// getKustomizeBuildOptions will return the kuztomize build options for the given ArgoCD.
func getKustomizeBuildOptions(cr *argoproj.ArgoCD) string {
kbo := common.ArgoCDDefaultKustomizeBuildOptions
if len(cr.Spec.KustomizeBuildOptions) > 0 {
kbo = cr.Spec.KustomizeBuildOptions
}
return kbo
}
// getOIDCConfig will return the OIDC configuration for the given ArgoCD.
func getOIDCConfig(cr *argoproj.ArgoCD) string {
config := common.ArgoCDDefaultOIDCConfig
if len(cr.Spec.OIDCConfig) > 0 {
config = cr.Spec.OIDCConfig
}
return config
}
// getRBACPolicy will return the RBAC policy for the given ArgoCD.
func getRBACPolicy(cr *argoproj.ArgoCD) string {
policy := common.ArgoCDDefaultRBACPolicy
if cr.Spec.RBAC.Policy != nil {
policy = *cr.Spec.RBAC.Policy
}
return policy
}
// getRBACDefaultPolicy will retun the RBAC default policy for the given ArgoCD.
func getRBACDefaultPolicy(cr *argoproj.ArgoCD) string {
dp := common.ArgoCDDefaultRBACDefaultPolicy
if cr.Spec.RBAC.DefaultPolicy != nil {
dp = *cr.Spec.RBAC.DefaultPolicy
}
return dp
}
// getRBACScopes will return the RBAC scopes for the given ArgoCD.
func getRBACScopes(cr *argoproj.ArgoCD) string {
scopes := common.ArgoCDDefaultRBACScopes
if cr.Spec.RBAC.Scopes != nil {
scopes = *cr.Spec.RBAC.Scopes
}
return scopes
}
// getResourceHealthChecks loads health customizations to `resource.customizations.health` from argocd-cm ConfigMap
func getResourceHealthChecks(cr *argoproj.ArgoCD) map[string]string {
healthCheck := make(map[string]string)
if cr.Spec.ResourceHealthChecks != nil {
resourceHealthChecks := cr.Spec.ResourceHealthChecks
for _, healthCustomization := range resourceHealthChecks {
if healthCustomization.Group != "" {
healthCustomization.Group += "_"
}
subkey := "resource.customizations.health." + healthCustomization.Group + healthCustomization.Kind
subvalue := healthCustomization.Check
healthCheck[subkey] = subvalue
}
}
return healthCheck
}
// getResourceIgnoreDifferences loads ignore differences customizations to `resource.customizations.ignoreDifferences` from argocd-cm ConfigMap
func getResourceIgnoreDifferences(cr *argoproj.ArgoCD) (map[string]string, error) {
ignoreDiff := make(map[string]string)
if cr.Spec.ResourceIgnoreDifferences != nil {
resourceIgnoreDiff := cr.Spec.ResourceIgnoreDifferences
if !reflect.DeepEqual(resourceIgnoreDiff.All, &argoproj.IgnoreDifferenceCustomization{}) {
subkey := "resource.customizations.ignoreDifferences.all"
bytes, err := yaml.Marshal(resourceIgnoreDiff.All)
if err != nil {
return ignoreDiff, err
}
subvalue := string(bytes)
ignoreDiff[subkey] = subvalue
}
for _, ignoreDiffCustomization := range resourceIgnoreDiff.ResourceIdentifiers {
if ignoreDiffCustomization.Group != "" {
ignoreDiffCustomization.Group += "_"
}
subkey := "resource.customizations.ignoreDifferences." + ignoreDiffCustomization.Group + ignoreDiffCustomization.Kind
bytes, err := yaml.Marshal(ignoreDiffCustomization.Customization)
if err != nil {
return ignoreDiff, err
}
subvalue := string(bytes)
ignoreDiff[subkey] = subvalue
}
}
return ignoreDiff, nil
}
// getResourceActions loads custom actions to `resource.customizations.actions` from argocd-cm ConfigMap
func getResourceActions(cr *argoproj.ArgoCD) map[string]string {
action := make(map[string]string)
if cr.Spec.ResourceActions != nil {
resourceAction := cr.Spec.ResourceActions
for _, actionCustomization := range resourceAction {
if actionCustomization.Group != "" {
actionCustomization.Group += "_"
}
subkey := "resource.customizations.actions." + actionCustomization.Group + actionCustomization.Kind
subvalue := actionCustomization.Action
action[subkey] = subvalue
}
}
return action
}
// getResourceExclusions will return the resource exclusions for the given ArgoCD.
func getResourceExclusions(cr *argoproj.ArgoCD) string {
re := common.ArgoCDDefaultResourceExclusions
if cr.Spec.ResourceExclusions != "" {
re = cr.Spec.ResourceExclusions
}
return re
}
// getResourceInclusions will return the resource inclusions for the given ArgoCD.
func getResourceInclusions(cr *argoproj.ArgoCD) string {
re := common.ArgoCDDefaultResourceInclusions
if cr.Spec.ResourceInclusions != "" {
re = cr.Spec.ResourceInclusions
}
return re
}
// getResourceTrackingMethod will return the resource tracking method for the given ArgoCD.
func getResourceTrackingMethod(cr *argoproj.ArgoCD) string {
rtm := argoproj.ParseResourceTrackingMethod(cr.Spec.ResourceTrackingMethod)
if rtm == argoproj.ResourceTrackingMethodInvalid {
log.Info(fmt.Sprintf("Found '%s' as resource tracking method, which is invalid. Using default 'label' method.", cr.Spec.ResourceTrackingMethod))
} else if cr.Spec.ResourceTrackingMethod != "" {
log.Info(fmt.Sprintf("Found '%s' as tracking method", cr.Spec.ResourceTrackingMethod))
} else {
log.Info("Using default resource tracking method 'label'")
}
return rtm.String()
}
// getInitialRepositories will return the initial repositories for the given ArgoCD.
func getInitialRepositories(cr *argoproj.ArgoCD) string {
repos := common.ArgoCDDefaultRepositories
if len(cr.Spec.InitialRepositories) > 0 {
repos = cr.Spec.InitialRepositories
}
return repos
}
// getRepositoryCredentials will return the repository credentials for the given ArgoCD.
func getRepositoryCredentials(cr *argoproj.ArgoCD) string {
repos := common.ArgoCDDefaultRepositoryCredentials
if len(cr.Spec.RepositoryCredentials) > 0 {
repos = cr.Spec.RepositoryCredentials
}
return repos
}
// getSSHKnownHosts will return the SSH Known Hosts data for the given ArgoCD.
func getInitialSSHKnownHosts(cr *argoproj.ArgoCD) string {
skh := common.ArgoCDDefaultSSHKnownHosts
if cr.Spec.InitialSSHKnownHosts.ExcludeDefaultHosts {
skh = ""
}
if len(cr.Spec.InitialSSHKnownHosts.Keys) > 0 {
skh += cr.Spec.InitialSSHKnownHosts.Keys
}
return skh
}
// getTLSCerts will return the TLS certs for the given ArgoCD.
func getInitialTLSCerts(cr *argoproj.ArgoCD) map[string]string {
certs := make(map[string]string)
if len(cr.Spec.TLS.InitialCerts) > 0 {
certs = cr.Spec.TLS.InitialCerts
}
return certs
}
// newConfigMap returns a new ConfigMap instance for the given ArgoCD.
func newConfigMap(cr *argoproj.ArgoCD) *corev1.ConfigMap {
return &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: cr.Name,
Namespace: cr.Namespace,
Labels: argoutil.LabelsForCluster(cr),
},
}
}
// newConfigMapWithName creates a new ConfigMap with the given name for the given ArgCD.
func newConfigMapWithName(name string, cr *argoproj.ArgoCD) *corev1.ConfigMap {
cm := newConfigMap(cr)
cm.ObjectMeta.Name = name
lbls := cm.ObjectMeta.Labels
lbls[common.ArgoCDKeyName] = name
cm.ObjectMeta.Labels = lbls
return cm
}
// reconcileConfigMaps will ensure that all ArgoCD ConfigMaps are present.
func (r *ReconcileArgoCD) reconcileConfigMaps(cr *argoproj.ArgoCD, useTLSForRedis bool) error {
if err := r.reconcileArgoConfigMap(cr); err != nil {
return err
}
if err := r.reconcileRedisConfiguration(cr, useTLSForRedis); err != nil {
return err
}
if err := r.reconcileRBAC(cr); err != nil {
return err
}
if err := r.reconcileSSHKnownHosts(cr); err != nil {
return err
}
if err := r.reconcileTLSCerts(cr); err != nil {
return err
}
if err := r.reconcileGrafanaConfiguration(cr); err != nil {
return err
}
if err := r.reconcileGrafanaDashboards(cr); err != nil {
return err
}
return r.reconcileGPGKeysConfigMap(cr)
}
// reconcileCAConfigMap will ensure that the Certificate Authority ConfigMap is present.
// This ConfigMap holds the CA Certificate data for client use.
func (r *ReconcileArgoCD) reconcileCAConfigMap(cr *argoproj.ArgoCD) error {
cm := newConfigMapWithName(getCAConfigMapName(cr), cr)
if argoutil.IsObjectFound(r.Client, cr.Namespace, cm.Name, cm) {
return nil // ConfigMap found, do nothing
}
caSecret := argoutil.NewSecretWithSuffix(cr, common.ArgoCDCASuffix)
if !argoutil.IsObjectFound(r.Client, cr.Namespace, caSecret.Name, caSecret) {
log.Info(fmt.Sprintf("ca secret [%s] not found, waiting to reconcile ca configmap [%s]", caSecret.Name, cm.Name))
return nil
}
cm.Data = map[string]string{
common.ArgoCDKeyTLSCert: string(caSecret.Data[common.ArgoCDKeyTLSCert]),
}
if err := controllerutil.SetControllerReference(cr, cm, r.Scheme); err != nil {
return err
}
return r.Client.Create(context.TODO(), cm)
}
// reconcileConfiguration will ensure that the main ConfigMap for ArgoCD is present.
func (r *ReconcileArgoCD) reconcileArgoConfigMap(cr *argoproj.ArgoCD) error {
cm := newConfigMapWithName(common.ArgoCDConfigMapName, cr)
cm.Data = make(map[string]string)
cm.Data[common.ArgoCDKeyApplicationInstanceLabelKey] = getApplicationInstanceLabelKey(cr)
cm.Data[common.ArgoCDKeyConfigManagementPlugins] = getConfigManagementPlugins(cr)
cm.Data[common.ArgoCDKeyAdminEnabled] = fmt.Sprintf("%t", !cr.Spec.DisableAdmin)
cm.Data[common.ArgoCDKeyGATrackingID] = getGATrackingID(cr)
cm.Data[common.ArgoCDKeyGAAnonymizeUsers] = fmt.Sprint(cr.Spec.GAAnonymizeUsers)
cm.Data[common.ArgoCDKeyHelpChatURL] = getHelpChatURL(cr)
cm.Data[common.ArgoCDKeyHelpChatText] = getHelpChatText(cr)
cm.Data[common.ArgoCDKeyKustomizeBuildOptions] = getKustomizeBuildOptions(cr)
if len(cr.Spec.KustomizeVersions) > 0 {
for _, kv := range cr.Spec.KustomizeVersions {
cm.Data["kustomize.version."+kv.Version] = kv.Path
}
}
cm.Data[common.ArgoCDKeyOIDCConfig] = getOIDCConfig(cr)
if c := getResourceHealthChecks(cr); c != nil {
for k, v := range c {
cm.Data[k] = v
}
}
if c, err := getResourceIgnoreDifferences(cr); c != nil && err == nil {
for k, v := range c {
cm.Data[k] = v
}
} else {
return err
}
if c := getResourceActions(cr); c != nil {
for k, v := range c {
cm.Data[k] = v
}
}
cm.Data[common.ArgoCDKeyResourceExclusions] = getResourceExclusions(cr)
cm.Data[common.ArgoCDKeyResourceInclusions] = getResourceInclusions(cr)
cm.Data[common.ArgoCDKeyResourceTrackingMethod] = getResourceTrackingMethod(cr)
cm.Data[common.ArgoCDKeyRepositories] = getInitialRepositories(cr)
cm.Data[common.ArgoCDKeyRepositoryCredentials] = getRepositoryCredentials(cr)
cm.Data[common.ArgoCDKeyStatusBadgeEnabled] = fmt.Sprint(cr.Spec.StatusBadgeEnabled)
cm.Data[common.ArgoCDKeyServerURL] = r.getArgoServerURI(cr)
cm.Data[common.ArgoCDKeyUsersAnonymousEnabled] = fmt.Sprint(cr.Spec.UsersAnonymousEnabled)
// create dex config if dex is enabled through `.spec.sso`
if UseDex(cr) {
dexConfig := getDexConfig(cr)
// Append the default OpenShift dex config if the openShiftOAuth is requested through `.spec.sso.dex`.
if cr.Spec.SSO != nil && cr.Spec.SSO.Dex != nil && cr.Spec.SSO.Dex.OpenShiftOAuth {
cfg, err := r.getOpenShiftDexConfig(cr)
if err != nil {
return err
}
dexConfig = cfg
}
cm.Data[common.ArgoCDKeyDexConfig] = dexConfig
}
if cr.Spec.Banner != nil {
if cr.Spec.Banner.Content != "" {
cm.Data[common.ArgoCDKeyBannerContent] = cr.Spec.Banner.Content
if cr.Spec.Banner.URL != "" {
cm.Data[common.ArgoCDKeyBannerURL] = cr.Spec.Banner.URL
}
}
}
if len(cr.Spec.ExtraConfig) > 0 {
for k, v := range cr.Spec.ExtraConfig {
cm.Data[k] = v
}
}
if err := controllerutil.SetControllerReference(cr, cm, r.Scheme); err != nil {
return err
}
existingCM := &corev1.ConfigMap{}
if argoutil.IsObjectFound(r.Client, cr.Namespace, cm.Name, existingCM) {
// reconcile dex configuration if dex is enabled `.spec.sso.dex.provider` or there is
// existing dex configuration
if UseDex(cr) {
if err := r.reconcileDexConfiguration(existingCM, cr); err != nil {
return err
}
} else if cr.Spec.SSO != nil && cr.Spec.SSO.Provider.ToLower() == argoproj.SSOProviderTypeKeycloak {
// retain oidc.config during reconcilliation when keycloak is configured
cm.Data[common.ArgoCDKeyOIDCConfig] = existingCM.Data[common.ArgoCDKeyOIDCConfig]
}
if !reflect.DeepEqual(cm.Data, existingCM.Data) {
existingCM.Data = cm.Data
return r.Client.Update(context.TODO(), existingCM)
}
return nil // Do nothing as there is no change in the configmap.
}
return r.Client.Create(context.TODO(), cm)
}
// reconcileGrafanaConfiguration will ensure that the Grafana configuration ConfigMap is present.
func (r *ReconcileArgoCD) reconcileGrafanaConfiguration(cr *argoproj.ArgoCD) error {
if !cr.Spec.Grafana.Enabled {
return nil // Grafana not enabled, do nothing.
}
log.Info(grafanaDeprecatedWarning)
return nil
}
// reconcileGrafanaDashboards will ensure that the Grafana dashboards ConfigMap is present.
func (r *ReconcileArgoCD) reconcileGrafanaDashboards(cr *argoproj.ArgoCD) error {
if !cr.Spec.Grafana.Enabled {
return nil // Grafana not enabled, do nothing.
}
log.Info(grafanaDeprecatedWarning)
return nil
}
// reconcileRBAC will ensure that the ArgoCD RBAC ConfigMap is present.
func (r *ReconcileArgoCD) reconcileRBAC(cr *argoproj.ArgoCD) error {
cm := newConfigMapWithName(common.ArgoCDRBACConfigMapName, cr)
if argoutil.IsObjectFound(r.Client, cr.Namespace, cm.Name, cm) {
return r.reconcileRBACConfigMap(cm, cr)
}
return r.createRBACConfigMap(cm, cr)
}
// reconcileRBACConfigMap will ensure that the RBAC ConfigMap is syncronized with the given ArgoCD.
func (r *ReconcileArgoCD) reconcileRBACConfigMap(cm *corev1.ConfigMap, cr *argoproj.ArgoCD) error {
changed := false
// Policy CSV
if cr.Spec.RBAC.Policy != nil && cm.Data[common.ArgoCDKeyRBACPolicyCSV] != *cr.Spec.RBAC.Policy {
cm.Data[common.ArgoCDKeyRBACPolicyCSV] = *cr.Spec.RBAC.Policy
changed = true
}
// Default Policy
if cr.Spec.RBAC.DefaultPolicy != nil && cm.Data[common.ArgoCDKeyRBACPolicyDefault] != *cr.Spec.RBAC.DefaultPolicy {
cm.Data[common.ArgoCDKeyRBACPolicyDefault] = *cr.Spec.RBAC.DefaultPolicy
changed = true
}
// Default Policy Matcher Mode
if cr.Spec.RBAC.PolicyMatcherMode != nil && cm.Data[common.ArgoCDPolicyMatcherMode] != *cr.Spec.RBAC.PolicyMatcherMode {
cm.Data[common.ArgoCDPolicyMatcherMode] = *cr.Spec.RBAC.PolicyMatcherMode
changed = true
}
// Scopes
if cr.Spec.RBAC.Scopes != nil && cm.Data[common.ArgoCDKeyRBACScopes] != *cr.Spec.RBAC.Scopes {
cm.Data[common.ArgoCDKeyRBACScopes] = *cr.Spec.RBAC.Scopes
changed = true
}
if changed {
// TODO: Reload server (and dex?) if RBAC settings change?
return r.Client.Update(context.TODO(), cm)
}
return nil // ConfigMap exists and nothing to do, move along...
}
// reconcileRedisConfiguration will ensure that all of the Redis ConfigMaps are present for the given ArgoCD.
func (r *ReconcileArgoCD) reconcileRedisConfiguration(cr *argoproj.ArgoCD, useTLSForRedis bool) error {
if err := r.reconcileRedisHAConfigMap(cr, useTLSForRedis); err != nil {
return err
}
if err := r.reconcileRedisHAHealthConfigMap(cr, useTLSForRedis); err != nil {
return err
}
return nil
}
// reconcileRedisHAConfigMap will ensure that the Redis HA Health ConfigMap is present for the given ArgoCD.
func (r *ReconcileArgoCD) reconcileRedisHAHealthConfigMap(cr *argoproj.ArgoCD, useTLSForRedis bool) error {
cm := newConfigMapWithName(common.ArgoCDRedisHAHealthConfigMapName, cr)
if argoutil.IsObjectFound(r.Client, cr.Namespace, cm.Name, cm) {
if !cr.Spec.HA.Enabled {
// ConfigMap exists but HA enabled flag has been set to false, delete the ConfigMap
return r.Client.Delete(context.TODO(), cm)
}
return nil // ConfigMap found with nothing changed, move along...
}
if !cr.Spec.HA.Enabled {
return nil // HA not enabled, do nothing.
}
cm.Data = map[string]string{
"redis_liveness.sh": getRedisLivenessScript(useTLSForRedis),
"redis_readiness.sh": getRedisReadinessScript(useTLSForRedis),
"sentinel_liveness.sh": getSentinelLivenessScript(useTLSForRedis),
}
if err := controllerutil.SetControllerReference(cr, cm, r.Scheme); err != nil {
return err
}
return r.Client.Create(context.TODO(), cm)
}
// reconcileRedisHAConfigMap will ensure that the Redis HA ConfigMap is present for the given ArgoCD.
func (r *ReconcileArgoCD) reconcileRedisHAConfigMap(cr *argoproj.ArgoCD, useTLSForRedis bool) error {
cm := newConfigMapWithName(common.ArgoCDRedisHAConfigMapName, cr)
if argoutil.IsObjectFound(r.Client, cr.Namespace, cm.Name, cm) {
if !cr.Spec.HA.Enabled {
// ConfigMap exists but HA enabled flag has been set to false, delete the ConfigMap
return r.Client.Delete(context.TODO(), cm)
}
return nil // ConfigMap found with nothing changed, move along...
}
if !cr.Spec.HA.Enabled {
return nil // HA not enabled, do nothing.
}
cm.Data = map[string]string{
"haproxy.cfg": getRedisHAProxyConfig(cr, useTLSForRedis),
"haproxy_init.sh": getRedisHAProxyScript(cr),
"init.sh": getRedisInitScript(cr, useTLSForRedis),
"redis.conf": getRedisConf(useTLSForRedis),
"sentinel.conf": getRedisSentinelConf(useTLSForRedis),
}
if err := controllerutil.SetControllerReference(cr, cm, r.Scheme); err != nil {
return err
}
return r.Client.Create(context.TODO(), cm)
}
func (r *ReconcileArgoCD) recreateRedisHAConfigMap(cr *argoproj.ArgoCD, useTLSForRedis bool) error {
cm := newConfigMapWithName(common.ArgoCDRedisHAConfigMapName, cr)
if argoutil.IsObjectFound(r.Client, cr.Namespace, cm.Name, cm) {
if err := r.Client.Delete(context.TODO(), cm); err != nil {
return err
}
}
return r.reconcileRedisHAConfigMap(cr, useTLSForRedis)
}
func (r *ReconcileArgoCD) recreateRedisHAHealthConfigMap(cr *argoproj.ArgoCD, useTLSForRedis bool) error {
cm := newConfigMapWithName(common.ArgoCDRedisHAHealthConfigMapName, cr)
if argoutil.IsObjectFound(r.Client, cr.Namespace, cm.Name, cm) {
if err := r.Client.Delete(context.TODO(), cm); err != nil {
return err
}
}
return r.reconcileRedisHAHealthConfigMap(cr, useTLSForRedis)
}
// reconcileSSHKnownHosts will ensure that the ArgoCD SSH Known Hosts ConfigMap is present.
func (r *ReconcileArgoCD) reconcileSSHKnownHosts(cr *argoproj.ArgoCD) error {
cm := newConfigMapWithName(common.ArgoCDKnownHostsConfigMapName, cr)
if argoutil.IsObjectFound(r.Client, cr.Namespace, cm.Name, cm) {
return nil // ConfigMap found, move along...
}
cm.Data = map[string]string{
common.ArgoCDKeySSHKnownHosts: getInitialSSHKnownHosts(cr),
}
if err := controllerutil.SetControllerReference(cr, cm, r.Scheme); err != nil {
return err
}
return r.Client.Create(context.TODO(), cm)
}
// reconcileTLSCerts will ensure that the ArgoCD TLS Certs ConfigMap is present.
func (r *ReconcileArgoCD) reconcileTLSCerts(cr *argoproj.ArgoCD) error {
cm := newConfigMapWithName(common.ArgoCDTLSCertsConfigMapName, cr)
if argoutil.IsObjectFound(r.Client, cr.Namespace, cm.Name, cm) {
return nil // ConfigMap found, move along...
}
cm.Data = getInitialTLSCerts(cr)
if err := controllerutil.SetControllerReference(cr, cm, r.Scheme); err != nil {
return err
}
return r.Client.Create(context.TODO(), cm)
}
// reconcileGPGKeysConfigMap creates a gpg-keys config map
func (r *ReconcileArgoCD) reconcileGPGKeysConfigMap(cr *argoproj.ArgoCD) error {
cm := newConfigMapWithName(common.ArgoCDGPGKeysConfigMapName, cr)
if argoutil.IsObjectFound(r.Client, cr.Namespace, cm.Name, cm) {
return nil
}
if err := controllerutil.SetControllerReference(cr, cm, r.Scheme); err != nil {
return err
}
return r.Client.Create(context.TODO(), cm)
}