From 794b44835f98df719f2b1186b2ad90a11f9a35b0 Mon Sep 17 00:00:00 2001 From: wangpengfei <274878379@qq.com> Date: 星期四, 08 六月 2023 20:28:11 +0800 Subject: [PATCH] fix --- src/k8s/delete.go | 23 ++++++++++------------- 1 files changed, 10 insertions(+), 13 deletions(-) diff --git a/src/k8s/delete.go b/src/k8s/delete.go index d63af12..8d99f16 100644 --- a/src/k8s/delete.go +++ b/src/k8s/delete.go @@ -13,14 +13,11 @@ "k8s.io/client-go/tools/clientcmd" ) -var ( - replicas int32 = 3 - port int32 = 9081 - namespaces = []string{"guangsheng", "geruimi", "tongsheng"} - usedNodePorts = make(map[int32]bool) -) +func delete_test() { + var ( + namespaces = []string{"guangsheng", "geruimi", "tongsheng"} + ) -func main() { // 閰嶇疆 Kubernetes 闆嗙兢鐨� kubeconfig 璺緞 kubeconfig := flag.String("kubeconfig", filepath.Join(util.HomeDir(), ".kube", "config"), "kubeconfig file") flag.Parse() @@ -64,7 +61,7 @@ } // 鍒犻櫎 Namespace - err = deleteNamespace(clientset, namespace) + err = DeleteNamespace(Config{Client: clientset, NameSpace: namespace}) if err != nil { return err } @@ -109,18 +106,18 @@ } // deleteNamespace 鍒犻櫎鎸囧畾鐨� Namespace -func deleteNamespace(clientset *kubernetes.Clientset, namespace string) error { - fmt.Println("\033[1;37;40mDeleting Namespace:", namespace, "\033[0m") +func DeleteNamespace(config Config) error { + fmt.Println("\033[1;37;40mDeleting Namespace:", config.NameSpace, "\033[0m") - err := clientset.CoreV1().Namespaces().Delete(context.TODO(), namespace, metav1.DeleteOptions{}) + err := config.Client.CoreV1().Namespaces().Delete(context.TODO(), config.NameSpace, metav1.DeleteOptions{}) if err != nil { if errors.IsNotFound(err) { - fmt.Printf("Namespace %s not found\n", namespace) + fmt.Printf("Namespace %s not found\n", config.NameSpace) } else { return fmt.Errorf("failed to delete Namespace: %v", err) } } else { - fmt.Printf("Namespace %s deleted\n", namespace) + fmt.Printf("Namespace %s deleted\n", config.NameSpace) } return nil -- Gitblit v1.8.0