diff --git a/cmd/kube-proxy/app/server.go b/cmd/kube-proxy/app/server.go index c249b9db6ff..906da60847a 100644 --- a/cmd/kube-proxy/app/server.go +++ b/cmd/kube-proxy/app/server.go @@ -137,7 +137,7 @@ func (o *Options) AddFlags(fs *pflag.FlagSet) { fs.StringVar(&o.config.ResourceContainer, "resource-container", o.config.ResourceContainer, "Absolute name of the resource-only container to create and run the Kube-proxy in (Default: /kube-proxy).") fs.MarkDeprecated("resource-container", "This feature will be removed in a later release.") fs.StringVar(&o.config.ClientConnection.KubeConfigFile, "kubeconfig", o.config.ClientConnection.KubeConfigFile, "Path to kubeconfig file with authorization information (the master location is set by the master flag).") - fs.Var(componentconfig.PortRangeVar{Val: &o.config.PortRange}, "proxy-port-range", "Range of host ports (beginPort-endPort, single port or beginPort+offset, inclusive) that may be consumed in order to proxy service traffic. If unspecified (0-0) then ports will be randomly chosen.") + fs.Var(componentconfig.PortRangeVar{Val: &o.config.PortRange}, "proxy-port-range", "Range of host ports (beginPort-endPort, single port or beginPort+offset, inclusive) that may be consumed in order to proxy service traffic. If (unspecified, 0, or 0-0) then ports will be randomly chosen.") fs.StringVar(&o.config.HostnameOverride, "hostname-override", o.config.HostnameOverride, "If non-empty, will use this string as identification instead of the actual hostname.") fs.Var(&o.config.Mode, "proxy-mode", "Which proxy mode to use: 'userspace' (older) or 'iptables' (faster) or 'ipvs' (experimental). If blank, use the best-available proxy (currently iptables). If the iptables proxy is selected, regardless of how, but the system's kernel or iptables versions are insufficient, this always falls back to the userspace proxy.") fs.Int32Var(o.config.IPTables.MasqueradeBit, "iptables-masquerade-bit", utilpointer.Int32PtrDerefOr(o.config.IPTables.MasqueradeBit, 14), "If using the pure iptables proxy, the bit of the fwmark space to mark packets requiring SNAT with. Must be within the range [0, 31].") diff --git a/staging/src/k8s.io/apimachinery/pkg/util/net/port_range.go b/staging/src/k8s.io/apimachinery/pkg/util/net/port_range.go index 8d3af80b019..7b6eca89321 100644 --- a/staging/src/k8s.io/apimachinery/pkg/util/net/port_range.go +++ b/staging/src/k8s.io/apimachinery/pkg/util/net/port_range.go @@ -43,16 +43,15 @@ func (pr PortRange) String() string { return fmt.Sprintf("%d-%d", pr.Base, pr.Base+pr.Size-1) } -const ( - SinglePortNotation = iota - HyphenNotation = 1 << iota - PlusNotation -) - -// Set parses a string of the form "min-max", inclusive at both ends, and +// Set parses a string of the form "value", "min-max", or "min+offset", inclusive at both ends, and // sets the PortRange from it. This is part of the flag.Value and pflag.Value // interfaces. func (pr *PortRange) Set(value string) error { + const ( + SinglePortNotation = 1 << iota + HyphenNotation + PlusNotation + ) value = strings.TrimSpace(value) hyphenIndex := strings.Index(value, "-") @@ -65,10 +64,13 @@ func (pr *PortRange) Set(value string) error { } var err error - var notation int var low, high int + var notation int - if hyphenIndex >= 0 { + if plusIndex == -1 && hyphenIndex == -1 { + notation |= SinglePortNotation + } + if hyphenIndex != -1 { notation |= HyphenNotation } if plusIndex != -1 {