diff --git a/cmd/kusk/cmd/uninstall.go b/cmd/kusk/cmd/uninstall.go index 2dc3e5ed6..eab75970f 100644 --- a/cmd/kusk/cmd/uninstall.go +++ b/cmd/kusk/cmd/uninstall.go @@ -4,6 +4,7 @@ import ( "fmt" "os" "path/filepath" + "time" kuskv1 "github.com/kubeshop/kusk-gateway/api/v1alpha1" "github.com/kubeshop/kusk-gateway/cmd/kusk/internal/errors" @@ -101,6 +102,20 @@ var uninstallCmd = &cobra.Command{ } apiSpinner.Success("Deleted APIs") } + for { + if err := c.List(cmd.Context(), apis, &client.ListOptions{}); err != nil { + if err.Error() == `no matches for kind "API" in version "gateway.kusk.io/v1alpha1"` { + kuskui.PrintInfo("Kusk Custom Resource Definition API is not installed.") + } else { + reportError(err) + return err + } + } + if len(apis.Items) == 0 { + break + } + time.Sleep(1 * time.Second) + } fleets := &kuskv1.EnvoyFleetList{} if err := c.List(cmd.Context(), fleets, &client.ListOptions{}); err != nil { @@ -123,6 +138,21 @@ var uninstallCmd = &cobra.Command{ envoyFleetSpinner.Success("Deleted EnvoyFleets") } + for { + if err := c.List(cmd.Context(), fleets, &client.ListOptions{}); err != nil { + if err.Error() == `no matches for kind "EnvoyFleet" in version "gateway.kusk.io/v1alpha1"` { + kuskui.PrintInfo("Kusk Custom Resource Definition EnvoyFleet is not installed.") + } else { + reportError(err) + return err + } + } + if len(fleets.Items) == 0 { + break + } + time.Sleep(1 * time.Second) + } + staticRoutes := &kuskv1.StaticRouteList{} if err := c.List(cmd.Context(), staticRoutes, &client.ListOptions{}); err != nil { if err.Error() == `no matches for kind "StaticRoute" in version "gateway.kusk.io/v1alpha1"` { @@ -144,6 +174,21 @@ var uninstallCmd = &cobra.Command{ staticRoutesSpinner.Success("Deleted StaticRoutes") } + for { + if err := c.List(cmd.Context(), staticRoutes, &client.ListOptions{}); err != nil { + if err.Error() == `no matches for kind "StaticRoute" in version "gateway.kusk.io/v1alpha1"` { + kuskui.PrintInfo("Kusk Custom Resource Definition StaticRouote is not installed") + } else { + reportError(err) + return err + } + } + if len(staticRoutes.Items) == 0 { + break + } + time.Sleep(1 * time.Second) + } + kuskGatewaySpinner := utils.NewSpinner("Deleting Kusk Gateway...") if err := deletek(dir); err != nil {