Use utils.net to parse ports instead of atoi (#89120)

This commit is contained in:
Jie Shen
2020-04-22 11:55:52 +08:00
committed by GitHub
parent 85ee5fdd90
commit 363bb39142
10 changed files with 20 additions and 12 deletions

View File

@@ -36,6 +36,7 @@ go_library(
"//vendor/github.com/pkg/errors:go_default_library",
"//vendor/k8s.io/klog:go_default_library",
"//vendor/k8s.io/utils/exec:go_default_library",
"//vendor/k8s.io/utils/net:go_default_library",
],
)

View File

@@ -26,6 +26,7 @@ import (
"k8s.io/apimachinery/pkg/util/validation"
kubeadmapi "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm"
utilsnet "k8s.io/utils/net"
)
// GetControlPlaneEndpoint returns a properly formatted endpoint for the control plane built according following rules:
@@ -115,7 +116,7 @@ func ParseHostPort(hostport string) (string, string, error) {
// ParsePort parses a string representing a TCP port.
// If the string is not a valid representation of a TCP port, ParsePort returns an error.
func ParsePort(port string) (int, error) {
portInt, err := strconv.Atoi(port)
portInt, err := utilsnet.ParsePort(port, true)
if err == nil && (1 <= portInt && portInt <= 65535) {
return portInt, nil
}