Skip to content

Commit

Permalink
fix: address nil pointer when controller runs with sts and replicas >…
Browse files Browse the repository at this point in the history
… 1 (argoproj#15770)

* fix: address nil pointer when controller runs with sts and replicas > 1

Signed-off-by: Leonardo Luz Almeida <leonardo_almeida@intuit.com>

* fix: lint

Signed-off-by: Leonardo Luz Almeida <leonardo_almeida@intuit.com>

* fix: better handle errors

Signed-off-by: Leonardo Luz Almeida <leonardo_almeida@intuit.com>

---------

Signed-off-by: Leonardo Luz Almeida <leonardo_almeida@intuit.com>
  • Loading branch information
leoluz authored and tesla59 committed Dec 16, 2023
1 parent f595b33 commit 661a871
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions util/db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ import (
"strings"

v1 "k8s.io/api/core/v1"
kubeerrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"

"github.com/argoproj/argo-cd/v2/common"
appv1 "github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
"github.com/argoproj/argo-cd/v2/util/env"
"github.com/argoproj/argo-cd/v2/util/settings"
log "github.com/sirupsen/logrus"
)

// SecretMaperValidation determine whether the secret should be transformed(i.e. trailing CRLF characters trimmed)
Expand Down Expand Up @@ -153,8 +155,13 @@ func (db *db) GetApplicationControllerReplicas() int {
// get the replicas from application controller deployment, if the application controller deployment does not exist, check for environment variable
applicationControllerName := env.StringFromEnv(common.EnvAppControllerName, common.DefaultApplicationControllerName)
appControllerDeployment, err := db.kubeclientset.AppsV1().Deployments(db.settingsMgr.GetNamespace()).Get(context.Background(), applicationControllerName, metav1.GetOptions{})

if err == nil && appControllerDeployment.Spec.Replicas != nil {
if err != nil {
appControllerDeployment = nil
if !kubeerrors.IsNotFound(err) {
log.Warnf("error retrieveing Argo CD controller deployment: %s", err)
}
}
if appControllerDeployment != nil && appControllerDeployment.Spec.Replicas != nil {
return int(*appControllerDeployment.Spec.Replicas)
}
return env.ParseNumFromEnv(common.EnvControllerReplicas, 0, 0, math.MaxInt32)
Expand Down

0 comments on commit 661a871

Please sign in to comment.