Skip to content

Commit

Permalink
fix: Reconcile serviceAccount fields in redis deployment (#1635) (#1639)
Browse files Browse the repository at this point in the history
* fix: Reconcile serviceAccount fields in redis deployment (#1635)

* fix redis SA updation issue

Signed-off-by: Varsha B <[email protected]>

* fix CI test failure

Signed-off-by: Varsha B <[email protected]>

---------

Signed-off-by: Varsha B <[email protected]>

* Addressed review comment

Signed-off-by: Varsha B <[email protected]>

---------

Signed-off-by: Varsha B <[email protected]>
  • Loading branch information
varshab1210 authored Jan 15, 2025
1 parent f8e6b0f commit 66246bc
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 1 deletion.
5 changes: 5 additions & 0 deletions controllers/argocd/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,11 @@ func (r *ReconcileArgoCD) reconcileRedisDeployment(cr *argoproj.ArgoCD, useTLS b
changed = true
}

if !reflect.DeepEqual(deploy.Spec.Template.Spec.ServiceAccountName, existing.Spec.Template.Spec.ServiceAccountName) {
existing.Spec.Template.Spec.ServiceAccountName = deploy.Spec.Template.Spec.ServiceAccountName
changed = true
}

if changed {
return r.Client.Update(context.TODO(), existing)
}
Expand Down
59 changes: 59 additions & 0 deletions controllers/argocd/deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1833,6 +1833,65 @@ func TestReconcileArgoCD_reconcileRedisDeployment_with_error(t *testing.T) {
assert.Error(t, r.reconcileRedisDeployment(cr, false), "this is a test error")
}

func TestReconcileRedisDeployment_serviceAccountNameUpdate(t *testing.T) {
// tests SA update for redis deployment

tests := []struct {
name string
SA string
expectedSA string
}{
{
name: "serviceAccountName field should reflect the original value",
SA: "argocd-argocd-redis",
expectedSA: "argocd-argocd-redis",
},
{
name: "serviceAccountName field should be reset to the original value with an existing SA modification",
SA: "builder",
expectedSA: "argocd-argocd-redis",
},
{
name: "serviceAccountName field should be reset to the original value with a non-existing SA modification",
SA: "argocd-argocd-redis-new",
expectedSA: "argocd-argocd-redis",
},
{
name: "serviceAccountName field should be reset to the original value and not left empty",
SA: "",
expectedSA: "argocd-argocd-redis",
},
}

cr := makeTestArgoCD()

resObjs := []client.Object{cr}
subresObjs := []client.Object{cr}
runtimeObjs := []runtime.Object{}
sch := makeTestReconcilerScheme(argoproj.AddToScheme)
cl := makeTestReconcilerClient(sch, resObjs, subresObjs, runtimeObjs)
r := makeTestReconciler(cl, sch)

// Verify redis deployment
assert.NoError(t, r.reconcileRedisDeployment(cr, false))

// Verify SA update
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
existing := &appsv1.Deployment{}
assert.NoError(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: cr.Name + "-redis", Namespace: cr.Namespace}, existing))

existing.Spec.Template.Spec.ServiceAccountName = test.SA
assert.NoError(t, cl.Update(context.TODO(), existing))
assert.NoError(t, r.reconcileRedisDeployment(cr, false))

newRedis := &appsv1.Deployment{}
assert.NoError(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: cr.Name + "-redis", Namespace: cr.Namespace}, newRedis))
assert.Equal(t, newRedis.Spec.Template.Spec.ServiceAccountName, test.expectedSA)
})
}
}

func operationProcessors(n int32) argoCDOpt {
return func(a *argoproj.ArgoCD) {
a.Spec.Controller.Processors.Operation = n
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ apiVersion: kuttl.dev/v1beta1
kind: TestStep
commands:
- script: |
oc patch -n test-1-38-controller-extra-command argocds/example-argocd --type=json --patch '[{"op": "remove", "path": "/spec/controller/extraCommandArgs"}]'
kubectl patch -n test-1-38-controller-extra-command argocds/example-argocd --type=json --patch '[{"op": "remove", "path": "/spec/controller/extraCommandArgs"}]'

0 comments on commit 66246bc

Please sign in to comment.