Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix the setting of environment variable ARGOCD_CONTROLLER_REPLICAS fo… #1576

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions controllers/argocd/statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ func (r *ReconcileArgoCD) reconcileRedisStatefulSet(cr *argoproj.ArgoCD) error {
return r.Client.Create(context.TODO(), ss)
}

func getArgoControllerContainerEnv(cr *argoproj.ArgoCD) []corev1.EnvVar {
func getArgoControllerContainerEnv(cr *argoproj.ArgoCD, replicas int32) []corev1.EnvVar {
env := make([]corev1.EnvVar, 0)

env = append(env, corev1.EnvVar{
Expand All @@ -489,10 +489,10 @@ func getArgoControllerContainerEnv(cr *argoproj.ArgoCD) []corev1.EnvVar {
},
})

if cr.Spec.Controller.Sharding.Enabled {
if cr.Spec.Controller.Sharding.Enabled || (cr.Spec.Controller.Sharding.DynamicScalingEnabled != nil && *cr.Spec.Controller.Sharding.DynamicScalingEnabled) {
env = append(env, corev1.EnvVar{
Name: "ARGOCD_CONTROLLER_REPLICAS",
Value: fmt.Sprint(cr.Spec.Controller.Sharding.Replicas),
Value: fmt.Sprint(replicas),
})
}

Expand Down Expand Up @@ -564,7 +564,7 @@ func (r *ReconcileArgoCD) reconcileApplicationControllerStatefulSet(cr *argoproj
ss.Spec.Replicas = &replicas
controllerEnv := cr.Spec.Controller.Env
// Sharding setting explicitly overrides a value set in the env
controllerEnv = argoutil.EnvMerge(controllerEnv, getArgoControllerContainerEnv(cr), true)
controllerEnv = argoutil.EnvMerge(controllerEnv, getArgoControllerContainerEnv(cr, replicas), true)
// Let user specify their own environment first
controllerEnv = argoutil.EnvMerge(controllerEnv, proxyEnvVars(), false)
podSpec := &ss.Spec.Template.Spec
Expand Down
23 changes: 23 additions & 0 deletions controllers/argocd/statefulset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,29 @@ func TestReconcileArgoCD_reconcileApplicationController_withSharding(t *testing.
}},
},
},
{
sharding: argoproj.ArgoCDApplicationControllerShardSpec{
DynamicScalingEnabled: boolPtr(true),
MinShards: 2,
MaxShards: 4,
ClustersPerShard: 1,
},
replicas: 2,
vars: []corev1.EnvVar{
{Name: "ARGOCD_CONTROLLER_REPLICAS", Value: "2"},
{Name: "HOME", Value: "/home/argocd"},
{Name: "REDIS_PASSWORD", Value: "",
ValueFrom: &corev1.EnvVarSource{
SecretKeyRef: &corev1.SecretKeySelector{
LocalObjectReference: corev1.LocalObjectReference{
Name: fmt.Sprintf("argocd-redis-initial-password"),
},
Key: "admin.password",
},
},
},
},
},
}

for _, st := range tests {
Expand Down
2 changes: 1 addition & 1 deletion controllers/argocd/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ func TestGetArgoApplicationContainerEnv(t *testing.T) {

for _, tt := range cmdTests {
cr := makeTestArgoCD(tt.opts...)
env := getArgoControllerContainerEnv(cr)
env := getArgoControllerContainerEnv(cr, 1)

if !reflect.DeepEqual(env, tt.want) {
t.Fatalf("got %#v, want %#v", env, tt.want)
Expand Down
22 changes: 21 additions & 1 deletion tests/k8s/1-032_validate_dynamic_scaling/01-assert.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,24 @@ kind: ArgoCD
metadata:
name: argocd
status:
phase: Available
phase: Available
---
apiVersion: kuttl.dev/v1beta1
kind: TestAssert
timeout: 720
commands:
- script: |
stsReplicas=$(kubectl get sts argocd-application-controller -n $NAMESPACE -o jsonpath='{.status.replicas}')
echo "$stsReplicas"
if test "$stsReplicas" != "1"; then
echo "FAILED! Number of replicas not equal to desired replicas"
exit 1
fi

replicaEnvVariable=$(kubectl exec -it -n $NAMESPACE argocd-application-controller-0 -- printenv | grep -i ARGOCD_CONTROLLER_REPLICAS)
echo "$replicaEnvVariable"
if test "$replicaEnvVariable" != "ARGOCD_CONTROLLER_REPLICAS=1"; then
echo "FAILED! ARGOCD_CONTROLLER_REPLICAS not equal to desired replicas"
exit 1
fi
exit 0
2 changes: 1 addition & 1 deletion tests/k8s/1-032_validate_dynamic_scaling/01-install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ spec:
apiVersion: kuttl.dev/v1beta1
kind: TestStep
commands:
- command: sleep 30s
- command: sleep 60s
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ stringData:
apiVersion: kuttl.dev/v1beta1
kind: TestStep
commands:
- command: sleep 30s
- command: sleep 60s
23 changes: 20 additions & 3 deletions tests/k8s/1-032_validate_dynamic_scaling/02-assert.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
apiVersion: kuttl.dev/v1beta1
kind: TestAssert
timeout: 720
---
apiVersion: argoproj.io/v1alpha1
kind: ArgoCD
Expand All @@ -15,3 +12,23 @@ metadata:
name: argocd-application-controller
status:
replicas: 3
---
apiVersion: kuttl.dev/v1beta1
kind: TestAssert
timeout: 720
commands:
- script: |
stsReplicas=$(kubectl get sts argocd-application-controller -n $NAMESPACE -o jsonpath='{.status.replicas}')
echo "$stsReplicas"
if test "$stsReplicas" != "3"; then
echo "FAILED! Number of replicas not equal to desired replicas"
exit 1
fi

replicaEnvVariable=$(kubectl exec -it -n $NAMESPACE argocd-application-controller-0 -- printenv | grep -i ARGOCD_CONTROLLER_REPLICAS)
echo "$replicaEnvVariable"
if test "$replicaEnvVariable" != "ARGOCD_CONTROLLER_REPLICAS=3"; then
echo "FAILED! ARGOCD_CONTROLLER_REPLICAS not equal to desired replicas"
exit 1
fi
exit 0
23 changes: 15 additions & 8 deletions tests/k8s/1-032_validate_dynamic_scaling/03-assert.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,18 @@ apiVersion: kuttl.dev/v1beta1
kind: TestAssert
timeout: 720
commands:
- script: |
stsReplicas=$(kubectl get sts argocd-application-controller -n $NAMESPACE -o jsonpath='{.status.replicas}')
echo "$stsReplicas"
if test "$stsReplicas" != "4"; then
echo "FAILED! Number of replicas not equal to maxShards"
exit 1
fi
exit 0
- script: |
stsReplicas=$(kubectl get sts argocd-application-controller -n $NAMESPACE -o jsonpath='{.status.replicas}')
echo "$stsReplicas"
if test "$stsReplicas" != "4"; then
echo "FAILED! Number of replicas not equal to maxShards"
exit 1
fi

replicaEnvVariable=$(kubectl exec -it -n $NAMESPACE argocd-application-controller-0 -- printenv | grep -i ARGOCD_CONTROLLER_REPLICAS)
echo "$replicaEnvVariable"
if test "$replicaEnvVariable" != "ARGOCD_CONTROLLER_REPLICAS=4"; then
echo "FAILED! ARGOCD_CONTROLLER_REPLICAS not equal to maxShards"
exit 1
fi
exit 0
Loading