Skip to content

Commit c484a31

Browse files
committed
Add default health value in CM to get Health status in the Application CR
1 parent e22ccbf commit c484a31

File tree

10 files changed

+146
-15
lines changed

10 files changed

+146
-15
lines changed

controllers/argocd/configmap.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -800,20 +800,17 @@ func (r *ReconcileArgoCD) reconcileArgoCmdParamsConfigMap(cr *argoproj.ArgoCD) e
800800
cm := newConfigMapWithName(common.ArgoCDCmdParamsConfigMapName, cr)
801801
cm.Data = make(map[string]string)
802802

803+
// Set default for controller.resource.health.persist to "true"
804+
const healthPersistKey = "controller.resource.health.persist"
805+
cm.Data[healthPersistKey] = "true"
806+
803807
// Copy user-specified command parameters if any
804808
if len(cr.Spec.CmdParams) > 0 {
805809
for k, v := range cr.Spec.CmdParams {
806810
cm.Data[k] = v
807811
}
808812
}
809813

810-
// Set default for controller.resource.health.persist to "true"
811-
// only if user hasn't provided it explicitly
812-
const healthPersistKey = "controller.resource.health.persist"
813-
if _, exists := cm.Data[healthPersistKey]; !exists {
814-
cm.Data[healthPersistKey] = "true"
815-
}
816-
817814
if err := controllerutil.SetControllerReference(cr, cm, r.Scheme); err != nil {
818815
return err
819816
}

controllers/argocd/configmap_test.go

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1537,3 +1537,66 @@ func TestReconcileArgoCD_RemovesLegacyLogEnforceFlag(t *testing.T) {
15371537
_, exists := updated.Data["server.rbac.log.enforce.enable"]
15381538
assert.False(t, exists, "expected deprecated key to be removed")
15391539
}
1540+
1541+
func TestReconcileArgoCD_reconcileArgoCmdParamsConfigMap(t *testing.T) {
1542+
logf.SetLogger(ZapLogger(true))
1543+
1544+
tests := []struct {
1545+
name string
1546+
cmdParams map[string]string
1547+
expectedValue string
1548+
expectKeyExist bool
1549+
}{
1550+
{
1551+
name: "No user-specified CmdParams",
1552+
cmdParams: nil,
1553+
expectedValue: "true",
1554+
expectKeyExist: true,
1555+
},
1556+
{
1557+
name: "User-specified CmdParams without health.persist",
1558+
cmdParams: map[string]string{
1559+
"some.other.param": "value",
1560+
},
1561+
expectedValue: "true",
1562+
expectKeyExist: true,
1563+
},
1564+
{
1565+
name: "User overrides health.persist to false",
1566+
cmdParams: map[string]string{
1567+
"controller.resource.health.persist": "false",
1568+
},
1569+
expectedValue: "false",
1570+
expectKeyExist: true,
1571+
},
1572+
}
1573+
1574+
for _, test := range tests {
1575+
t.Run(test.name, func(t *testing.T) {
1576+
a := makeTestArgoCD(func(a *argoproj.ArgoCD) {
1577+
a.Spec.CmdParams = test.cmdParams
1578+
})
1579+
1580+
resObjs := []client.Object{a}
1581+
subresObjs := []client.Object{a}
1582+
runtimeObjs := []runtime.Object{}
1583+
sch := makeTestReconcilerScheme(argoproj.AddToScheme)
1584+
cl := makeTestReconcilerClient(sch, resObjs, subresObjs, runtimeObjs)
1585+
r := makeTestReconciler(cl, sch)
1586+
1587+
err := r.reconcileArgoCmdParamsConfigMap(a)
1588+
assert.NoError(t, err)
1589+
1590+
cm := &corev1.ConfigMap{}
1591+
err = r.Client.Get(context.TODO(), types.NamespacedName{
1592+
Name: common.ArgoCDCmdParamsConfigMapName,
1593+
Namespace: testNamespace,
1594+
}, cm)
1595+
assert.NoError(t, err)
1596+
1597+
val, exists := cm.Data["controller.resource.health.persist"]
1598+
assert.Equal(t, test.expectKeyExist, exists, "Expected key existence mismatesth")
1599+
assert.Equal(t, test.expectedValue, val, "Expected value mismatch")
1600+
})
1601+
}
1602+
}

