From 3b028c05ac5fdca8f3a5de27d84acda67b570123 Mon Sep 17 00:00:00 2001 From: JameKeal <70508195+JameKeal@users.noreply.github.com> Date: Fri, 27 Aug 2021 16:24:48 +0800 Subject: [PATCH] =?UTF-8?q?optimize=20yurttunnel=20server=20deployment=20a?= =?UTF-8?q?nd=20yurt=20app=20manager=20deployment=E2=80=A6=20(#435)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * optimize yurttunnel server deployment and yurt app manager deployment yaml for system arch, not write for amd64 forever * Add a new parameter for yurtctl to control the system architecture * help information describe more correct --- pkg/yurtctl/cmd/convert/convert.go | 28 +++++++++++++++---- .../constants/yurt-app-manager-tmpl.go | 2 +- .../constants/yurt-tunnel-server-tmpl.go | 2 +- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/pkg/yurtctl/cmd/convert/convert.go b/pkg/yurtctl/cmd/convert/convert.go index 89005ebcb64..39f21590761 100644 --- a/pkg/yurtctl/cmd/convert/convert.go +++ b/pkg/yurtctl/cmd/convert/convert.go @@ -22,13 +22,14 @@ import ( "strings" "time" + "github.com/spf13/cobra" + "github.com/spf13/pflag" + "github.com/openyurtio/openyurt/pkg/projectinfo" "github.com/openyurtio/openyurt/pkg/yurtctl/constants" "github.com/openyurtio/openyurt/pkg/yurtctl/lock" kubeutil "github.com/openyurtio/openyurt/pkg/yurtctl/util/kubernetes" strutil "github.com/openyurtio/openyurt/pkg/yurtctl/util/strings" - "github.com/spf13/cobra" - "github.com/spf13/pflag" v1 "k8s.io/api/core/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" @@ -76,6 +77,7 @@ type ConvertOptions struct { kubeConfigPath string EnableAppManager bool YurtAppManagerImage string + SystemArchitecture string yurtAppManagerClientSet dynamic.Interface } @@ -141,6 +143,8 @@ func NewConvertCmd() *cobra.Command { cmd.Flags().String("yurt-app-manager-image", "openyurt/yurt-app-manager:v0.4.0", "The yurt-app-manager image.") + cmd.Flags().String("system-architecture", "amd64", + "The system architecture of cloud nodes.") return cmd } @@ -230,6 +234,12 @@ func (co *ConvertOptions) Complete(flags *pflag.FlagSet) error { } co.KubeadmConfPath = kcp + sa, err := flags.GetString("system-architecture") + if err != nil { + return err + } + co.SystemArchitecture = sa + // parse kubeconfig and generate the clientset co.clientSet, err = kubeutil.GenClientSet(flags) if err != nil { @@ -362,7 +372,8 @@ func (co *ConvertOptions) RunConvert() (err error) { if co.DeployTunnel { if err = deployYurttunnelServer(co.clientSet, co.CloudNodes, - co.YurttunnelServerImage); err != nil { + co.YurttunnelServerImage, + co.SystemArchitecture); err != nil { err = fmt.Errorf("fail to deploy the yurt-tunnel-server: %s", err) return } @@ -388,7 +399,8 @@ func (co *ConvertOptions) RunConvert() (err error) { if co.EnableAppManager { if err = deployYurtAppManager(co.clientSet, co.YurtAppManagerImage, - co.yurtAppManagerClientSet); err != nil { + co.yurtAppManagerClientSet, + co.SystemArchitecture); err != nil { err = fmt.Errorf("fail to deploy the yurt-app-manager: %s", err) return } @@ -428,7 +440,8 @@ func (co *ConvertOptions) RunConvert() (err error) { func deployYurtAppManager( client *kubernetes.Clientset, yurtappmanagerImage string, - yurtAppManagerClient dynamic.Interface) error { + yurtAppManagerClient dynamic.Interface, + systemArchitecture string) error { // 1.create the YurtAppManagerCustomResourceDefinition // 1.1 nodepool @@ -483,6 +496,7 @@ func deployYurtAppManager( constants.YurtAppManagerDeployment, map[string]string{ "image": yurtappmanagerImage, + "arch": systemArchitecture, "edgeWorkerLabel": projectinfo.GetEdgeWorkerLabelKey()}); err != nil { return err } @@ -505,7 +519,8 @@ func deployYurtAppManager( func deployYurttunnelServer( client *kubernetes.Clientset, cloudNodes []string, - yurttunnelServerImage string) error { + yurttunnelServerImage string, + systemArchitecture string) error { // 1. create the ClusterRole if err := kubeutil.CreateClusterRoleFromYaml(client, constants.YurttunnelServerClusterRole); err != nil { @@ -549,6 +564,7 @@ func deployYurttunnelServer( constants.YurttunnelServerDeployment, map[string]string{ "image": yurttunnelServerImage, + "arch": systemArchitecture, "edgeWorkerLabel": projectinfo.GetEdgeWorkerLabelKey()}); err != nil { return err } diff --git a/pkg/yurtctl/constants/yurt-app-manager-tmpl.go b/pkg/yurtctl/constants/yurt-app-manager-tmpl.go index 120205e2329..559f342649a 100644 --- a/pkg/yurtctl/constants/yurt-app-manager-tmpl.go +++ b/pkg/yurtctl/constants/yurt-app-manager-tmpl.go @@ -664,7 +664,7 @@ spec: readOnly: true nodeSelector: openyurt.io/is-edge-worker: "false" - beta.kubernetes.io/arch: amd64 + beta.kubernetes.io/arch: {{.arch}} beta.kubernetes.io/os: linux priorityClassName: system-node-critical terminationGracePeriodSeconds: 10 diff --git a/pkg/yurtctl/constants/yurt-tunnel-server-tmpl.go b/pkg/yurtctl/constants/yurt-tunnel-server-tmpl.go index 84dd14fd634..e65d22e66ad 100644 --- a/pkg/yurtctl/constants/yurt-tunnel-server-tmpl.go +++ b/pkg/yurtctl/constants/yurt-tunnel-server-tmpl.go @@ -186,7 +186,7 @@ spec: tolerations: - operator: "Exists" nodeSelector: - beta.kubernetes.io/arch: amd64 + beta.kubernetes.io/arch: {{.arch}} beta.kubernetes.io/os: linux {{.edgeWorkerLabel}}: "false" containers: