From bdf181616ae27ef8fa9e60bdb882b348cc8b87a2 Mon Sep 17 00:00:00 2001 From: yashsinghcodes Date: Wed, 14 Jan 2026 17:51:04 +0530 Subject: [PATCH] check app deployment in k8s before deploying --- functions/onprem/worker/worker.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/functions/onprem/worker/worker.go b/functions/onprem/worker/worker.go index abf793fc..2e36c728 100644 --- a/functions/onprem/worker/worker.go +++ b/functions/onprem/worker/worker.go @@ -413,6 +413,8 @@ func deployk8sApp(image string, identifier string, env []string) error { kubernetesNamespace = "default" } + ctx := context.Background() + log.Printf("[DEBUG] Deploying k8s app with identifier %s to namespace %s", identifier, kubernetesNamespace) deployport, err := strconv.Atoi(os.Getenv("SHUFFLE_APP_EXPOSED_PORT")) if err != nil { @@ -624,6 +626,21 @@ func deployk8sApp(image string, identifier string, env []string) error { } } + existing, err := clientset.AppsV1().Deployments(kubernetesNamespace).List( + ctx, + metav1.ListOptions{ + LabelSelector: fmt.Sprintf("app: %s", name), + }, + ) + if err != nil { + log.Printf("[ERROR] Failed listing existing deployments: %v", err) + } + + if len(existing.Items) > 0 { + log.Printf("[INFO] Found existing deployments, skipping creation") + return errors.New("Found existing deployment") + } + replicaNumberInt32 := int32(replicaNumber) // apps do not need access the k8s api. automountServiceAccountToken := false