Skip to content

Commit

Permalink
feature(main): using 22 default port (labring#3759)
Browse files Browse the repository at this point in the history
Signed-off-by: cuisongliu <[email protected]>
  • Loading branch information
cuisongliu committed Aug 24, 2023
1 parent cf77d1e commit b5db485
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
12 changes: 10 additions & 2 deletions pkg/apply/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func (r *ClusterArgs) runArgs(cmd *cobra.Command, args *RunArgs, imageList []str

r.cluster.SetNewImages(imageList)

defaultPort := strconv.Itoa(int(r.cluster.Spec.SSH.Port))
defaultPort := strconv.Itoa(int(defaultSSHPort(r.cluster.Spec.SSH.Port)))
masters := stringsutil.SplitRemoveEmpty(args.Cluster.Masters, ",")
nodes := stringsutil.SplitRemoveEmpty(args.Cluster.Nodes, ",")
r.hosts = []v2.Host{}
Expand All @@ -139,10 +139,11 @@ func (r *ClusterArgs) runArgs(cmd *cobra.Command, args *RunArgs, imageList []str
}

func (r *ClusterArgs) setHostWithIpsPort(ips []string, roles []string) {
defaultPort := strconv.Itoa(int(r.cluster.Spec.SSH.Port))
defaultPort := strconv.Itoa(int(defaultSSHPort(r.cluster.Spec.SSH.Port)))
hostMap := map[string]*v2.Host{}
for i := range ips {
ip, port := iputils.GetHostIPAndPortOrDefault(ips[i], defaultPort)
logger.Debug("defaultPort: %s", defaultPort)
socket := fmt.Sprintf("%s:%s", ip, port)
if stringsutil.In(socket, r.cluster.GetAllIPS()) {
continue
Expand All @@ -163,3 +164,10 @@ func (r *ClusterArgs) setHostWithIpsPort(ips []string, roles []string) {
r.hosts = append(r.hosts, *host)
}
}

func defaultSSHPort(port uint16) uint16 {
if port == 0 {
port = v2.DefaultSSHPort
}
return port
}
2 changes: 1 addition & 1 deletion pkg/apply/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func TestNewApplierFromArgs(t *testing.T) {
},
Spec: v2.ClusterSpec{
Hosts: []v2.Host{
{IPS: []string{iputils.LocalIP(addr) + ":0"}, Roles: []string{v2.MASTER, GetHostArch(ssh.NewSSHClient(&v2.SSH{}, true), iputils.LocalIP(addr)+":0")}},
{IPS: []string{iputils.LocalIP(addr) + ":22"}, Roles: []string{v2.MASTER, GetHostArch(ssh.NewSSHClient(&v2.SSH{}, true), iputils.LocalIP(addr)+":22")}},
},
Image: []string{"labring/kubernetes:v1.24.0"},
SSH: v2.SSH{},
Expand Down
4 changes: 1 addition & 3 deletions pkg/apply/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,7 @@ func GetNewImages(currentCluster, desiredCluster *v2.Cluster) []string {
}

func CheckAndInitialize(cluster *v2.Cluster) {
if cluster.Spec.SSH.Port == 0 {
cluster.Spec.SSH.Port = v2.DefaultSSHPort
}
cluster.Spec.SSH.Port = defaultSSHPort(cluster.Spec.SSH.Port)

if cluster.Spec.SSH.Pk == "" {
cluster.Spec.SSH.Pk = filepath.Join(constants.GetHomeDir(), ".ssh", "id_rsa")
Expand Down

0 comments on commit b5db485

Please sign in to comment.