Merge pull request #64016 from stewart-yu/stewart-controller-manager-codeclean

Automatic merge from submit-queue (batch tested with PRs 57082, 64325, 64016, 64443, 64403). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

should not ignore err when convert api version

**What this PR does / why we need it**:
should not ignore err when convert api version

**Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*:
Fixes #

**Special notes for your reviewer**:

**Release note**:

```release-note
NONE
```
pull/8/head
Kubernetes Submit Queue 2018-05-30 18:49:17 -07:00 committed by GitHub
commit 0340864ae9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 36 additions and 17 deletions

View File

@ -54,7 +54,11 @@ const (
// NewCloudControllerManagerCommand creates a *cobra.Command object with default parameters
func NewCloudControllerManagerCommand() *cobra.Command {
s := options.NewCloudControllerManagerOptions()
s, err := options.NewCloudControllerManagerOptions()
if err != nil {
glog.Fatalf("unable to initialize command options: %v", err)
}
cmd := &cobra.Command{
Use: "cloud-controller-manager",
Long: `The Cloud controller manager is a daemon that embeds

View File

@ -72,8 +72,11 @@ type CloudControllerManagerOptions struct {
}
// NewCloudControllerManagerOptions creates a new ExternalCMServer with a default config.
func NewCloudControllerManagerOptions() *CloudControllerManagerOptions {
componentConfig := NewDefaultComponentConfig(ports.InsecureCloudControllerManagerPort)
func NewCloudControllerManagerOptions() (*CloudControllerManagerOptions, error) {
componentConfig, err := NewDefaultComponentConfig(ports.InsecureCloudControllerManagerPort)
if err != nil {
return nil, err
}
s := CloudControllerManagerOptions{
CloudProvider: &cmoptions.CloudProviderOptions{},
@ -101,11 +104,11 @@ func NewCloudControllerManagerOptions() *CloudControllerManagerOptions {
// TODO: enable HTTPS by default
s.SecureServing.BindPort = 0
return &s
return &s, nil
}
// NewDefaultComponentConfig returns cloud-controller manager configuration object.
func NewDefaultComponentConfig(insecurePort int32) componentconfig.CloudControllerManagerConfiguration {
func NewDefaultComponentConfig(insecurePort int32) (componentconfig.CloudControllerManagerConfiguration, error) {
scheme := runtime.NewScheme()
componentconfigv1alpha1.AddToScheme(scheme)
componentconfig.AddToScheme(scheme)
@ -114,9 +117,11 @@ func NewDefaultComponentConfig(insecurePort int32) componentconfig.CloudControll
scheme.Default(&versioned)
internal := componentconfig.CloudControllerManagerConfiguration{}
scheme.Convert(&versioned, &internal, nil)
if err := scheme.Convert(&versioned, &internal, nil); err != nil {
return internal, err
}
internal.KubeCloudShared.Port = insecurePort
return internal
return internal, nil
}
// AddFlags adds flags for a specific ExternalCMServer to the specified FlagSet

View File

@ -32,7 +32,7 @@ import (
)
func TestDefaultFlags(t *testing.T) {
s := NewCloudControllerManagerOptions()
s, _ := NewCloudControllerManagerOptions()
expected := &CloudControllerManagerOptions{
CloudProvider: &cmoptions.CloudProviderOptions{
@ -95,7 +95,7 @@ func TestDefaultFlags(t *testing.T) {
func TestAddFlags(t *testing.T) {
f := pflag.NewFlagSet("addflagstest", pflag.ContinueOnError)
s := NewCloudControllerManagerOptions()
s, _ := NewCloudControllerManagerOptions()
s.AddFlags(f)
args := []string{

View File

@ -70,7 +70,11 @@ const (
// NewControllerManagerCommand creates a *cobra.Command object with default parameters
func NewControllerManagerCommand() *cobra.Command {
s := options.NewKubeControllerManagerOptions()
s, err := options.NewKubeControllerManagerOptions()
if err != nil {
glog.Fatalf("unable to initialize command options: %v", err)
}
cmd := &cobra.Command{
Use: "kube-controller-manager",
Long: `The Kubernetes controller manager is a daemon that embeds

View File

@ -90,8 +90,12 @@ type KubeControllerManagerOptions struct {
}
// NewKubeControllerManagerOptions creates a new KubeControllerManagerOptions with a default config.
func NewKubeControllerManagerOptions() *KubeControllerManagerOptions {
componentConfig := NewDefaultComponentConfig(ports.InsecureKubeControllerManagerPort)
func NewKubeControllerManagerOptions() (*KubeControllerManagerOptions, error) {
componentConfig, err := NewDefaultComponentConfig(ports.InsecureKubeControllerManagerPort)
if err != nil {
return nil, err
}
s := KubeControllerManagerOptions{
CloudProvider: &cmoptions.CloudProviderOptions{},
Debugging: &cmoptions.DebuggingOptions{},
@ -193,11 +197,11 @@ func NewKubeControllerManagerOptions() *KubeControllerManagerOptions {
s.GarbageCollectorController.GCIgnoredResources = gcIgnoredResources
return &s
return &s, nil
}
// NewDefaultComponentConfig returns kube-controller manager configuration object.
func NewDefaultComponentConfig(insecurePort int32) componentconfig.KubeControllerManagerConfiguration {
func NewDefaultComponentConfig(insecurePort int32) (componentconfig.KubeControllerManagerConfiguration, error) {
scheme := runtime.NewScheme()
componentconfigv1alpha1.AddToScheme(scheme)
componentconfig.AddToScheme(scheme)
@ -206,9 +210,11 @@ func NewDefaultComponentConfig(insecurePort int32) componentconfig.KubeControlle
scheme.Default(&versioned)
internal := componentconfig.KubeControllerManagerConfiguration{}
scheme.Convert(&versioned, &internal, nil)
if err := scheme.Convert(&versioned, &internal, nil); err != nil {
return internal, err
}
internal.KubeCloudShared.Port = insecurePort
return internal
return internal, nil
}
// AddFlags adds flags for a specific KubeControllerManagerOptions to the specified FlagSet

View File

@ -34,7 +34,7 @@ import (
func TestAddFlags(t *testing.T) {
f := pflag.NewFlagSet("addflagstest", pflag.ContinueOnError)
s := NewKubeControllerManagerOptions()
s, _ := NewKubeControllerManagerOptions()
s.AddFlags(f, []string{""}, []string{""})
args := []string{