controller-manager: fix a bug that the kubeconfig field of kubecontrollermanager.config.k8s.io configuration is not set correctly

This commit is contained in:
SataQiu 2023-03-04 11:17:55 +08:00
parent b6d102d634
commit eb541bb819
4 changed files with 12 additions and 13 deletions

View File

@ -92,7 +92,6 @@ type KubeControllerManagerOptions struct {
Logs *logs.Options
Master string
Kubeconfig string
ShowHiddenMetricsForVersion string
}
@ -260,7 +259,7 @@ func (s *KubeControllerManagerOptions) Flags(allControllers []string, disabledBy
fs := fss.FlagSet("misc")
fs.StringVar(&s.Master, "master", s.Master, "The address of the Kubernetes API server (overrides any value in kubeconfig).")
fs.StringVar(&s.Kubeconfig, "kubeconfig", s.Kubeconfig, "Path to kubeconfig file with authorization and master location information.")
fs.StringVar(&s.Generic.ClientConnection.Kubeconfig, "kubeconfig", s.Generic.ClientConnection.Kubeconfig, "Path to kubeconfig file with authorization and master location information (the master location can be overridden by the master flag).")
utilfeature.DefaultMutableFeatureGate.AddFlag(fss.FlagSet("generic"))
return fss
@ -414,7 +413,7 @@ func (s KubeControllerManagerOptions) Config(allControllers []string, disabledBy
return nil, fmt.Errorf("error creating self-signed certificates: %v", err)
}
kubeconfig, err := clientcmd.BuildConfigFromFlags(s.Master, s.Kubeconfig)
kubeconfig, err := clientcmd.BuildConfigFromFlags(s.Master, s.Generic.ClientConnection.Kubeconfig)
if err != nil {
return nil, err
}

View File

@ -180,6 +180,7 @@ func TestAddFlags(t *testing.T) {
Address: "0.0.0.0", // Note: This field should have no effect in CM now, and "0.0.0.0" is the default value.
MinResyncPeriod: metav1.Duration{Duration: 8 * time.Hour},
ClientConnection: componentbaseconfig.ClientConnectionConfiguration{
Kubeconfig: "/kubeconfig",
ContentType: "application/json",
QPS: 50.0,
Burst: 100,
@ -434,10 +435,9 @@ func TestAddFlags(t *testing.T) {
AlwaysAllowPaths: []string{"/healthz", "/readyz", "/livez"}, // note: this does not match /healthz/ or /healthz/*
AlwaysAllowGroups: []string{"system:masters"},
},
Kubeconfig: "/kubeconfig",
Master: "192.168.4.20",
Metrics: &metrics.Options{},
Logs: logs.NewOptions(),
Master: "192.168.4.20",
Metrics: &metrics.Options{},
Logs: logs.NewOptions(),
}
// Sort GCIgnoredResources because it's built from a map, which means the
@ -468,6 +468,7 @@ func TestApplyTo(t *testing.T) {
Address: "0.0.0.0", // Note: This field should have no effect in CM now, and "0.0.0.0" is the default value.
MinResyncPeriod: metav1.Duration{Duration: 8 * time.Hour},
ClientConnection: componentbaseconfig.ClientConnectionConfiguration{
Kubeconfig: "/kubeconfig",
ContentType: "application/json",
QPS: 50.0,
Burst: 100,

View File

@ -63,8 +63,7 @@ type CloudControllerManagerOptions struct {
Authentication *apiserveroptions.DelegatingAuthenticationOptions
Authorization *apiserveroptions.DelegatingAuthorizationOptions
Master string
Kubeconfig string
Master string
// NodeStatusUpdateFrequency is the frequency at which the controller updates nodes' status
NodeStatusUpdateFrequency metav1.Duration
@ -133,7 +132,7 @@ func (o *CloudControllerManagerOptions) Flags(allControllers, disabledByDefaultC
fs := fss.FlagSet("misc")
fs.StringVar(&o.Master, "master", o.Master, "The address of the Kubernetes API server (overrides any value in kubeconfig).")
fs.StringVar(&o.Kubeconfig, "kubeconfig", o.Kubeconfig, "Path to kubeconfig file with authorization and master location information.")
fs.StringVar(&o.Generic.ClientConnection.Kubeconfig, "kubeconfig", o.Generic.ClientConnection.Kubeconfig, "Path to kubeconfig file with authorization and master location information (the master location can be overridden by the master flag).")
fs.DurationVar(&o.NodeStatusUpdateFrequency.Duration, "node-status-update-frequency", o.NodeStatusUpdateFrequency.Duration, "Specifies how often the controller updates nodes' status.")
utilfeature.DefaultMutableFeatureGate.AddFlag(fss.FlagSet("generic"))
@ -148,7 +147,7 @@ func (o *CloudControllerManagerOptions) ApplyTo(c *config.Config, userAgent stri
// Build kubeconfig first to so that if it fails, it doesn't cause leaking
// goroutines (started from initializing secure serving - which underneath
// creates a queue which in its constructor starts a goroutine).
c.Kubeconfig, err = clientcmd.BuildConfigFromFlags(o.Master, o.Kubeconfig)
c.Kubeconfig, err = clientcmd.BuildConfigFromFlags(o.Master, o.Generic.ClientConnection.Kubeconfig)
if err != nil {
return err
}

View File

@ -44,6 +44,7 @@ func TestDefaultFlags(t *testing.T) {
Address: "0.0.0.0",
MinResyncPeriod: metav1.Duration{Duration: 12 * time.Hour},
ClientConnection: componentbaseconfig.ClientConnectionConfiguration{
Kubeconfig: "",
ContentType: "application/vnd.kubernetes.protobuf",
QPS: 20.0,
Burst: 30,
@ -125,7 +126,6 @@ func TestDefaultFlags(t *testing.T) {
AlwaysAllowPaths: []string{"/healthz", "/readyz", "/livez"}, // note: this does not match /healthz/ or /healthz/*
AlwaysAllowGroups: []string{"system:masters"},
},
Kubeconfig: "",
Master: "",
NodeStatusUpdateFrequency: metav1.Duration{Duration: 5 * time.Minute},
}
@ -188,6 +188,7 @@ func TestAddFlags(t *testing.T) {
Address: "0.0.0.0",
MinResyncPeriod: metav1.Duration{Duration: 100 * time.Minute},
ClientConnection: componentbaseconfig.ClientConnectionConfiguration{
Kubeconfig: "/kubeconfig",
ContentType: "application/vnd.kubernetes.protobuf",
QPS: 50.0,
Burst: 100,
@ -269,7 +270,6 @@ func TestAddFlags(t *testing.T) {
AlwaysAllowPaths: []string{},
AlwaysAllowGroups: []string{"system:masters"},
},
Kubeconfig: "/kubeconfig",
Master: "192.168.4.20",
NodeStatusUpdateFrequency: metav1.Duration{Duration: 10 * time.Minute},
}