From fea0f950d0fffae8af87e53161a31f4f1c063039 Mon Sep 17 00:00:00 2001 From: Afzal Ansari Date: Sun, 22 Oct 2023 18:05:07 +0000 Subject: [PATCH 1/2] Added option to delete config map for vcluster delete --- cmd/vclusterctl/cmd/delete.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/cmd/vclusterctl/cmd/delete.go b/cmd/vclusterctl/cmd/delete.go index 1a50b09a0..34f865881 100644 --- a/cmd/vclusterctl/cmd/delete.go +++ b/cmd/vclusterctl/cmd/delete.go @@ -36,6 +36,7 @@ type DeleteCmd struct { Wait bool KeepPVC bool DeleteNamespace bool + DeleteConfigMap bool AutoDeleteNamespace bool rawConfig *clientcmdapi.Config @@ -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 not delete the config map 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") @@ -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 { From 2f4c5b5a55f52fa3681d7b0ace8c001e56eb700f Mon Sep 17 00:00:00 2001 From: Afzal Ansari Date: Mon, 23 Oct 2023 10:31:12 +0000 Subject: [PATCH 2/2] modifies the info for cm deletion --- cmd/vclusterctl/cmd/delete.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cmd/vclusterctl/cmd/delete.go b/cmd/vclusterctl/cmd/delete.go index 34f865881..63dc56d0e 100644 --- a/cmd/vclusterctl/cmd/delete.go +++ b/cmd/vclusterctl/cmd/delete.go @@ -75,7 +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 not delete the config map of the vcluster") + 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") @@ -175,9 +175,9 @@ func (cmd *DeleteCmd) Run(cobraCmd *cobra.Command, args []string) error { 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 { @@ -187,7 +187,7 @@ func (cmd *DeleteCmd) Run(cobraCmd *cobra.Command, args []string) error { } 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)