From 3e6ba36502b7e3d5399d74c82ad0661ebd7eb1ea Mon Sep 17 00:00:00 2001 From: Jason-ZW Date: Wed, 23 Sep 2020 13:26:07 +0800 Subject: [PATCH] feat(autok3s): add --k3s-version flag Signed-off-by: Jason-ZW --- pkg/cluster/cluster.go | 15 ++++++++------- pkg/providers/alibaba/alibaba.go | 2 ++ pkg/providers/alibaba/flag.go | 7 +++++++ pkg/types/autok3s.go | 4 ++-- 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/pkg/cluster/cluster.go b/pkg/cluster/cluster.go index 78a9f436..7ff99e55 100644 --- a/pkg/cluster/cluster.go +++ b/pkg/cluster/cluster.go @@ -25,8 +25,8 @@ import ( ) var ( - initCommand = "curl -sLS %s | %s INSTALL_K3S_CHANNEL=latest INSTALL_K3S_REGISTRIES='%s' K3S_TOKEN='%s' INSTALL_K3S_EXEC='server %s --tls-san %s %s' sh -\n" - joinCommand = "curl -sLS %s | %s INSTALL_K3S_CHANNEL=latest INSTALL_K3S_REGISTRIES='%s' K3S_URL='https://%s:6443' K3S_TOKEN='%s' INSTALL_K3S_EXEC='%s' sh -\n" + initCommand = "curl -sLS %s | %s INSTALL_K3S_REGISTRIES='%s' K3S_TOKEN='%s' INSTALL_K3S_EXEC='server %s --tls-san %s %s' INSTALL_K3S_VERSION='%s' sh -\n" + joinCommand = "curl -sLS %s | %s INSTALL_K3S_REGISTRIES='%s' K3S_URL='https://%s:6443' K3S_TOKEN='%s' INSTALL_K3S_EXEC='%s' INSTALL_K3S_VERSION='%s' sh -\n" catCfgCommand = "cat /etc/rancher/k3s/k3s.yaml" dockerCommand = "curl https://get.docker.com | VERSION=19.03 sh -s - %s\n" deployUICommand = "echo \"%s\" > \"%s/ui.yaml\"" @@ -514,7 +514,7 @@ func initMaster(k3sScript, k3sMirror, dockerMirror, ip, extraArgs string, cluste if _, err := execute(&hosts.Host{Node: master}, fmt.Sprintf(initCommand, k3sScript, k3sMirror, cluster.Registries, cluster.Token, "--cluster-init", ip, - strings.TrimSpace(extraArgs)), false); err != nil { + strings.TrimSpace(extraArgs), cluster.K3sVersion), false); err != nil { return err } @@ -542,7 +542,7 @@ func initAdditionalMaster(wg *sync.WaitGroup, errChan chan error, k3sScript, k3s if _, err := execute(&hosts.Host{Node: master}, fmt.Sprintf(joinCommand, k3sScript, k3sMirror, cluster.Registries, ip, cluster.Token, - strings.TrimSpace(extraArgs)), false); err != nil { + strings.TrimSpace(extraArgs), cluster.K3sVersion), false); err != nil { errChan <- err } } @@ -564,7 +564,7 @@ func initWorker(wg *sync.WaitGroup, errChan chan error, k3sScript, k3sMirror, do if _, err := execute(&hosts.Host{Node: worker}, fmt.Sprintf(joinCommand, k3sScript, k3sMirror, cluster.Registries, cluster.URL, cluster.Token, - strings.TrimSpace(extraArgs)), false); err != nil { + strings.TrimSpace(extraArgs), cluster.K3sVersion), false); err != nil { errChan <- err } } @@ -608,7 +608,7 @@ func joinMaster(wg *sync.WaitGroup, errChan chan error, noFlannel bool, k3sScrip // for now, use the workerCommand to join the additional master server node. if _, err := execute(&hosts.Host{Node: full}, fmt.Sprintf(joinCommand, k3sScript, k3sMirror, merged.Registries, merged.URL, merged.Token, - strings.TrimSpace(extraArgs)), false); err != nil { + strings.TrimSpace(extraArgs), merged.K3sVersion), false); err != nil { errChan <- err } } @@ -629,7 +629,8 @@ func joinWorker(wg *sync.WaitGroup, errChan chan error, k3sScript, k3sMirror, do } if _, err := execute(&hosts.Host{Node: full}, - fmt.Sprintf(joinCommand, k3sScript, k3sMirror, merged.Registries, merged.URL, merged.Token, strings.TrimSpace(extraArgs)), false); err != nil { + fmt.Sprintf(joinCommand, k3sScript, k3sMirror, merged.Registries, merged.URL, merged.Token, + strings.TrimSpace(extraArgs), merged.K3sVersion), false); err != nil { errChan <- err } } diff --git a/pkg/providers/alibaba/alibaba.go b/pkg/providers/alibaba/alibaba.go index b5c49a7f..b53c7f81 100644 --- a/pkg/providers/alibaba/alibaba.go +++ b/pkg/providers/alibaba/alibaba.go @@ -23,6 +23,7 @@ import ( ) const ( + k3sVersion = "v1.19.2+k3s1" accessKeyID = "access-key" accessKeySecret = "access-secret" imageID = "ubuntu_18_04_x64_20G_alibase_20200618.vhd" @@ -65,6 +66,7 @@ func NewProvider() *Alibaba { UI: ui, Repo: repo, CloudControllerManager: cloudControllerManager, + K3sVersion: k3sVersion, }, Options: alibaba.Options{ DiskCategory: diskCategory, diff --git a/pkg/providers/alibaba/flag.go b/pkg/providers/alibaba/flag.go index f11eb7a3..d3c561cc 100644 --- a/pkg/providers/alibaba/flag.go +++ b/pkg/providers/alibaba/flag.go @@ -372,6 +372,13 @@ func (p *Alibaba) sharedFlags() []types.Flag { Usage: "Used to specify the maximum out flow of the instance internet", Required: true, }, + { + Name: "k3s-version", + P: &p.K3sVersion, + V: p.K3sVersion, + Usage: "Used to specify the version of k3s cluster", + Required: true, + }, { Name: "cloud-controller-manager", P: &p.CloudControllerManager, diff --git a/pkg/types/autok3s.go b/pkg/types/autok3s.go index a69a3de5..8ea58756 100644 --- a/pkg/types/autok3s.go +++ b/pkg/types/autok3s.go @@ -26,6 +26,7 @@ type Metadata struct { WorkerExtraArgs string `json:"worker-extra-args,omitempty" yaml:"worker-extra-args,omitempty"` Registries string `json:"registries,omitempty" yaml:"registries,omitempty"` DataStore string `json:"datastore,omitempty" yaml:"datastore,omitempty"` + K3sVersion string `json:"k3s-version,omitempty" yaml:"k3s-version,omitempty"` } type Status struct { @@ -55,8 +56,7 @@ type SSH struct { SSHCert string `json:"ssh-cert,omitempty" yaml:"ssh-cert,omitempty"` SSHCertPath string `json:"ssh-cert-path,omitempty" yaml:"ssh-cert-path,omitempty"` SSHKeyPassphrase string `json:"ssh-key-passphrase,omitempty" yaml:"ssh-key-passphrase,omitempty"` - - SSHAgentAuth bool `json:"ssh-agent-auth,omitempty" yaml:"ssh-agent-auth,omitempty" ` + SSHAgentAuth bool `json:"ssh-agent-auth,omitempty" yaml:"ssh-agent-auth,omitempty" ` } type Flag struct {