Skip to content

Commit

Permalink
namespaces command improvements (#947)
Browse files Browse the repository at this point in the history
Signed-off-by: Mayank Shah <[email protected]>
  • Loading branch information
mayankshah1607 authored Dec 20, 2024
1 parent 6d2d98f commit 9e649a9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 10 additions & 0 deletions pkg/cli/namespaces/remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
cliutils "github.com/percona/everest/pkg/cli/utils"
"github.com/percona/everest/pkg/common"
"github.com/percona/everest/pkg/kubernetes"
"github.com/percona/everest/pkg/output"
)

const (
Expand Down Expand Up @@ -87,6 +88,15 @@ func (r *NamespaceRemover) Run(ctx context.Context) error {

removalSteps := []steps.Step{}
for _, ns := range r.config.Namespaces {
// Check that the namespace exists.
_, err := r.kubeClient.GetNamespace(ctx, ns)
if k8serrors.IsNotFound(err) {
r.l.Infof("Namespace '%s' does not exist", ns)
fmt.Fprint(os.Stdout, output.Warn("Namespace (%s) does not exist, skipping..", ns))
continue
} else if err != nil {
return errors.Join(err, errors.New("failed to get namespace"))
}
removalSteps = append(removalSteps, NewRemoveNamespaceSteps(ns, r.config.KeepNamespace, r.kubeClient)...)
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/kubernetes/database_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (k *Kubernetes) DeleteDatabaseClusters(ctx context.Context, namespace strin
return true, nil
}
for _, cluster := range list.Items {
if err := k.DeleteDatabaseCluster(ctx, cluster.GetNamespace(), cluster.GetName()); err != nil {
if err := k.DeleteDatabaseCluster(ctx, cluster.GetNamespace(), cluster.GetName()); ctrlclient.IgnoreNotFound(err) != nil {
return false, err
}
}
Expand Down

0 comments on commit 9e649a9

Please sign in to comment.