Merge pull request #114860 from TommyStarK/cmd-kubeapiserver/clean-code

cmd/kubeapiserver: Clean code, avoid unnecessary condition, avoid non-nil but zero-length slice
This commit is contained in:
Kubernetes Prow Robot 2023-01-06 11:22:09 -08:00 committed by GitHub
commit 810cdfc9df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -218,12 +218,7 @@ func CreateServerChain(completedOptions completedServerRunOptions) (*aggregatora
// CreateKubeAPIServer creates and wires a workable kube-apiserver
func CreateKubeAPIServer(kubeAPIServerConfig *controlplane.Config, delegateAPIServer genericapiserver.DelegationTarget) (*controlplane.Instance, error) {
kubeAPIServer, err := kubeAPIServerConfig.Complete().New(delegateAPIServer)
if err != nil {
return nil, err
}
return kubeAPIServer, nil
return kubeAPIServerConfig.Complete().New(delegateAPIServer)
}
// CreateProxyTransport creates the dialer infrastructure to connect to the nodes.
@ -546,11 +541,11 @@ func Complete(s *options.ServerRunOptions) (completedServerRunOptions, error) {
if len(s.GenericServerRunOptions.AdvertiseAddress) > 0 {
s.GenericServerRunOptions.ExternalHost = s.GenericServerRunOptions.AdvertiseAddress.String()
} else {
if hostname, err := os.Hostname(); err == nil {
s.GenericServerRunOptions.ExternalHost = hostname
} else {
hostname, err := os.Hostname()
if err != nil {
return options, fmt.Errorf("error finding host name: %v", err)
}
s.GenericServerRunOptions.ExternalHost = hostname
}
klog.Infof("external host was not specified, using %v", s.GenericServerRunOptions.ExternalHost)
}