From 851be2a866f290e951d0af62bcd26a33a87f791f Mon Sep 17 00:00:00 2001 From: JameKeal <70508195+JameKeal@users.noreply.github.com> Date: Mon, 18 Apr 2022 14:12:40 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90Optimize=E3=80=91optimize=20kubernetes?= =?UTF-8?q?=20util=20function=20(#808)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * add yurt-app-manager yurtappdaemon/yurtingress deploy and revert * Revert "add yurt-app-manager yurtappdaemon/yurtingress deploy and revert" This reverts commit ba28364ed6ba1093d05b6dbf40d5772a34e6574a. * optimize kubernetes util func --- pkg/yurtctl/util/kubernetes/apply_addons.go | 4 ++++ pkg/yurtctl/util/kubernetes/util.go | 8 ++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/pkg/yurtctl/util/kubernetes/apply_addons.go b/pkg/yurtctl/util/kubernetes/apply_addons.go index c643fa7b7d4..5c62bd787f9 100644 --- a/pkg/yurtctl/util/kubernetes/apply_addons.go +++ b/pkg/yurtctl/util/kubernetes/apply_addons.go @@ -106,6 +106,7 @@ func DeployYurtAppManager( // 7. create the Service if err := CreateServiceFromYaml(client, + SystemNamespace, constants.YurtAppManagerService); err != nil { return err } @@ -161,12 +162,14 @@ func DeployYurttunnelServer( // 4. create the Service if err := CreateServiceFromYaml(client, + SystemNamespace, constants.YurttunnelServerService); err != nil { return err } // 5. create the internal Service(type=ClusterIP) if err := CreateServiceFromYaml(client, + SystemNamespace, constants.YurttunnelServerInternalService); err != nil { return err } @@ -199,6 +202,7 @@ func DeployYurttunnelAgent( yurttunnelAgentImage string) error { // 1. Deploy the yurt-tunnel-agent DaemonSet if err := CreateDaemonSetFromYaml(client, + SystemNamespace, constants.YurttunnelAgentDaemonSet, map[string]string{ "image": yurttunnelAgentImage, diff --git a/pkg/yurtctl/util/kubernetes/util.go b/pkg/yurtctl/util/kubernetes/util.go index a4de554d807..2529898c20a 100644 --- a/pkg/yurtctl/util/kubernetes/util.go +++ b/pkg/yurtctl/util/kubernetes/util.go @@ -194,7 +194,7 @@ func CreateDeployFromYaml(cliSet *kubernetes.Clientset, ns, dplyTmpl string, ctx } // CreateDaemonSetFromYaml creates the DaemonSet from the yaml template. -func CreateDaemonSetFromYaml(cliSet *kubernetes.Clientset, dsTmpl string, ctx interface{}) error { +func CreateDaemonSetFromYaml(cliSet *kubernetes.Clientset, ns, dsTmpl string, ctx interface{}) error { var ytadstmp string var err error if ctx != nil { @@ -214,7 +214,7 @@ func CreateDaemonSetFromYaml(cliSet *kubernetes.Clientset, dsTmpl string, ctx in if !ok { return fmt.Errorf("fail to assert daemonset: %v", err) } - _, err = cliSet.AppsV1().DaemonSets(SystemNamespace).Create(context.Background(), ds, metav1.CreateOptions{}) + _, err = cliSet.AppsV1().DaemonSets(ns).Create(context.Background(), ds, metav1.CreateOptions{}) if err != nil { return fmt.Errorf("fail to create the daemonset/%s: %v", ds.Name, err) } @@ -223,7 +223,7 @@ func CreateDaemonSetFromYaml(cliSet *kubernetes.Clientset, dsTmpl string, ctx in } // CreateServiceFromYaml creates the Service from the yaml template. -func CreateServiceFromYaml(cliSet *kubernetes.Clientset, svcTmpl string) error { +func CreateServiceFromYaml(cliSet *kubernetes.Clientset, ns, svcTmpl string) error { obj, err := YamlToObject([]byte(svcTmpl)) if err != nil { return err @@ -232,7 +232,7 @@ func CreateServiceFromYaml(cliSet *kubernetes.Clientset, svcTmpl string) error { if !ok { return fmt.Errorf("fail to assert service: %v", err) } - _, err = cliSet.CoreV1().Services(SystemNamespace).Create(context.Background(), svc, metav1.CreateOptions{}) + _, err = cliSet.CoreV1().Services(ns).Create(context.Background(), svc, metav1.CreateOptions{}) return processCreateErr("service", svc.Name, err) }