Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI now cleans up etcd pvc volume when using k8s or eks distros #17

Open
wants to merge 1 commit into
base: develop_bkp
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion cmd/vclusterctl/cmd/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package cmd
import (
"context"
"fmt"
"github.com/loft-sh/vcluster/pkg/util/translate"
"os/exec"

"github.com/loft-sh/vcluster/pkg/util/translate"

"github.com/loft-sh/vcluster/cmd/vclusterctl/cmd/app/localkubernetes"
"github.com/loft-sh/vcluster/cmd/vclusterctl/cmd/find"
"k8s.io/client-go/rest"
Expand Down Expand Up @@ -114,6 +115,8 @@ func (cmd *DeleteCmd) Run(cobraCmd *cobra.Command, args []string) error {
// try to delete the pvc
if !cmd.KeepPVC && !cmd.DeleteNamespace {
pvcName := fmt.Sprintf("data-%s-0", args[0])
pvcNameForK8sAndEks := fmt.Sprintf("data-%s-etcd-0", args[0])

client, err := kubernetes.NewForConfig(cmd.restConfig)
if err != nil {
return err
Expand All @@ -127,6 +130,16 @@ func (cmd *DeleteCmd) Run(cobraCmd *cobra.Command, args []string) error {
} else {
cmd.log.Donef("Successfully deleted virtual cluster pvc %s in namespace %s", pvcName, cmd.Namespace)
}

// Deleting PVC for K8s and eks distro as well.
err = client.CoreV1().PersistentVolumeClaims(cmd.Namespace).Delete(context.Background(), pvcNameForK8sAndEks, metav1.DeleteOptions{})
if err != nil {
if !kerrors.IsNotFound(err) {
return errors.Wrap(err, "delete pvc")
}
} else {
cmd.log.Donef("Successfully deleted virtual cluster pvc %s in namespace %s", pvcName, cmd.Namespace)
}
}

// check if there are any other vclusters in the namespace you are deleting vcluster in.
Expand Down