controllers/argocd/statefulset.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ import (
2121
"strconv"
2222
"time"
2323

24-
"k8s.io/utils/pointer"
25-
2624
appsv1 "k8s.io/api/apps/v1"
2725
corev1 "k8s.io/api/core/v1"
2826
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -613,8 +611,7 @@ func getArgoControllerContainerEnv(cr *argoproj.ArgoCD, replicas int32) []corev1
613611
LocalObjectReference: corev1.LocalObjectReference{
614612
Name: common.ArgoCDCmdParamsConfigMapName,
615613
},
616-
Key: "controller.resource.health.persist",
617-
Optional: pointer.Bool(true),
614+
Key: "controller.resource.health.persist",
618615
},
619616
},
620617
},

controllers/argocd/statefulset_test.go

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ func controllerDefaultVolumes() []corev1.Volume {
7272
Key: "controller.profile.enabled",
7373
Path: "profiler.enabled",
7474
},
75+
{
76+
Key: "controller.resource.health.persist",
77+
Path: "controller.resource.health.persist",
78+
},
7579
},
7680
},
7781
},
@@ -208,7 +212,9 @@ func TestReconcileArgoCD_reconcileApplicationController(t *testing.T) {
208212
"--status-processors", "20",
209213
"--kubectl-parallelism-limit", "10",
210214
"--loglevel", "info",
211-
"--logformat", "text"}
215+
"--logformat", "text",
216+
"--persist-resource-health",
217+
}
212218
if diff := cmp.Diff(want, command); diff != "" {
213219
t.Fatalf("reconciliation failed:\n%s", diff)
214220
}
@@ -254,7 +260,8 @@ func TestReconcileArgoCD_reconcileApplicationController_withRedisTLS(t *testing.
254260
"--status-processors", "20",
255261
"--kubectl-parallelism-limit", "10",
256262
"--loglevel", "info",
257-
"--logformat", "text"}
263+
"--logformat", "text",
264+
"--persist-resource-health"}
258265
if diff := cmp.Diff(want, command); diff != "" {
259266
t.Fatalf("reconciliation failed:\n%s", diff)
260267
}
@@ -293,7 +300,8 @@ func TestReconcileArgoCD_reconcileApplicationController_withUpdate(t *testing.T)
293300
"--status-processors", "30",
294301
"--kubectl-parallelism-limit", "10",
295302
"--loglevel", "info",
296-
"--logformat", "text"}
303+
"--logformat", "text",
304+
"--persist-resource-health"}
297305
if diff := cmp.Diff(want, command); diff != "" {
298306
t.Fatalf("reconciliation failed:\n%s", diff)
299307
}
@@ -401,6 +409,12 @@ func TestReconcileArgoCD_reconcileApplicationController_withSharding(t *testing.
401409
},
402410
replicas: 1,
403411
vars: []corev1.EnvVar{
412+
{Name: "ARGOCD_CONTROLLER_RESOURCE_HEALTH_PERSIST", ValueFrom: &corev1.EnvVarSource{
413+
ConfigMapKeyRef: &corev1.ConfigMapKeySelector{
414+
LocalObjectReference: corev1.LocalObjectReference{Name: common.ArgoCDCmdParamsConfigMapName},
415+
Key: "controller.resource.health.persist",
416+
},
417+
}},
404418
{Name: "HOME", Value: "/home/argocd"},
405419
{Name: "REDIS_PASSWORD", Value: "",
406420
ValueFrom: &corev1.EnvVarSource{
@@ -421,6 +435,12 @@ func TestReconcileArgoCD_reconcileApplicationController_withSharding(t *testing.
421435
replicas: 1,
422436
vars: []corev1.EnvVar{
423437
{Name: "ARGOCD_CONTROLLER_REPLICAS", Value: "1"},
438+
{Name: "ARGOCD_CONTROLLER_RESOURCE_HEALTH_PERSIST", ValueFrom: &corev1.EnvVarSource{
439+
ConfigMapKeyRef: &corev1.ConfigMapKeySelector{
440+
LocalObjectReference: corev1.LocalObjectReference{Name: common.ArgoCDCmdParamsConfigMapName},
441+
Key: "controller.resource.health.persist",
442+
},
443+
}},
424444
{Name: "HOME", Value: "/home/argocd"},
425445
{Name: "REDIS_PASSWORD", Value: "",
426446
ValueFrom: &corev1.EnvVarSource{
@@ -441,6 +461,12 @@ func TestReconcileArgoCD_reconcileApplicationController_withSharding(t *testing.
441461
replicas: 3,
442462
vars: []corev1.EnvVar{
443463
{Name: "ARGOCD_CONTROLLER_REPLICAS", Value: "3"},
464+
{Name: "ARGOCD_CONTROLLER_RESOURCE_HEALTH_PERSIST", ValueFrom: &corev1.EnvVarSource{
465+
ConfigMapKeyRef: &corev1.ConfigMapKeySelector{
466+
LocalObjectReference: corev1.LocalObjectReference{Name: common.ArgoCDCmdParamsConfigMapName},
467+
Key: "controller.resource.health.persist",
468+
},
469+
}},
444470
{Name: "HOME", Value: "/home/argocd"},
445471
{Name: "REDIS_PASSWORD", Value: "",
446472
ValueFrom: &corev1.EnvVarSource{
@@ -463,6 +489,12 @@ func TestReconcileArgoCD_reconcileApplicationController_withSharding(t *testing.
463489
replicas: 2,
464490
vars: []corev1.EnvVar{
465491
{Name: "ARGOCD_CONTROLLER_REPLICAS", Value: "2"},
492+
{Name: "ARGOCD_CONTROLLER_RESOURCE_HEALTH_PERSIST", ValueFrom: &corev1.EnvVarSource{
493+
ConfigMapKeyRef: &corev1.ConfigMapKeySelector{
494+
LocalObjectReference: corev1.LocalObjectReference{Name: common.ArgoCDCmdParamsConfigMapName},
495+
Key: "controller.resource.health.persist",
496+
},
497+
}},
466498
{Name: "HOME", Value: "/home/argocd"},
467499
{Name: "REDIS_PASSWORD", Value: "",
468500
ValueFrom: &corev1.EnvVarSource{
@@ -520,6 +552,12 @@ func TestReconcileArgoCD_reconcileApplicationController_withSharding(t *testing.
520552
func TestReconcileArgoCD_reconcileApplicationController_withAppSync(t *testing.T) {
521553

522554
expectedEnv := []corev1.EnvVar{
555+
{Name: "ARGOCD_CONTROLLER_RESOURCE_HEALTH_PERSIST", ValueFrom: &corev1.EnvVarSource{
556+
ConfigMapKeyRef: &corev1.ConfigMapKeySelector{
557+
LocalObjectReference: corev1.LocalObjectReference{Name: common.ArgoCDCmdParamsConfigMapName},
558+
Key: "controller.resource.health.persist",
559+
},
560+
}},
523561
{Name: "ARGOCD_RECONCILIATION_TIMEOUT", Value: "600s"},
524562
{Name: "HOME", Value: "/home/argocd"},
525563
{Name: "REDIS_PASSWORD", Value: "",
@@ -567,6 +605,12 @@ func TestReconcileArgoCD_reconcileApplicationController_withAppSync(t *testing.T
567605
func TestReconcileArgoCD_reconcileApplicationController_withEnv(t *testing.T) {
568606

569607
expectedEnv := []corev1.EnvVar{
608+
{Name: "ARGOCD_CONTROLLER_RESOURCE_HEALTH_PERSIST", ValueFrom: &corev1.EnvVarSource{
609+
ConfigMapKeyRef: &corev1.ConfigMapKeySelector{
610+
LocalObjectReference: corev1.LocalObjectReference{Name: common.ArgoCDCmdParamsConfigMapName},
611+
Key: "controller.resource.health.persist",
612+
},
613+
}},
570614
{Name: "CUSTOM_ENV_VAR", Value: "custom-value"},
571615
{Name: "HOME", Value: "/home/argocd"},
572616
{Name: "REDIS_PASSWORD", Value: "",

controllers/argocd/util.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,16 @@ func getArgoApplicationControllerCommand(cr *argoproj.ArgoCD, useTLSForRedis boo
177177
cmd = append(cmd, "--logformat")
178178
cmd = append(cmd, getLogFormat(cr.Spec.Controller.LogFormat))
179179

180+
persistHealth := "true" // default
181+
if val, ok := cr.Spec.CmdParams["controller.resource.health.persist"]; ok {
182+
persistHealth = val
183+
}
184+
185+
// set the command only if persistHealth is true
186+
if persistHealth == "true" {
187+
cmd = append(cmd, "--persist-resource-health")
188+
}
189+
180190
// check if extra args are present
181191
extraArgs := cr.Spec.Controller.ExtraCommandArgs
182192
cmd = appendUniqueArgs(cmd, extraArgs)

controllers/argocd/util_test.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"github.com/argoproj-labs/argocd-operator/common"
1717
"github.com/argoproj-labs/argocd-operator/controllers/argoutil"
1818

19+
corev1 "k8s.io/api/core/v1"
1920
v1 "k8s.io/api/core/v1"
2021
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2122
"k8s.io/apimachinery/pkg/runtime"
@@ -376,6 +377,7 @@ func TestGetArgoApplicationControllerCommand(t *testing.T) {
376377
"info",
377378
"--logformat",
378379
"text",
380+
"--persist-resource-health",
379381
}
380382

381383
controllerProcesorsChangedResult := func(n string) []string {
@@ -395,6 +397,7 @@ func TestGetArgoApplicationControllerCommand(t *testing.T) {
395397
"info",
396398
"--logformat",
397399
"text",
400+
"--persist-resource-health",
398401
}
399402
}
400403

@@ -415,6 +418,7 @@ func TestGetArgoApplicationControllerCommand(t *testing.T) {
415418
"info",
416419
"--logformat",
417420
"text",
421+
"--persist-resource-health",
418422
}
419423
}
420424

@@ -433,6 +437,7 @@ func TestGetArgoApplicationControllerCommand(t *testing.T) {
433437
"info",
434438
"--logformat",
435439
"text",
440+
"--persist-resource-health",
436441
"--operation-processors",
437442
n,
438443
}
@@ -455,6 +460,7 @@ func TestGetArgoApplicationControllerCommand(t *testing.T) {
455460
"info",
456461
"--logformat",
457462
"text",
463+
"--persist-resource-health",
458464
}
459465
}
460466

@@ -475,6 +481,7 @@ func TestGetArgoApplicationControllerCommand(t *testing.T) {
475481
"info",
476482
"--logformat",
477483
f,
484+
"--persist-resource-health",
478485
}
479486
}
480487

@@ -495,6 +502,7 @@ func TestGetArgoApplicationControllerCommand(t *testing.T) {
495502
l,
496503
"--logformat",
497504
"text",
505+
"--persist-resource-health",
498506
}
499507
}
500508

@@ -637,7 +645,13 @@ func TestGetArgoApplicationContainerEnv(t *testing.T) {
637645
Key: "admin.password",
638646
},
639647
}},
640-
{Name: "ARGOCD_RECONCILIATION_TIMEOUT", Value: "60s", ValueFrom: (*v1.EnvVarSource)(nil)}}
648+
{Name: "ARGOCD_RECONCILIATION_TIMEOUT", Value: "60s", ValueFrom: (*v1.EnvVarSource)(nil)},
649+
{Name: "ARGOCD_CONTROLLER_RESOURCE_HEALTH_PERSIST", ValueFrom: &corev1.EnvVarSource{
650+
ConfigMapKeyRef: &corev1.ConfigMapKeySelector{
651+
LocalObjectReference: corev1.LocalObjectReference{Name: common.ArgoCDCmdParamsConfigMapName},
652+
Key: "controller.resource.health.persist",
653+
},
654+
}}}
641655

642656
cmdTests := []struct {
643657
name string

tests/k8s/1-007_validate_volume_mounts/01-assert.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,5 +159,7 @@ spec:
159159
items:
160160
- key: controller.profile.enabled
161161
path: profiler.enabled
162+
- key: controller.resource.health.persist
163+
path: controller.resource.health.persist
162164
- name: argocd-application-controller-tmp
163165
emptyDir: {}

tests/k8s/1-038_validate_controller_extra_command_args/02-assert.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,5 @@ spec:
2323
- info
2424
- --logformat
2525
- text
26+
- --persist-resource-health
2627
- --hydrator-enabled

tests/k8s/1-038_validate_controller_extra_command_args/03-errors.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,5 @@ spec:
2323
- info
2424
- --logformat
2525
- text
26+
- --persist-resource-health
2627
- --hydrator-enabled

tests/k8s/1-038_validate_controller_extra_command_args/04-errors.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ spec:
2222
- --loglevel
2323
- info
2424
- --logformat
25+
- --persist-resource-health
2526
- text
2627
---
2728
apiVersion: apps/v1
@@ -49,6 +50,7 @@ spec:
4950
- info
5051
- --logformat
5152
- text
53+
- --persist-resource-health
5254
- --status-processors
5355
- "15"
5456
- --kubectl-parallelism-limit

0 commit comments

Comments
 (0)