Skip to content

Commit

Permalink
feat(autok3s): add --k3s-install-script 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 Dec 18, 2020
1 parent 180fa43 commit 33113cb
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 28 deletions.
4 changes: 0 additions & 4 deletions pkg/cluster/cluster.go
Expand Up @@ -30,10 +30,6 @@ import (
"k8s.io/kubectl/pkg/scheme"
)

var (
DefaultScript = "http://rancher-mirror.cnrancher.com/k3s/k3s-install.sh"
)

var (
logger *logrus.Logger
initCommand = "curl -sLS %s | %s K3S_TOKEN='%s' INSTALL_K3S_EXEC='server %s --tls-san %s %s' %s sh -"
Expand Down
3 changes: 2 additions & 1 deletion pkg/providers/alibaba/alibaba.go
Expand Up @@ -31,6 +31,7 @@ import (
const (
k3sVersion = ""
k3sChannel = "stable"
k3sInstallScript = "http://rancher-mirror.cnrancher.com/k3s/k3s-install.sh"
accessKeyID = "access-key"
accessKeySecret = "access-secret"
imageID = "ubuntu_18_04_x64_20G_alibase_20200618.vhd"
Expand Down Expand Up @@ -101,6 +102,7 @@ func NewProvider() *Alibaba {
CloudControllerManager: cloudControllerManager,
K3sVersion: k3sVersion,
K3sChannel: k3sChannel,
InstallScript: k3sInstallScript,
},
Options: alibaba.Options{
DiskCategory: diskCategory,
Expand Down Expand Up @@ -1235,7 +1237,6 @@ func (p *Alibaba) generateInstance(fn checkFun, ssh *types.SSH) (*types.Cluster,
return nil, err
}

c.InstallScript = cluster.DefaultScript
c.Mirror = k3sMirror
c.DockerMirror = dockerMirror

Expand Down
9 changes: 9 additions & 0 deletions pkg/providers/alibaba/flag.go
Expand Up @@ -295,6 +295,9 @@ func (p *Alibaba) overwriteMetadata(matched *types.Cluster) {
if p.K3sVersion == "" {
p.K3sVersion = matched.K3sVersion
}
if p.InstallScript == "" {
p.InstallScript = matched.InstallScript
}
if p.Registry == "" {
p.Registry = matched.Registry
}
Expand Down Expand Up @@ -402,6 +405,12 @@ func (p *Alibaba) sharedFlags() []types.Flag {
V: p.K3sChannel,
Usage: "Used to specify the release channel of k3s. e.g.(stable, latest, or i.e. v1.18)",
},
{
Name: "k3s-install-script",
P: &p.InstallScript,
V: p.InstallScript,
Usage: "Change the default upstream k3s install script address",
},
{
Name: "cloud-controller-manager",
P: &p.CloudControllerManager,
Expand Down
9 changes: 9 additions & 0 deletions pkg/providers/native/flag.go
Expand Up @@ -171,6 +171,12 @@ func (p *Native) sharedFlags() []types.Flag {
V: p.K3sChannel,
Usage: "Used to specify the release channel of k3s. e.g.(stable, latest, or i.e. v1.18)",
},
{
Name: "k3s-install-script",
P: &p.InstallScript,
V: p.InstallScript,
Usage: "Change the default upstream k3s install script address",
},
{
Name: "master-extra-args",
P: &p.MasterExtraArgs,
Expand Down Expand Up @@ -234,6 +240,9 @@ func (p *Native) overwriteMetadata(matched *types.Cluster) {
if p.K3sVersion == "" {
p.K3sVersion = matched.K3sVersion
}
if p.InstallScript == "" {
p.InstallScript = matched.InstallScript
}
if p.Registry == "" {
p.Registry = matched.Registry
}
Expand Down
29 changes: 15 additions & 14 deletions pkg/providers/native/native.go
Expand Up @@ -19,12 +19,13 @@ import (
)

const (
k3sVersion = ""
k3sChannel = "stable"
master = "0"
worker = "0"
ui = false
repo = "https://apphub.aliyuncs.com"
k3sVersion = ""
k3sChannel = "stable"
k3sInstallScript = "http://rancher-mirror.cnrancher.com/k3s/k3s-install.sh"
master = "0"
worker = "0"
ui = false
repo = "https://apphub.aliyuncs.com"
)

// ProviderName is the name of this provider.
Expand Down Expand Up @@ -55,13 +56,14 @@ func init() {
func NewProvider() *Native {
return &Native{
Metadata: types.Metadata{
Provider: ProviderName,
Master: master,
Worker: worker,
UI: ui,
Repo: repo,
K3sVersion: k3sVersion,
K3sChannel: k3sChannel,
Provider: ProviderName,
Master: master,
Worker: worker,
UI: ui,
Repo: repo,
K3sVersion: k3sVersion,
K3sChannel: k3sChannel,
InstallScript: k3sInstallScript,
},
Options: native.Options{
MasterIps: "",
Expand Down Expand Up @@ -121,7 +123,6 @@ func (p *Native) CreateK3sCluster(ssh *types.SSH) (err error) {
return err
}

c.InstallScript = cluster.DefaultScript
c.Mirror = k3sMirror
c.DockerMirror = dockerMirror

Expand Down
9 changes: 9 additions & 0 deletions pkg/providers/tencent/flag.go
Expand Up @@ -292,6 +292,9 @@ func (p *Tencent) overwriteMetadata(matched *types.Cluster) {
if p.K3sVersion == "" {
p.K3sVersion = matched.K3sVersion
}
if p.InstallScript == "" {
p.InstallScript = matched.InstallScript
}
if p.Registry == "" {
p.Registry = matched.Registry
}
Expand Down Expand Up @@ -405,6 +408,12 @@ func (p *Tencent) sharedFlags() []types.Flag {
V: p.K3sChannel,
Usage: "Used to specify the release channel of k3s. e.g.(stable, latest, or i.e. v1.18)",
},
{
Name: "k3s-install-script",
P: &p.InstallScript,
V: p.InstallScript,
Usage: "Change the default upstream k3s install script address",
},
{
Name: "cloud-controller-manager",
P: &p.CloudControllerManager,
Expand Down
17 changes: 9 additions & 8 deletions pkg/providers/tencent/tencent.go
Expand Up @@ -34,6 +34,7 @@ import (
const (
k3sVersion = ""
k3sChannel = "stable"
k3sInstallScript = "http://rancher-mirror.cnrancher.com/k3s/k3s-install.sh"
secretID = "secret-id"
secretKey = "secret-key"
imageID = "img-pi0ii46r" /* Ubuntu Server 18.04.1 LTS x64 */
Expand Down Expand Up @@ -93,13 +94,14 @@ func init() {
func NewProvider() *Tencent {
return &Tencent{
Metadata: types.Metadata{
Provider: ProviderName,
Master: master,
Worker: worker,
UI: ui,
Repo: repo,
K3sVersion: k3sVersion,
K3sChannel: k3sChannel,
Provider: ProviderName,
Master: master,
Worker: worker,
UI: ui,
Repo: repo,
K3sVersion: k3sVersion,
K3sChannel: k3sChannel,
InstallScript: k3sInstallScript,
},
Options: tencent.Options{
ImageID: imageID,
Expand Down Expand Up @@ -606,7 +608,6 @@ func (p *Tencent) generateInstance(fn checkFun, ssh *types.SSH) (*types.Cluster,
return nil, err
}

c.InstallScript = cluster.DefaultScript
c.Mirror = k3sMirror
c.DockerMirror = dockerMirror

Expand Down
2 changes: 1 addition & 1 deletion pkg/types/autok3s.go
Expand Up @@ -26,7 +26,7 @@ type Metadata struct {
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"`
InstallScript string `json:"installScript,omitempty" yaml:"installScript,omitempty"`
Mirror string `json:"mirror,omitempty" yaml:"mirror,omitempty"`
DockerMirror string `json:"dockerMirror,omitempty" yaml:"dockerMirror,omitempty"`
Network string `json:"network,omitempty" yaml:"network,omitempty"`
Expand Down

0 comments on commit 33113cb

Please sign in to comment.