Skip to content

Commit

Permalink
Merge pull request #1311 from Cloud-Hacks/add-cm-delete-option
Browse files Browse the repository at this point in the history
Added option to delete config map for vcluster delete
  • Loading branch information
Thomas Kosiewski authored Oct 23, 2023
2 parents 9b2ced7 + 2f4c5b5 commit 01843db
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions cmd/vclusterctl/cmd/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type DeleteCmd struct {
Wait bool
KeepPVC bool
DeleteNamespace bool
DeleteConfigMap bool
AutoDeleteNamespace bool

rawConfig *clientcmdapi.Config
Expand Down Expand Up @@ -74,6 +75,7 @@ vcluster delete test --namespace test

cobraCmd.Flags().StringVar(&cmd.Project, "project", "", "[PRO] The pro project the vcluster is in")
cobraCmd.Flags().BoolVar(&cmd.Wait, "wait", true, "If enabled, vcluster will wait until the vcluster is deleted")
cobraCmd.Flags().BoolVar(&cmd.DeleteConfigMap, "delete-configmap", false, "If enabled, vCluster will delete the ConfigMap of the vCluster")
cobraCmd.Flags().BoolVar(&cmd.KeepPVC, "keep-pvc", false, "If enabled, vcluster will not delete the persistent volume claim of the vcluster")
cobraCmd.Flags().BoolVar(&cmd.DeleteNamespace, "delete-namespace", false, "If enabled, vcluster will delete the namespace of the vcluster. In the case of multi-namespace mode, will also delete all other namespaces created by vcluster")
cobraCmd.Flags().BoolVar(&cmd.AutoDeleteNamespace, "auto-delete-namespace", true, "If enabled, vcluster will delete the namespace of the vcluster if it was created by vclusterctl. In the case of multi-namespace mode, will also delete all other namespaces created by vcluster")
Expand Down Expand Up @@ -167,6 +169,26 @@ func (cmd *DeleteCmd) Run(cobraCmd *cobra.Command, args []string) error {
}
}

// try to delete the ConfigMap
if cmd.DeleteConfigMap {
client, err := kubernetes.NewForConfig(cmd.restConfig)
if err != nil {
return err
}

configMapName := fmt.Sprintf("configmap-%s", args[0])

// Attempt to delete the ConfigMap
err = client.CoreV1().ConfigMaps(cmd.Namespace).Delete(ctx, configMapName, metav1.DeleteOptions{})
if err != nil {
if !kerrors.IsNotFound(err) {
return errors.Wrap(err, "delete configmap")
}
} else {
cmd.log.Donef("Successfully deleted ConfigMap %s in namespace %s", configMapName, cmd.Namespace)
}
}

// check if there are any other vclusters in the namespace you are deleting vcluster in.
vClusters, _, err := find.ListVClusters(cobraCmd.Context(), nil, cmd.Context, "", cmd.Namespace, "", cmd.log)
if err != nil {
Expand Down

0 comments on commit 01843db

Please sign in to comment.