Skip to content

Commit d8bd863

Browse files
authored
fix: Redis HA Server StatefulSet SecurityContext Not Updated During Upgrade (#1703)
* add missing check for security context Signed-off-by: Mangaal <[email protected]> * update unit test for RedisStatefulSet Signed-off-by: Mangaal <[email protected]> --------- Signed-off-by: Mangaal <[email protected]>
1 parent f5ae3cc commit d8bd863

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
@@ -498,6 +498,14 @@ func (r *ReconcileArgoCD) reconcileRedisStatefulSet(cr *argoproj.ArgoCD) error {
498498
changed = true
499499
}
500500
}
501+
if !reflect.DeepEqual(ss.Spec.Template.Spec.SecurityContext, existing.Spec.Template.Spec.SecurityContext) {
502+
existing.Spec.Template.Spec.SecurityContext = ss.Spec.Template.Spec.SecurityContext
503+
if changed {
504+
explanation += ", "
505+
}
506+
explanation += "security context"
507+
changed = true
508+
}
501509
if !reflect.DeepEqual(ss.Spec.Template.Spec.Volumes, existing.Spec.Template.Spec.Volumes) {
502510
existing.Spec.Template.Spec.Volumes = ss.Spec.Template.Spec.Volumes
503511
if changed {
@@ -943,6 +951,14 @@ func (r *ReconcileArgoCD) reconcileApplicationControllerStatefulSet(cr *argoproj
943951
explanation += "replicas"
944952
changed = true
945953
}
954+
if !reflect.DeepEqual(ss.Spec.Template.Spec.SecurityContext, existing.Spec.Template.Spec.SecurityContext) {
955+
existing.Spec.Template.Spec.SecurityContext = ss.Spec.Template.Spec.SecurityContext
956+
if changed {
957+
explanation += ", "
958+
}
959+
explanation += "security context"
960+
changed = true
961+
}
946962

947963
if !reflect.DeepEqual(ss.Spec.Template.Spec.Containers[1:],
948964
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

@@ -931,6 +932,20 @@ func TestReconcileArgoCD_reconcileRedisStatefulSet_ModifyContainerSpec(t *testin
931932
}
932933
assert.False(t, envVarFound, "NEW_ENV_VAR should not be present")
933934

935+
// Modify the SecurityContext
936+
assert.NoError(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: s.Name, Namespace: a.Namespace}, s))
937+
expectedSecurityContext := s.Spec.Template.Spec.SecurityContext
938+
fsGroup := int64(2000)
939+
newSecurityContext := &corev1.PodSecurityContext{
940+
FSGroup: &fsGroup,
941+
}
942+
s.Spec.Template.Spec.SecurityContext = newSecurityContext
943+
assert.NoError(t, r.Client.Update(context.TODO(), s))
944+
// Reconcile again and check if the SecurityContext is reverted
945+
assert.NoError(t, r.reconcileRedisStatefulSet(a))
946+
assert.NoError(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: s.Name, Namespace: a.Namespace}, s))
947+
assert.Equal(t, true, reflect.DeepEqual(expectedSecurityContext, s.Spec.Template.Spec.SecurityContext))
948+
934949
// Modify the initcontainer environment variable
935950
s.Spec.Template.Spec.Containers[0].Env = append(s.Spec.Template.Spec.InitContainers[0].Env, corev1.EnvVar{
936951
Name: "NEW_ENV_VAR",

0 commit comments

Comments
 (0)