Skip to content

Commit

Permalink
feat(autok3s): add --k3s-channel 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 Oct 15, 2020
1 parent a4cb3c1 commit ee0c87b
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 11 deletions.
21 changes: 14 additions & 7 deletions pkg/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ import (
)

var (
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"
initCommand = "curl -sLS %s | %s INSTALL_K3S_REGISTRIES='%s' K3S_TOKEN='%s' INSTALL_K3S_EXEC='server %s --tls-san %s %s' %s sh -\n"
joinCommand = "curl -sLS %s | %s INSTALL_K3S_REGISTRIES='%s' K3S_URL='https://%s:6443' K3S_TOKEN='%s' INSTALL_K3S_EXEC='%s' %s sh -\n"
catCfgCommand = "cat /etc/rancher/k3s/k3s.yaml"
dockerCommand = "curl http://rancher-mirror.cnrancher.com/autok3s/docker-install.sh | sh -s - %s\n"
deployUICommand = "echo \"%s\" | base64 -d > \"%s/ui.yaml\""
Expand Down Expand Up @@ -536,7 +536,7 @@ func initMaster(k3sScript, k3sMirror, dockerMirror, ip, extraArgs string, cluste

if _, err := execute(&hosts.Host{Node: master}, false,
[]string{fmt.Sprintf(initCommand, k3sScript, k3sMirror, cluster.Registries, cluster.Token, "--cluster-init", ip,
strings.TrimSpace(extraArgs), cluster.K3sVersion)}); err != nil {
strings.TrimSpace(extraArgs), genK3sVersion(cluster.K3sVersion, cluster.K3sChannel))}); err != nil {
return err
}

Expand All @@ -561,7 +561,7 @@ func initAdditionalMaster(k3sScript, k3sMirror, dockerMirror, ip, extraArgs stri

if _, err := execute(&hosts.Host{Node: master}, false,
[]string{fmt.Sprintf(joinCommand, k3sScript, k3sMirror, cluster.Registries, ip, cluster.Token,
strings.TrimSpace(sortedExtraArgs), cluster.K3sVersion)}); err != nil {
strings.TrimSpace(sortedExtraArgs), genK3sVersion(cluster.K3sVersion, cluster.K3sChannel))}); err != nil {
return err
}

Expand All @@ -583,7 +583,7 @@ func initWorker(wg *sync.WaitGroup, errChan chan error, k3sScript, k3sMirror, do

if _, err := execute(&hosts.Host{Node: worker}, false,
[]string{fmt.Sprintf(joinCommand, k3sScript, k3sMirror, cluster.Registries, cluster.IP, cluster.Token,
strings.TrimSpace(sortedExtraArgs), cluster.K3sVersion)}); err != nil {
strings.TrimSpace(sortedExtraArgs), genK3sVersion(cluster.K3sVersion, cluster.K3sChannel))}); err != nil {
errChan <- err
}

Expand Down Expand Up @@ -618,7 +618,7 @@ func joinMaster(k3sScript, k3sMirror, dockerMirror,
// for now, use the workerCommand to join the additional master server node.
if _, err := execute(&hosts.Host{Node: full}, false,
[]string{fmt.Sprintf(joinCommand, k3sScript, k3sMirror, merged.Registries, merged.IP, merged.Token,
strings.TrimSpace(sortedExtraArgs), merged.K3sVersion)}); err != nil {
strings.TrimSpace(sortedExtraArgs), genK3sVersion(merged.K3sVersion, merged.K3sChannel))}); err != nil {
return err
}

Expand All @@ -640,7 +640,7 @@ func joinWorker(wg *sync.WaitGroup, errChan chan error, k3sScript, k3sMirror, do

if _, err := execute(&hosts.Host{Node: full}, false,
[]string{fmt.Sprintf(joinCommand, k3sScript, k3sMirror, merged.Registries, merged.IP, merged.Token,
strings.TrimSpace(sortedExtraArgs), merged.K3sVersion)}); err != nil {
strings.TrimSpace(sortedExtraArgs), genK3sVersion(merged.K3sVersion, merged.K3sChannel))}); err != nil {
errChan <- err
}

Expand Down Expand Up @@ -776,3 +776,10 @@ func deleteClusterFromState(name string, provider string) ([]types.Cluster, erro

return converts, nil
}

func genK3sVersion(version, channel string) string {
if version != "" {
return fmt.Sprintf("INSTALL_K3S_VERSION='%s'", version)
}
return fmt.Sprintf("INSTALL_K3S_CHANNEL='%s'", channel)
}
4 changes: 3 additions & 1 deletion pkg/providers/alibaba/alibaba.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ import (
)

const (
k3sVersion = "v1.19.2+k3s1"
k3sVersion = ""
k3sChannel = "v1.18"
accessKeyID = "access-key"
accessKeySecret = "access-secret"
imageID = "ubuntu_18_04_x64_20G_alibase_20200618.vhd"
Expand Down Expand Up @@ -88,6 +89,7 @@ func NewProvider() *Alibaba {
Repo: repo,
CloudControllerManager: cloudControllerManager,
K3sVersion: k3sVersion,
K3sChannel: k3sChannel,
},
Options: alibaba.Options{
DiskCategory: diskCategory,
Expand Down
9 changes: 8 additions & 1 deletion pkg/providers/alibaba/flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,14 @@ func (p *Alibaba) sharedFlags() []types.Flag {
Name: "k3s-version",
P: &p.K3sVersion,
V: p.K3sVersion,
Usage: "Used to specify the version of k3s cluster",
Usage: "Used to specify the version of k3s cluster, overrides k3s-channel",
Required: true,
},
{
Name: "k3s-channel",
P: &p.K3sChannel,
V: p.K3sChannel,
Usage: "Used to specify the release channel of k3s. e.g.(stable, latest, or i.e. v1.18)",
Required: true,
},
{
Expand Down
9 changes: 8 additions & 1 deletion pkg/providers/native/flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,14 @@ func (p *Native) sharedFlags() []types.Flag {
Name: "k3s-version",
P: &p.K3sVersion,
V: p.K3sVersion,
Usage: "Used to specify the version of k3s cluster",
Usage: "Used to specify the version of k3s cluster, overrides k3s-channel",
Required: true,
},
{
Name: "k3s-channel",
P: &p.K3sChannel,
V: p.K3sChannel,
Usage: "Used to specify the release channel of k3s. e.g.(stable, latest, or i.e. v1.18)",
Required: true,
},
{
Expand Down
4 changes: 3 additions & 1 deletion pkg/providers/native/native.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ import (
)

const (
k3sVersion = "v1.19.2+k3s1"
k3sVersion = ""
k3sChannel = "v1.18"
master = "0"
worker = "0"
ui = false
Expand Down Expand Up @@ -61,6 +62,7 @@ func NewProvider() *Native {
UI: ui,
Repo: repo,
K3sVersion: k3sVersion,
K3sChannel: k3sChannel,
},
Options: native.Options{
MasterIps: "",
Expand Down
1 change: 1 addition & 0 deletions pkg/types/autok3s.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type Metadata struct {
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"`
K3sChannel string `json:"k3s-channel,omitempty" yaml:"k3s-channel,omitempty"`
InstallScript string `json:"installScript,omitempty" yaml:"installScript,omitempty" default:"https://get.k3s.io"`
Mirror string `json:"mirror,omitempty" yaml:"mirror,omitempty"`
DockerMirror string `json:"dockerMirror,omitempty" yaml:"dockerMirror,omitempty"`
Expand Down

0 comments on commit ee0c87b

Please sign in to comment.