Skip to content

Commit

Permalink
feat(autok3s): change --url to --ip 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 cb1ead8 commit a255e4e
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ sudo autok3s join \
--v-switch <v-switch id> \
--security-group <security-group id> \
--token <k3s token> \
--url <k3s master ip> \
--ip <k3s master/lb ip> \
--worker 1
```

Expand Down
20 changes: 12 additions & 8 deletions pkg/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,12 @@ func InitK3sCluster(cluster *types.Cluster) error {
return errors.New("[cluster] master node internal ip address can not be empty")
}

cluster.URL = cluster.MasterNodes[0].InternalIPAddress[0]
publicIP := cluster.MasterNodes[0].PublicIPAddress[0]
publicIP := cluster.IP
if cluster.IP == "" {
cluster.IP = cluster.MasterNodes[0].InternalIPAddress[0]
publicIP = cluster.MasterNodes[0].PublicIPAddress[0]
}

masterExtraArgs := cluster.MasterExtraArgs
workerExtraArgs := cluster.WorkerExtraArgs

Expand Down Expand Up @@ -271,11 +275,11 @@ func JoinK3sNode(merged, added *types.Cluster) error {
return errors.New("[cluster] k3s token can not be empty")
}

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

errChan := make(chan error)
Expand Down Expand Up @@ -563,7 +567,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,
fmt.Sprintf(joinCommand, k3sScript, k3sMirror, cluster.Registries, cluster.IP, cluster.Token,
strings.TrimSpace(extraArgs), cluster.K3sVersion), false); err != nil {
errChan <- err
}
Expand All @@ -574,7 +578,7 @@ func joinMaster(wg *sync.WaitGroup, errChan chan error, noFlannel bool, k3sScrip
defer wg.Done()

if !strings.Contains(extraArgs, "server --server") {
extraArgs += " server --server " + fmt.Sprintf("https://%s:6443", merged.URL)
extraArgs += " server --server " + fmt.Sprintf("https://%s:6443", merged.IP)
}

if merged.DataStore != "" {
Expand Down Expand Up @@ -607,7 +611,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,
fmt.Sprintf(joinCommand, k3sScript, k3sMirror, merged.Registries, merged.IP, merged.Token,
strings.TrimSpace(extraArgs), merged.K3sVersion), false); err != nil {
errChan <- err
}
Expand All @@ -629,7 +633,7 @@ 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,
fmt.Sprintf(joinCommand, k3sScript, k3sMirror, merged.Registries, merged.IP, merged.Token,
strings.TrimSpace(extraArgs), merged.K3sVersion), false); err != nil {
errChan <- err
}
Expand Down
18 changes: 7 additions & 11 deletions pkg/providers/alibaba/flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,16 +151,6 @@ func (p *Alibaba) GetDeleteFlags(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 @@ -193,7 +183,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.IP = matched.IP
p.mergeOptions(*matched)
}

Expand Down Expand Up @@ -372,6 +362,12 @@ func (p *Alibaba) sharedFlags() []types.Flag {
Usage: "Used to specify the maximum out flow of the instance internet",
Required: true,
},
{
Name: "ip",
P: &p.IP,
V: p.IP,
Usage: "Specify K3s master/lb ip",
},
{
Name: "k3s-version",
P: &p.K3sVersion,
Expand Down
2 changes: 1 addition & 1 deletion pkg/types/autok3s.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +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"`
IP string `json:"ip,omitempty" yaml:"ip,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 a255e4e

Please # to comment.