diff --git a/pkg/cluster/cluster.go b/pkg/cluster/cluster.go index 7d516d08..6cef0efc 100644 --- a/pkg/cluster/cluster.go +++ b/pkg/cluster/cluster.go @@ -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 @@ -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 } } @@ -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. @@ -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 } diff --git a/pkg/providers/alibaba/flag.go b/pkg/providers/alibaba/flag.go index a524f486..5cb20a9d 100644 --- a/pkg/providers/alibaba/flag.go +++ b/pkg/providers/alibaba/flag.go @@ -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 { @@ -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) } diff --git a/pkg/types/autok3s.go b/pkg/types/autok3s.go index 12484911..9ae59f8c 100644 --- a/pkg/types/autok3s.go +++ b/pkg/types/autok3s.go @@ -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"`