Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【Optimize】optimize kubernetes util function #808

Merged
merged 4 commits into from
Apr 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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