mirror of
				https://github.com/k3s-io/kubernetes.git
				synced 2025-11-03 23:40:03 +00:00 
			
		
		
		
	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 ```
This commit is contained in:
		@@ -54,7 +54,11 @@ const (
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
// NewCloudControllerManagerCommand creates a *cobra.Command object with default parameters
 | 
					// NewCloudControllerManagerCommand creates a *cobra.Command object with default parameters
 | 
				
			||||||
func NewCloudControllerManagerCommand() *cobra.Command {
 | 
					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{
 | 
						cmd := &cobra.Command{
 | 
				
			||||||
		Use: "cloud-controller-manager",
 | 
							Use: "cloud-controller-manager",
 | 
				
			||||||
		Long: `The Cloud controller manager is a daemon that embeds
 | 
							Long: `The Cloud controller manager is a daemon that embeds
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -72,8 +72,11 @@ type CloudControllerManagerOptions struct {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// NewCloudControllerManagerOptions creates a new ExternalCMServer with a default config.
 | 
					// NewCloudControllerManagerOptions creates a new ExternalCMServer with a default config.
 | 
				
			||||||
func NewCloudControllerManagerOptions() *CloudControllerManagerOptions {
 | 
					func NewCloudControllerManagerOptions() (*CloudControllerManagerOptions, error) {
 | 
				
			||||||
	componentConfig := NewDefaultComponentConfig(ports.InsecureCloudControllerManagerPort)
 | 
						componentConfig, err := NewDefaultComponentConfig(ports.InsecureCloudControllerManagerPort)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return nil, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	s := CloudControllerManagerOptions{
 | 
						s := CloudControllerManagerOptions{
 | 
				
			||||||
		CloudProvider:    &cmoptions.CloudProviderOptions{},
 | 
							CloudProvider:    &cmoptions.CloudProviderOptions{},
 | 
				
			||||||
@@ -101,11 +104,11 @@ func NewCloudControllerManagerOptions() *CloudControllerManagerOptions {
 | 
				
			|||||||
	// TODO: enable HTTPS by default
 | 
						// TODO: enable HTTPS by default
 | 
				
			||||||
	s.SecureServing.BindPort = 0
 | 
						s.SecureServing.BindPort = 0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return &s
 | 
						return &s, nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// NewDefaultComponentConfig returns cloud-controller manager configuration object.
 | 
					// NewDefaultComponentConfig returns cloud-controller manager configuration object.
 | 
				
			||||||
func NewDefaultComponentConfig(insecurePort int32) componentconfig.CloudControllerManagerConfiguration {
 | 
					func NewDefaultComponentConfig(insecurePort int32) (componentconfig.CloudControllerManagerConfiguration, error) {
 | 
				
			||||||
	scheme := runtime.NewScheme()
 | 
						scheme := runtime.NewScheme()
 | 
				
			||||||
	componentconfigv1alpha1.AddToScheme(scheme)
 | 
						componentconfigv1alpha1.AddToScheme(scheme)
 | 
				
			||||||
	componentconfig.AddToScheme(scheme)
 | 
						componentconfig.AddToScheme(scheme)
 | 
				
			||||||
@@ -114,9 +117,11 @@ func NewDefaultComponentConfig(insecurePort int32) componentconfig.CloudControll
 | 
				
			|||||||
	scheme.Default(&versioned)
 | 
						scheme.Default(&versioned)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	internal := componentconfig.CloudControllerManagerConfiguration{}
 | 
						internal := componentconfig.CloudControllerManagerConfiguration{}
 | 
				
			||||||
	scheme.Convert(&versioned, &internal, nil)
 | 
						if err := scheme.Convert(&versioned, &internal, nil); err != nil {
 | 
				
			||||||
 | 
							return internal, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	internal.KubeCloudShared.Port = insecurePort
 | 
						internal.KubeCloudShared.Port = insecurePort
 | 
				
			||||||
	return internal
 | 
						return internal, nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// AddFlags adds flags for a specific ExternalCMServer to the specified FlagSet
 | 
					// AddFlags adds flags for a specific ExternalCMServer to the specified FlagSet
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -32,7 +32,7 @@ import (
 | 
				
			|||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func TestDefaultFlags(t *testing.T) {
 | 
					func TestDefaultFlags(t *testing.T) {
 | 
				
			||||||
	s := NewCloudControllerManagerOptions()
 | 
						s, _ := NewCloudControllerManagerOptions()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	expected := &CloudControllerManagerOptions{
 | 
						expected := &CloudControllerManagerOptions{
 | 
				
			||||||
		CloudProvider: &cmoptions.CloudProviderOptions{
 | 
							CloudProvider: &cmoptions.CloudProviderOptions{
 | 
				
			||||||
@@ -95,7 +95,7 @@ func TestDefaultFlags(t *testing.T) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
func TestAddFlags(t *testing.T) {
 | 
					func TestAddFlags(t *testing.T) {
 | 
				
			||||||
	f := pflag.NewFlagSet("addflagstest", pflag.ContinueOnError)
 | 
						f := pflag.NewFlagSet("addflagstest", pflag.ContinueOnError)
 | 
				
			||||||
	s := NewCloudControllerManagerOptions()
 | 
						s, _ := NewCloudControllerManagerOptions()
 | 
				
			||||||
	s.AddFlags(f)
 | 
						s.AddFlags(f)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	args := []string{
 | 
						args := []string{
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -70,7 +70,11 @@ const (
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
// NewControllerManagerCommand creates a *cobra.Command object with default parameters
 | 
					// NewControllerManagerCommand creates a *cobra.Command object with default parameters
 | 
				
			||||||
func NewControllerManagerCommand() *cobra.Command {
 | 
					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{
 | 
						cmd := &cobra.Command{
 | 
				
			||||||
		Use: "kube-controller-manager",
 | 
							Use: "kube-controller-manager",
 | 
				
			||||||
		Long: `The Kubernetes controller manager is a daemon that embeds
 | 
							Long: `The Kubernetes controller manager is a daemon that embeds
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -90,8 +90,12 @@ type KubeControllerManagerOptions struct {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// NewKubeControllerManagerOptions creates a new KubeControllerManagerOptions with a default config.
 | 
					// NewKubeControllerManagerOptions creates a new KubeControllerManagerOptions with a default config.
 | 
				
			||||||
func NewKubeControllerManagerOptions() *KubeControllerManagerOptions {
 | 
					func NewKubeControllerManagerOptions() (*KubeControllerManagerOptions, error) {
 | 
				
			||||||
	componentConfig := NewDefaultComponentConfig(ports.InsecureKubeControllerManagerPort)
 | 
						componentConfig, err := NewDefaultComponentConfig(ports.InsecureKubeControllerManagerPort)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return nil, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	s := KubeControllerManagerOptions{
 | 
						s := KubeControllerManagerOptions{
 | 
				
			||||||
		CloudProvider:    &cmoptions.CloudProviderOptions{},
 | 
							CloudProvider:    &cmoptions.CloudProviderOptions{},
 | 
				
			||||||
		Debugging:        &cmoptions.DebuggingOptions{},
 | 
							Debugging:        &cmoptions.DebuggingOptions{},
 | 
				
			||||||
@@ -193,11 +197,11 @@ func NewKubeControllerManagerOptions() *KubeControllerManagerOptions {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	s.GarbageCollectorController.GCIgnoredResources = gcIgnoredResources
 | 
						s.GarbageCollectorController.GCIgnoredResources = gcIgnoredResources
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return &s
 | 
						return &s, nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// NewDefaultComponentConfig returns kube-controller manager configuration object.
 | 
					// NewDefaultComponentConfig returns kube-controller manager configuration object.
 | 
				
			||||||
func NewDefaultComponentConfig(insecurePort int32) componentconfig.KubeControllerManagerConfiguration {
 | 
					func NewDefaultComponentConfig(insecurePort int32) (componentconfig.KubeControllerManagerConfiguration, error) {
 | 
				
			||||||
	scheme := runtime.NewScheme()
 | 
						scheme := runtime.NewScheme()
 | 
				
			||||||
	componentconfigv1alpha1.AddToScheme(scheme)
 | 
						componentconfigv1alpha1.AddToScheme(scheme)
 | 
				
			||||||
	componentconfig.AddToScheme(scheme)
 | 
						componentconfig.AddToScheme(scheme)
 | 
				
			||||||
@@ -206,9 +210,11 @@ func NewDefaultComponentConfig(insecurePort int32) componentconfig.KubeControlle
 | 
				
			|||||||
	scheme.Default(&versioned)
 | 
						scheme.Default(&versioned)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	internal := componentconfig.KubeControllerManagerConfiguration{}
 | 
						internal := componentconfig.KubeControllerManagerConfiguration{}
 | 
				
			||||||
	scheme.Convert(&versioned, &internal, nil)
 | 
						if err := scheme.Convert(&versioned, &internal, nil); err != nil {
 | 
				
			||||||
 | 
							return internal, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	internal.KubeCloudShared.Port = insecurePort
 | 
						internal.KubeCloudShared.Port = insecurePort
 | 
				
			||||||
	return internal
 | 
						return internal, nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// AddFlags adds flags for a specific KubeControllerManagerOptions to the specified FlagSet
 | 
					// AddFlags adds flags for a specific KubeControllerManagerOptions to the specified FlagSet
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -34,7 +34,7 @@ import (
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
func TestAddFlags(t *testing.T) {
 | 
					func TestAddFlags(t *testing.T) {
 | 
				
			||||||
	f := pflag.NewFlagSet("addflagstest", pflag.ContinueOnError)
 | 
						f := pflag.NewFlagSet("addflagstest", pflag.ContinueOnError)
 | 
				
			||||||
	s := NewKubeControllerManagerOptions()
 | 
						s, _ := NewKubeControllerManagerOptions()
 | 
				
			||||||
	s.AddFlags(f, []string{""}, []string{""})
 | 
						s.AddFlags(f, []string{""}, []string{""})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	args := []string{
 | 
						args := []string{
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user