Skip to content

Commit f66b337

Browse files
fix: Redis HA Server StatefulSet SecurityContext Not Updated During Upgrade (#1703) (#1719)
* add missing check for security context * update unit test for RedisStatefulSet --------- Signed-off-by: Mangaal <angommeeteimangaal@gmail.com> Signed-off-by: Alka Kumari <alkumari@redhat.com> Co-authored-by: Mangaal Meetei <angommeeteimangaal@gmail.com>
1 parent a95e322 commit f66b337

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

controllers/argocd/statefulset.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,14 @@ func (r *ReconcileArgoCD) reconcileRedisStatefulSet(cr *argoproj.ArgoCD) error {
495495
changed = true
496496
}
497497
}
498+
if !reflect.DeepEqual(ss.Spec.Template.Spec.SecurityContext, existing.Spec.Template.Spec.SecurityContext) {
499+
existing.Spec.Template.Spec.SecurityContext = ss.Spec.Template.Spec.SecurityContext
500+
if changed {
501+
explanation += ", "
502+
}
503+
explanation += "security context"
504+
changed = true
505+
}
498506
if !reflect.DeepEqual(ss.Spec.Template.Spec.Volumes, existing.Spec.Template.Spec.Volumes) {
499507
existing.Spec.Template.Spec.Volumes = ss.Spec.Template.Spec.Volumes
500508
if changed {
@@ -897,6 +905,14 @@ func (r *ReconcileArgoCD) reconcileApplicationControllerStatefulSet(cr *argoproj
897905
explanation += "replicas"
898906
changed = true
899907
}
908+
if !reflect.DeepEqual(ss.Spec.Template.Spec.SecurityContext, existing.Spec.Template.Spec.SecurityContext) {
909+
existing.Spec.Template.Spec.SecurityContext = ss.Spec.Template.Spec.SecurityContext
910+
if changed {
911+
explanation += ", "
912+
}
913+
explanation += "security context"
914+
changed = true
915+
}
900916

901917
if !reflect.DeepEqual(ss.Spec.Template.Spec.Containers[1:],
902918
existing.Spec.Template.Spec.Containers[1:]) {

controllers/argocd/statefulset_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package argocd
33
import (
44
"context"
55
"fmt"
6+
"reflect"
67
"testing"
78
"time"
89

@@ -890,6 +891,20 @@ func TestReconcileArgoCD_reconcileRedisStatefulSet_ModifyContainerSpec(t *testin
890891
}
891892
assert.False(t, envVarFound, "NEW_ENV_VAR should not be present")
892893

894+
// Modify the SecurityContext
895+
assert.NoError(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: s.Name, Namespace: a.Namespace}, s))
896+
expectedSecurityContext := s.Spec.Template.Spec.SecurityContext
897+
fsGroup := int64(2000)
898+
newSecurityContext := &corev1.PodSecurityContext{
899+
FSGroup: &fsGroup,
900+
}
901+
s.Spec.Template.Spec.SecurityContext = newSecurityContext
902+
assert.NoError(t, r.Client.Update(context.TODO(), s))
903+
// Reconcile again and check if the SecurityContext is reverted
904+
assert.NoError(t, r.reconcileRedisStatefulSet(a))
905+
assert.NoError(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: s.Name, Namespace: a.Namespace}, s))
906+
assert.Equal(t, true, reflect.DeepEqual(expectedSecurityContext, s.Spec.Template.Spec.SecurityContext))
907+
893908
// Modify the initcontainer environment variable
894909
s.Spec.Template.Spec.Containers[0].Env = append(s.Spec.Template.Spec.InitContainers[0].Env, corev1.EnvVar{
895910
Name: "NEW_ENV_VAR",

0 commit comments

Comments
 (0)