From b803d814994094d025e6055bea7c2a278df2f2cf Mon Sep 17 00:00:00 2001 From: 1012Charan Date: Mon, 4 Aug 2025 22:43:40 +0530 Subject: [PATCH] fix(cli): prevent uninstall timeout by deleting CRDs before controller Previously, uninstall would fail with 'timed out waiting for the condition' because the controller was removed before workers stopped using it. This change: - Deletes KubeSlice CRDs before removing the controller - Waits 2 seconds for cleanup - Adds timeout flag to helm uninstall for reliability Fixes #58 Signed-off-by: 1012Charan --- pkg/internal/controller.go | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/pkg/internal/controller.go b/pkg/internal/controller.go index 349c916..e15a3c9 100644 --- a/pkg/internal/controller.go +++ b/pkg/internal/controller.go @@ -50,6 +50,13 @@ func UninstallKubeSliceController(ApplicationConfiguration *ConfigurationSpecs) util.Printf("\nUninstalling KubeSlice Controller...") cc := ApplicationConfiguration.Configuration.ClusterConfiguration time.Sleep(200 * time.Millisecond) + + // First delete CRDs to trigger worker uninstallation + util.Printf("Deleting KubeSlice CRDs to trigger worker cleanup...") + deleteKubeSliceCRDs(cc.ControllerCluster) + time.Sleep(2 * time.Second) // Give time for workers to be cleaned up + + // Then uninstall the controller uninstallKubeSliceController(cc.ControllerCluster) time.Sleep(200 * time.Millisecond) util.Printf("%s Successfully uninstalled KubeSlice Controller", util.Tick) @@ -78,9 +85,32 @@ func installKubeSliceController(cluster Cluster, hc HelmChartConfiguration) { func uninstallKubeSliceController(cluster Cluster) { args := make([]string, 0) - args = append(args, "--kube-context", cluster.ContextName, "--kubeconfig", cluster.KubeConfigPath, "uninstall", KUBESLICE_CONTROLLER_NAMESPACE, "--namespace", KUBESLICE_CONTROLLER_NAMESPACE) + args = append(args, "--kube-context", cluster.ContextName, "--kubeconfig", cluster.KubeConfigPath, "uninstall", KUBESLICE_CONTROLLER_NAMESPACE, "--namespace", KUBESLICE_CONTROLLER_NAMESPACE, "--timeout", "2m") err := util.RunCommand("helm", args...) if err != nil { log.Fatalf("Process failed %v", err) } } + +func deleteKubeSliceCRDs(cluster Cluster) { + // List of KubeSlice CRDs to delete + crdNames := []string{ + "projects.controller.kubeslice.io", + "clusters.controller.kubeslice.io", + "sliceconfigs.controller.kubeslice.io", + "serviceexportconfigs.controller.kubeslice.io", + "serviceexports.networking.kubeslice.io", + } + + for _, crdName := range crdNames { + args := make([]string, 0) + args = append(args, "--kube-context", cluster.ContextName, "--kubeconfig", cluster.KubeConfigPath, "delete", "crd", crdName) + err := util.RunCommand("kubectl", args...) + if err != nil { + // Log error but continue with other CRDs + util.Printf("%s Warning: Failed to delete CRD %s: %v", util.Cross, crdName, err) + } else { + util.Printf("%s Deleted CRD: %s", util.Tick, crdName) + } + } +}