Skip to content

Commit

Permalink
【Optimize】optimize kubernetes util function (openyurtio#808)
Browse files Browse the repository at this point in the history
* add yurt-app-manager yurtappdaemon/yurtingress deploy and revert

* Revert "add yurt-app-manager yurtappdaemon/yurtingress deploy and revert"

This reverts commit ba28364.

* optimize kubernetes util func
  • Loading branch information
JameKeal committed May 16, 2022
1 parent 7a9a584 commit 851be2a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
4 changes: 4 additions & 0 deletions pkg/yurtctl/util/kubernetes/apply_addons.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ func DeployYurtAppManager(

// 7. create the Service
if err := CreateServiceFromYaml(client,
SystemNamespace,
constants.YurtAppManagerService); err != nil {
return err
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions pkg/yurtctl/util/kubernetes/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
}
Expand All @@ -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
Expand All @@ -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)
}

Expand Down

0 comments on commit 851be2a

Please sign in to comment.