From ee15d8bc047dfd4409b8ea6ad26c1bfd1871f1c1 Mon Sep 17 00:00:00 2001 From: JameKeal <413621396@qq.com> Date: Fri, 13 May 2022 18:32:26 +0800 Subject: [PATCH] uniform processCreateErr func to deal the resource create --- pkg/yurtctl/util/kubernetes/util.go | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/pkg/yurtctl/util/kubernetes/util.go b/pkg/yurtctl/util/kubernetes/util.go index 83c15186427..99c684fdaf7 100644 --- a/pkg/yurtctl/util/kubernetes/util.go +++ b/pkg/yurtctl/util/kubernetes/util.go @@ -185,11 +185,8 @@ func CreateDeployFromYaml(cliSet *kubernetes.Clientset, ns, dplyTmpl string, ctx if !ok { return errors.New("fail to assert Deployment") } - if _, err = cliSet.AppsV1().Deployments(ns).Create(context.Background(), dply, metav1.CreateOptions{}); err != nil { - return err - } - klog.V(4).Infof("the deployment/%s is deployed", dply.Name) - return nil + _, err = cliSet.AppsV1().Deployments(ns).Create(context.Background(), dply, metav1.CreateOptions{}) + return processCreateErr("deployment", dply.Name, err) } // CreateDaemonSetFromYaml creates the DaemonSet from the yaml template. @@ -214,11 +211,7 @@ func CreateDaemonSetFromYaml(cliSet *kubernetes.Clientset, ns, dsTmpl string, ct return fmt.Errorf("fail to assert daemonset: %v", err) } _, 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) - } - klog.V(4).Infof("daemonset/%s is created", ds.Name) - return nil + return processCreateErr("daemonset", ds.Name, err) } // CreateServiceFromYaml creates the Service from the yaml template.