diff --git a/cmd/argocd-application-controller/commands/argocd_application_controller.go b/cmd/argocd-application-controller/commands/argocd_application_controller.go index 519299ba8085a..6ab4dc2692932 100644 --- a/cmd/argocd-application-controller/commands/argocd_application_controller.go +++ b/cmd/argocd-application-controller/commands/argocd_application_controller.go @@ -93,7 +93,7 @@ func NewCommand() *cobra.Command { config, err := clientConfig.ClientConfig() errors.CheckError(err) errors.CheckError(v1alpha1.SetK8SConfigDefaults(config)) - config.UserAgent = fmt.Sprintf("argocd-application-controller/%s (%s)", vers.Version, vers.Platform) + config.UserAgent = fmt.Sprintf("%s/%s (%s)", common.DefaultApplicationControllerName, vers.Version, vers.Platform) kubeClient := kubernetes.NewForConfigOrDie(config) appClient := appclientset.NewForConfigOrDie(config) @@ -213,13 +213,12 @@ func getClusterFilter(kubeClient *kubernetes.Clientset, settingsMgr *settings.Se var replicas int shard := env.ParseNumFromEnv(common.EnvControllerShard, -1, -math.MaxInt32, math.MaxInt32) - appControllerDeployment, _ := kubeClient.AppsV1().Deployments(settingsMgr.GetNamespace()).Get(context.Background(), common.ApplicationController, metav1.GetOptions{}) - - appControllerStatefulset, _ := kubeClient.AppsV1().StatefulSets(settingsMgr.GetNamespace()).Get(context.Background(), common.ApplicationController, metav1.GetOptions{}) + applicationControllerName := env.StringFromEnv(common.EnvAppControllerName, common.DefaultApplicationControllerName) + appControllerDeployment, _ := kubeClient.AppsV1().Deployments(settingsMgr.GetNamespace()).Get(context.Background(), applicationControllerName, metav1.GetOptions{}) if appControllerDeployment != nil { replicas = int(*appControllerDeployment.Spec.Replicas) - } else if appControllerStatefulset != nil { + } else { replicas = env.ParseNumFromEnv(common.EnvControllerReplicas, 0, 0, math.MaxInt32) } @@ -241,7 +240,7 @@ func getClusterFilter(kubeClient *kubernetes.Clientset, settingsMgr *settings.Se log.Warnf("conflict when getting shard from shard mapping configMap. Retrying (%d/3)", i) } errors.CheckError(err) - } else if appControllerStatefulset != nil { + } else { if shard < 0 { var err error shard, err = sharding.InferShard() diff --git a/controller/appcontroller.go b/controller/appcontroller.go index 51bf50e703562..70b6aa9a9ffcb 100644 --- a/controller/appcontroller.go +++ b/controller/appcontroller.go @@ -204,7 +204,8 @@ func NewApplicationController( }) readinessHealthCheck := func(r *http.Request) error { - appControllerDeployment, _ := kubeClientset.AppsV1().Deployments(settingsMgr.GetNamespace()).Get(context.Background(), common.ApplicationController, metav1.GetOptions{}) + applicationControllerName := env.StringFromEnv(common.EnvAppControllerName, common.DefaultApplicationControllerName) + appControllerDeployment, _ := kubeClientset.AppsV1().Deployments(settingsMgr.GetNamespace()).Get(context.Background(), applicationControllerName, metav1.GetOptions{}) if appControllerDeployment != nil { if appControllerDeployment.Spec.Replicas != nil && int(*appControllerDeployment.Spec.Replicas) <= 0 { return fmt.Errorf("application controller deployment replicas is not set or is less than 0, replicas: %d", appControllerDeployment.Spec.Replicas) diff --git a/util/db/db.go b/util/db/db.go index 2f1f854739978..d5361ad148456 100644 --- a/util/db/db.go +++ b/util/db/db.go @@ -151,7 +151,8 @@ func StripCRLFCharacter(input string) string { // GetApplicationControllerReplicas gets the replicas of application controller func (db *db) GetApplicationControllerReplicas() int { // get the replicas from application controller deployment, if the application controller deployment does not exist, check for environment variable - appControllerDeployment, _ := db.kubeclientset.AppsV1().Deployments(db.settingsMgr.GetNamespace()).Get(context.Background(), common.ApplicationController, metav1.GetOptions{}) + applicationControllerName := env.StringFromEnv(common.EnvAppControllerName, common.DefaultApplicationControllerName) + appControllerDeployment, _ := db.kubeclientset.AppsV1().Deployments(db.settingsMgr.GetNamespace()).Get(context.Background(), applicationControllerName, metav1.GetOptions{}) if appControllerDeployment != nil { return int(*appControllerDeployment.Spec.Replicas) }