Skip to content

Commit

Permalink
fix(autok3s): add --url 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 8, 2020
1 parent a03b18b commit 83554f6
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
14 changes: 8 additions & 6 deletions pkg/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func InitK3sCluster(cluster *types.Cluster) error {
return errors.New("[cluster] master node internal ip address can not be empty\n")
}

url := cluster.MasterNodes[0].InternalIPAddress[0]
cluster.URL = cluster.MasterNodes[0].InternalIPAddress[0]
publicIP := cluster.MasterNodes[0].PublicIPAddress[0]
masterExtraArgs := cluster.MasterExtraArgs
workerExtraArgs := cluster.WorkerExtraArgs
Expand Down Expand Up @@ -137,7 +137,7 @@ func InitK3sCluster(cluster *types.Cluster) error {
}

if _, err := execute(&hosts.Host{Node: worker},
fmt.Sprintf(workerCommand, k3sScript, k3sMirror, url, cluster.Token, extraArgs), true); err != nil {
fmt.Sprintf(workerCommand, k3sScript, k3sMirror, cluster.URL, cluster.Token, extraArgs), true); err != nil {
return err
}
}
Expand Down Expand Up @@ -229,11 +229,13 @@ func JoinK3sNode(merged, added *types.Cluster) error {
return errors.New("[cluster] k3s token can not be empty\n")
}

if len(merged.MasterNodes) <= 0 || len(merged.MasterNodes[0].InternalIPAddress) <= 0 {
return errors.New("[cluster] master node internal ip address can not be empty\n")
if merged.URL == "" {
if len(merged.MasterNodes) <= 0 || len(merged.MasterNodes[0].InternalIPAddress) <= 0 {
return errors.New("[cluster] master node internal ip address can not be empty\n")
}
merged.URL = merged.MasterNodes[0].InternalIPAddress[0]
}

url := merged.MasterNodes[0].InternalIPAddress[0]
workerNum := 0

// TODO: join master node will be added soon.
Expand All @@ -254,7 +256,7 @@ func JoinK3sNode(merged, added *types.Cluster) error {
}

if _, err := execute(&hosts.Host{Node: full},
fmt.Sprintf(workerCommand, k3sScript, k3sMirror, url, merged.Token, extraArgs), true); err != nil {
fmt.Sprintf(workerCommand, k3sScript, k3sMirror, merged.URL, merged.Token, extraArgs), true); err != nil {
return err
}

Expand Down
11 changes: 11 additions & 0 deletions pkg/providers/alibaba/flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,16 @@ func (p *Alibaba) GetCreateFlags(cmd *cobra.Command) *pflag.FlagSet {
func (p *Alibaba) GetJoinFlags(cmd *cobra.Command) *pflag.FlagSet {
fs := p.sharedFlags()

fs = append(fs, []types.Flag{
{
Name: "url",
P: &p.URL,
V: p.URL,
Usage: "Specify K3s master URL",
Required: true,
},
}...)

for _, f := range fs {
if f.ShortHand == "" {
if cmd.Flags().Lookup(f.Name) == nil {
Expand Down Expand Up @@ -112,6 +122,7 @@ func (p *Alibaba) GetJoinFlags(cmd *cobra.Command) *pflag.FlagSet {
// join command need merge status & token value.
p.Status = matched.Status
p.Token = matched.Token
p.URL = matched.URL
p.mergeOptions(*matched)
}

Expand Down
1 change: 1 addition & 0 deletions pkg/types/autok3s.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type Metadata struct {
Worker string `json:"worker" yaml:"worker"`
Token string `json:"token,omitempty" yaml:"token,omitempty"`
UI string `json:"ui,omitempty" yaml:"ui,omitempty"`
URL string `json:"url,omitempty" yaml:"url,omitempty"`
Repo string `json:"repo,omitempty" yaml:"repo,omitempty"`
ClusterCIDR string `json:"cluster-cidr,omitempty" yaml:"cluster-cidr,omitempty"`
CloudControllerManager string `json:"cloud-controller-manager,omitempty" yaml:"cloud-controller-manager,omitempty"`
Expand Down

0 comments on commit 83554f6

Please # to comment.