Skip to content

Commit

Permalink
refactor: Change the return type of GetPublicPort to uint instead of …
Browse files Browse the repository at this point in the history
…uint16

All references to ports in the codebase use uint not uint16.
There is no reason to keep the ports as they are

Signed-off-by: aerosouund <[email protected]>
  • Loading branch information
aerosouund committed Oct 31, 2024
1 parent 9ab179c commit 6d52569
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 29 deletions.
4 changes: 2 additions & 2 deletions cluster-provision/gocli/cmd/utils/ports.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const (
)

// GetPublicPort returns public port by private port
func GetPublicPort(port uint16, ports nat.PortMap) (uint16, error) {
func GetPublicPort(port uint, ports nat.PortMap) (uint16, error) {
portStr := strconv.Itoa(int(port))
for k, p := range ports {
if k == nat.Port(portStr+"/tcp") || k == nat.Port(portStr+"/udp") {
Expand All @@ -84,7 +84,7 @@ func GetPublicPort(port uint16, ports nat.PortMap) (uint16, error) {
}

// PrintPublicPort prints public port
func PrintPublicPort(port uint16, ports nat.PortMap) error {
func PrintPublicPort(port uint, ports nat.PortMap) error {
p, err := GetPublicPort(port, ports)
if err != nil {
return err
Expand Down
20 changes: 10 additions & 10 deletions cluster-provision/gocli/providers/opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,61 +92,61 @@ func WithSlim(slim interface{}) KubevirtProviderOption {

func WithVNCPort(vncPort interface{}) KubevirtProviderOption {
return func(c *KubevirtProvider) {
c.VNCPort = vncPort.(uint16)
c.VNCPort = vncPort.(uint)
}
}

func WithHTTPPort(httpPort interface{}) KubevirtProviderOption {
return func(c *KubevirtProvider) {
c.HTTPPort = httpPort.(uint16)
c.HTTPPort = httpPort.(uint)
}
}

func WithHTTPSPort(httpsPort interface{}) KubevirtProviderOption {
return func(c *KubevirtProvider) {
c.HTTPSPort = httpsPort.(uint16)
c.HTTPSPort = httpsPort.(uint)
}
}

func WithRegistryPort(registryPort interface{}) KubevirtProviderOption {
return func(c *KubevirtProvider) {
c.RegistryPort = registryPort.(uint16)
c.RegistryPort = registryPort.(uint)
}
}

func WithOCPort(ocpPort interface{}) KubevirtProviderOption {
return func(c *KubevirtProvider) {
c.OCPort = ocpPort.(uint16)
c.OCPort = ocpPort.(uint)
}
}

func WithK8sPort(k8sPort interface{}) KubevirtProviderOption {
return func(c *KubevirtProvider) {
c.K8sPort = k8sPort.(uint16)
c.K8sPort = k8sPort.(uint)
}
}

func WithSSHPort(sshPort interface{}) KubevirtProviderOption {
return func(c *KubevirtProvider) {
c.SSHPort = sshPort.(uint16)
c.SSHPort = sshPort.(uint)
}
}

func WithPrometheusPort(prometheusPort interface{}) KubevirtProviderOption {
return func(c *KubevirtProvider) {
c.PrometheusPort = prometheusPort.(uint16)
c.PrometheusPort = prometheusPort.(uint)
}
}

func WithGrafanaPort(grafanaPort interface{}) KubevirtProviderOption {
return func(c *KubevirtProvider) {
c.GrafanaPort = grafanaPort.(uint16)
c.GrafanaPort = grafanaPort.(uint)
}
}

func WithDNSPort(dnsPort interface{}) KubevirtProviderOption {
return func(c *KubevirtProvider) {
c.DNSPort = dnsPort.(uint16)
c.DNSPort = dnsPort.(uint)
}
}

Expand Down
12 changes: 6 additions & 6 deletions cluster-provision/gocli/providers/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,15 @@ func (kp *KubevirtProvider) Start(ctx context.Context, cancel context.CancelFunc
if err != nil {
return err
}
kp.SSHPort = port
kp.SSHPort = uint(port)
}

if kp.APIServerPort == 0 {
port, err := utils.GetPublicPort(utils.PortAPI, dnsmasqJSON.NetworkSettings.Ports)
if err != nil {
return err
}
kp.APIServerPort = port
kp.APIServerPort = uint(port)
}

registry, err := kp.runRegistry(ctx)
Expand All @@ -97,7 +97,7 @@ func (kp *KubevirtProvider) Start(ctx context.Context, cancel context.CancelFunc

for x := 0; x < int(kp.Nodes); x++ {
nodeName := kp.nodeNameFromIndex(x + 1)
sshClient, err := libssh.NewSSHClient(kp.SSHPort, x+1, false)
sshClient, err := libssh.NewSSHClient(uint16(kp.SSHPort), x+1, false)
if err != nil {
return err
}
Expand Down Expand Up @@ -164,7 +164,7 @@ func (kp *KubevirtProvider) Start(ctx context.Context, cancel context.CancelFunc
if err = rootkey.Exec(); err != nil {
return err
}
sshClient, err = libssh.NewSSHClient(kp.SSHPort, x+1, true)
sshClient, err = libssh.NewSSHClient(uint16(kp.SSHPort), x+1, true)

if err = kp.provisionNode(sshClient, x+1); err != nil {
return err
Expand All @@ -176,7 +176,7 @@ func (kp *KubevirtProvider) Start(ctx context.Context, cancel context.CancelFunc
}(node.ID)
}

sshClient, err := libssh.NewSSHClient(kp.SSHPort, 1, true)
sshClient, err := libssh.NewSSHClient(uint16(kp.SSHPort), 1, true)
if err != nil {
return err
}
Expand All @@ -191,7 +191,7 @@ func (kp *KubevirtProvider) Start(ctx context.Context, cancel context.CancelFunc
return err
}

config, err := k8s.NewConfig(".kubeconfig", kp.APIServerPort)
config, err := k8s.NewConfig(".kubeconfig", uint16(kp.APIServerPort))
if err != nil {
return err
}
Expand Down
22 changes: 11 additions & 11 deletions cluster-provision/gocli/providers/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ type KubevirtProvider struct {
RandomPorts bool `flag:"random-ports" json:"random_ports"`
Prefix string `flag:"prefix" json:"prefix"`
Slim bool `flag:"slim" json:"slim"`
VNCPort uint16 `flag:"vnc-port" json:"vnc_port"`
HTTPPort uint16 `flag:"http-port" json:"http_port"`
HTTPSPort uint16 `flag:"https-port" json:"https_port"`
RegistryPort uint16 `flag:"registry-port" json:"registry_port"`
OCPort uint16 `flag:"ocp-port" json:"ocp_port"`
K8sPort uint16 `flag:"k8s-port" json:"k8s_port"`
SSHPort uint16 `flag:"ssh-port" json:"ssh_port"`
PrometheusPort uint16 `flag:"prometheus-port" json:"prometheus_port"`
GrafanaPort uint16 `flag:"grafana-port" json:"grafana_port"`
DNSPort uint16 `flag:"dns-port" json:"dns_port"`
APIServerPort uint16 `json:"api_server_port"`
VNCPort uint `flag:"vnc-port" json:"vnc_port"`
HTTPPort uint `flag:"http-port" json:"http_port"`
HTTPSPort uint `flag:"https-port" json:"https_port"`
RegistryPort uint `flag:"registry-port" json:"registry_port"`
OCPort uint `flag:"ocp-port" json:"ocp_port"`
K8sPort uint `flag:"k8s-port" json:"k8s_port"`
SSHPort uint `flag:"ssh-port" json:"ssh_port"`
PrometheusPort uint `flag:"prometheus-port" json:"prometheus_port"`
GrafanaPort uint `flag:"grafana-port" json:"grafana_port"`
DNSPort uint `flag:"dns-port" json:"dns_port"`
APIServerPort uint `json:"api_server_port"`
NFSData string `flag:"nfs-data" json:"nfs_data"`
EnableCeph bool `flag:"enable-ceph" json:"enable_ceph"`
EnableIstio bool `flag:"enable-istio" json:"enable_istio"`
Expand Down

0 comments on commit 6d52569

Please sign in to comment.