From 7d1d8680359f3737fed3fab3f4d2c479119ca7b7 Mon Sep 17 00:00:00 2001 From: Ishita Sequeira <46771830+ishitasequeira@users.noreply.github.com> Date: Tue, 26 Sep 2023 14:30:06 -0400 Subject: [PATCH] fix: add a not found check for application controller deployment (#15678) Signed-off-by: ishitasequeira --- .../commands/argocd_application_controller.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cmd/argocd-application-controller/commands/argocd_application_controller.go b/cmd/argocd-application-controller/commands/argocd_application_controller.go index a4707e511974c3..28491bab4899b8 100644 --- a/cmd/argocd-application-controller/commands/argocd_application_controller.go +++ b/cmd/argocd-application-controller/commands/argocd_application_controller.go @@ -216,7 +216,12 @@ func getClusterFilter(kubeClient *kubernetes.Clientset, settingsMgr *settings.Se shard := env.ParseNumFromEnv(common.EnvControllerShard, -1, -math.MaxInt32, math.MaxInt32) applicationControllerName := env.StringFromEnv(common.EnvAppControllerName, common.DefaultApplicationControllerName) - appControllerDeployment, _ := kubeClient.AppsV1().Deployments(settingsMgr.GetNamespace()).Get(context.Background(), applicationControllerName, metav1.GetOptions{}) + appControllerDeployment, err := kubeClient.AppsV1().Deployments(settingsMgr.GetNamespace()).Get(context.Background(), applicationControllerName, metav1.GetOptions{}) + + // if the application controller deployment was not found, the Get() call returns an empty Deployment object. So, set the variable to nil explicitly + if kubeerrors.IsNotFound(err) { + appControllerDeployment = nil + } if appControllerDeployment != nil && appControllerDeployment.Spec.Replicas != nil { replicas = int(*appControllerDeployment.Spec.Replicas)