support ipv6 in bind address
use split host port func instead trim specific character add unit test for metrics and healthz bind address recover import package refactor set default kube proxy configuration fix ipv4 condition fix set default port condition rewrite call function occasion to reduce error set ipv6 default value move get GetBindAddressHostPort to util use one func to handle deprecated series update bazel define address type return earlier in the error case refactor set default kube proxy configuration logic recover import package preserve some of the original comments add get default address func add append port if needed unit test rewrite unit test for deprecated flags remove unused codes
This commit is contained in:
@@ -61,6 +61,7 @@ import (
|
||||
"k8s.io/kubernetes/pkg/proxy/iptables"
|
||||
"k8s.io/kubernetes/pkg/proxy/ipvs"
|
||||
"k8s.io/kubernetes/pkg/proxy/userspace"
|
||||
proxyutil "k8s.io/kubernetes/pkg/proxy/util"
|
||||
"k8s.io/kubernetes/pkg/util/configz"
|
||||
"k8s.io/kubernetes/pkg/util/filesystem"
|
||||
utilflag "k8s.io/kubernetes/pkg/util/flag"
|
||||
@@ -212,8 +213,8 @@ func NewOptions() *Options {
|
||||
func (o *Options) Complete() error {
|
||||
if len(o.ConfigFile) == 0 && len(o.WriteConfigTo) == 0 {
|
||||
klog.Warning("WARNING: all flags other than --config, --write-config-to, and --cleanup are deprecated. Please begin using a config file ASAP.")
|
||||
o.applyDeprecatedHealthzPortToConfig()
|
||||
o.applyDeprecatedMetricsPortToConfig()
|
||||
o.config.HealthzBindAddress = addressFromDeprecatedFlags(o.config.HealthzBindAddress, o.healthzPort)
|
||||
o.config.MetricsBindAddress = addressFromDeprecatedFlags(o.config.MetricsBindAddress, o.metricsPort)
|
||||
}
|
||||
|
||||
// Load the config file here in Complete, so that Validate validates the fully-resolved config.
|
||||
@@ -357,38 +358,15 @@ func (o *Options) writeConfigFile() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// applyDeprecatedHealthzPortToConfig sets o.config.HealthzBindAddress from
|
||||
// flags passed on the command line based on the following rules:
|
||||
//
|
||||
// 1. If --healthz-port is 0, disable the healthz server.
|
||||
// 2. Otherwise, use the value of --healthz-port for the port portion of
|
||||
// o.config.HealthzBindAddress
|
||||
func (o *Options) applyDeprecatedHealthzPortToConfig() {
|
||||
if o.healthzPort == 0 {
|
||||
o.config.HealthzBindAddress = ""
|
||||
return
|
||||
// addressFromDeprecatedFlags returns server address from flags
|
||||
// passed on the command line based on the following rules:
|
||||
// 1. If port is 0, disable the server (e.g. set address to empty).
|
||||
// 2. Otherwise, set the port portion of the config accordingly.
|
||||
func addressFromDeprecatedFlags(addr string, port int32) string {
|
||||
if port == 0 {
|
||||
return ""
|
||||
}
|
||||
|
||||
index := strings.Index(o.config.HealthzBindAddress, ":")
|
||||
if index != -1 {
|
||||
o.config.HealthzBindAddress = o.config.HealthzBindAddress[0:index]
|
||||
}
|
||||
|
||||
o.config.HealthzBindAddress = fmt.Sprintf("%s:%d", o.config.HealthzBindAddress, o.healthzPort)
|
||||
}
|
||||
|
||||
func (o *Options) applyDeprecatedMetricsPortToConfig() {
|
||||
if o.metricsPort == 0 {
|
||||
o.config.MetricsBindAddress = ""
|
||||
return
|
||||
}
|
||||
|
||||
index := strings.Index(o.config.MetricsBindAddress, ":")
|
||||
if index != -1 {
|
||||
o.config.MetricsBindAddress = o.config.MetricsBindAddress[0:index]
|
||||
}
|
||||
|
||||
o.config.MetricsBindAddress = fmt.Sprintf("%s:%d", o.config.MetricsBindAddress, o.metricsPort)
|
||||
return proxyutil.AppendPortIfNeeded(addr, port)
|
||||
}
|
||||
|
||||
// loadConfigFromFile loads the contents of file and decodes it as a
|
||||
|
Reference in New Issue
Block a user