Skip to content

Commit

Permalink
feat(autok3s): add --k3s-version flag
Browse files Browse the repository at this point in the history
Signed-off-by: Jason-ZW <zhenyang@rancher.com>
  • Loading branch information
rancher-sy-bot committed Sep 25, 2020
1 parent 854199d commit 3e6ba36
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 9 deletions.
15 changes: 8 additions & 7 deletions pkg/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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\""
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}
}
Expand All @@ -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
}
}
Expand Down Expand Up @@ -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
}
}
Expand All @@ -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
}
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/providers/alibaba/alibaba.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -65,6 +66,7 @@ func NewProvider() *Alibaba {
UI: ui,
Repo: repo,
CloudControllerManager: cloudControllerManager,
K3sVersion: k3sVersion,
},
Options: alibaba.Options{
DiskCategory: diskCategory,
Expand Down
7 changes: 7 additions & 0 deletions pkg/providers/alibaba/flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions pkg/types/autok3s.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 3e6ba36

Please # to comment.