code cleanup: modify kube-scheduler, remove useless return value

This commit is contained in:
BinacsLee 2021-04-16 08:16:10 +08:00
parent 743ceb7e73
commit f29d0b548e

View File

@ -53,12 +53,8 @@ func (o *CombinedInsecureServingOptions) AddFlags(fs *pflag.FlagSet) {
} }
func (o *CombinedInsecureServingOptions) applyTo(c *schedulerappconfig.Config, componentConfig *kubeschedulerconfig.KubeSchedulerConfiguration) error { func (o *CombinedInsecureServingOptions) applyTo(c *schedulerappconfig.Config, componentConfig *kubeschedulerconfig.KubeSchedulerConfiguration) error {
if err := updateAddressFromDeprecatedInsecureServingOptions(&componentConfig.HealthzBindAddress, o.Healthz); err != nil { updateAddressFromDeprecatedInsecureServingOptions(&componentConfig.HealthzBindAddress, o.Healthz)
return err updateAddressFromDeprecatedInsecureServingOptions(&componentConfig.MetricsBindAddress, o.Metrics)
}
if err := updateAddressFromDeprecatedInsecureServingOptions(&componentConfig.MetricsBindAddress, o.Metrics); err != nil {
return err
}
if err := o.Healthz.ApplyTo(&c.InsecureServing, &c.LoopbackClientConfig); err != nil { if err := o.Healthz.ApplyTo(&c.InsecureServing, &c.LoopbackClientConfig); err != nil {
return err return err
@ -98,20 +94,18 @@ func (o *CombinedInsecureServingOptions) ApplyToFromLoadedConfig(c *schedulerapp
return nil return nil
} }
if err := updateDeprecatedInsecureServingOptionsFromAddress(o.Healthz, componentConfig.HealthzBindAddress); err != nil { updateDeprecatedInsecureServingOptionsFromAddress(o.Healthz, componentConfig.HealthzBindAddress)
return fmt.Errorf("invalid healthz address: %v", err) updateDeprecatedInsecureServingOptionsFromAddress(o.Metrics, componentConfig.MetricsBindAddress)
}
if err := updateDeprecatedInsecureServingOptionsFromAddress(o.Metrics, componentConfig.MetricsBindAddress); err != nil {
return fmt.Errorf("invalid metrics address: %v", err)
}
return o.applyTo(c, componentConfig) return o.applyTo(c, componentConfig)
} }
func updateAddressFromDeprecatedInsecureServingOptions(addr *string, is *apiserveroptions.DeprecatedInsecureServingOptionsWithLoopback) error { func updateAddressFromDeprecatedInsecureServingOptions(addr *string, is *apiserveroptions.DeprecatedInsecureServingOptionsWithLoopback) {
if is == nil { if is == nil {
*addr = "" *addr = ""
} else { return
}
if is.Listener != nil { if is.Listener != nil {
*addr = is.Listener.Addr().String() *addr = is.Listener.Addr().String()
} else if is.BindPort == 0 { } else if is.BindPort == 0 {
@ -121,27 +115,19 @@ func updateAddressFromDeprecatedInsecureServingOptions(addr *string, is *apiserv
} }
} }
return nil func updateDeprecatedInsecureServingOptionsFromAddress(is *apiserveroptions.DeprecatedInsecureServingOptionsWithLoopback, addr string) {
if is == nil {
return
} }
func updateDeprecatedInsecureServingOptionsFromAddress(is *apiserveroptions.DeprecatedInsecureServingOptionsWithLoopback, addr string) error {
if is == nil {
return nil
}
if len(addr) == 0 { if len(addr) == 0 {
is.BindPort = 0 is.BindPort = 0
return nil } else {
} // In the previous `validate` process, we can ensure that the `addr` is legal, so ignore the error
host, portInt, _ := splitHostIntPort(addr)
host, portInt, err := splitHostIntPort(addr)
if err != nil {
return fmt.Errorf("invalid address %q", addr)
}
is.BindAddress = net.ParseIP(host) is.BindAddress = net.ParseIP(host)
is.BindPort = portInt is.BindPort = portInt
}
return nil
} }
// Validate validates the insecure serving options. // Validate validates the insecure serving options.