k3s/vendor/k8s.io/kubernetes/cmd/kube-controller-manager/app/options/options.go

466 lines
20 KiB
Go
Raw Normal View History

2019-01-12 04:58:27 +00:00
/*
Copyright 2014 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Package options provides the flags used for the controller manager.
//
package options
import (
"fmt"
"net"
2019-04-07 17:07:55 +00:00
v1 "k8s.io/api/core/v1"
2019-01-12 04:58:27 +00:00
utilerrors "k8s.io/apimachinery/pkg/util/errors"
apiserveroptions "k8s.io/apiserver/pkg/server/options"
utilfeature "k8s.io/apiserver/pkg/util/feature"
clientset "k8s.io/client-go/kubernetes"
2019-04-07 17:07:55 +00:00
clientgokubescheme "k8s.io/client-go/kubernetes/scheme"
2019-01-12 04:58:27 +00:00
v1core "k8s.io/client-go/kubernetes/typed/core/v1"
restclient "k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/client-go/tools/record"
cpoptions "k8s.io/cloud-provider/options"
2019-04-07 17:07:55 +00:00
cliflag "k8s.io/component-base/cli/flag"
2020-08-10 17:43:49 +00:00
"k8s.io/component-base/logs"
2020-03-26 21:07:15 +00:00
"k8s.io/component-base/metrics"
cmoptions "k8s.io/controller-manager/options"
2019-01-12 04:58:27 +00:00
kubectrlmgrconfigv1alpha1 "k8s.io/kube-controller-manager/config/v1alpha1"
kubecontrollerconfig "k8s.io/kubernetes/cmd/kube-controller-manager/app/config"
"k8s.io/kubernetes/pkg/cluster/ports"
2019-01-12 04:58:27 +00:00
kubectrlmgrconfig "k8s.io/kubernetes/pkg/controller/apis/config"
2019-04-07 17:07:55 +00:00
kubectrlmgrconfigscheme "k8s.io/kubernetes/pkg/controller/apis/config/scheme"
2019-01-12 04:58:27 +00:00
"k8s.io/kubernetes/pkg/controller/garbagecollector"
2019-08-30 18:33:25 +00:00
garbagecollectorconfig "k8s.io/kubernetes/pkg/controller/garbagecollector/config"
2019-01-12 04:58:27 +00:00
// add the kubernetes feature gates
_ "k8s.io/kubernetes/pkg/features"
)
const (
// KubeControllerManagerUserAgent is the userAgent name when starting kube-controller managers.
KubeControllerManagerUserAgent = "kube-controller-manager"
)
// KubeControllerManagerOptions is the main context object for the kube-controller manager.
type KubeControllerManagerOptions struct {
Generic *cmoptions.GenericControllerManagerConfigurationOptions
KubeCloudShared *cpoptions.KubeCloudSharedOptions
ServiceController *cpoptions.ServiceControllerOptions
2019-01-12 04:58:27 +00:00
AttachDetachController *AttachDetachControllerOptions
CSRSigningController *CSRSigningControllerOptions
DaemonSetController *DaemonSetControllerOptions
DeploymentController *DeploymentControllerOptions
2019-09-27 21:51:53 +00:00
StatefulSetController *StatefulSetControllerOptions
2019-01-12 04:58:27 +00:00
DeprecatedFlags *DeprecatedControllerOptions
EndpointController *EndpointControllerOptions
2019-09-27 21:51:53 +00:00
EndpointSliceController *EndpointSliceControllerOptions
2020-08-10 17:43:49 +00:00
EndpointSliceMirroringController *EndpointSliceMirroringControllerOptions
2019-01-12 04:58:27 +00:00
GarbageCollectorController *GarbageCollectorControllerOptions
HPAController *HPAControllerOptions
JobController *JobControllerOptions
CronJobController *CronJobControllerOptions
2019-01-12 04:58:27 +00:00
NamespaceController *NamespaceControllerOptions
NodeIPAMController *NodeIPAMControllerOptions
NodeLifecycleController *NodeLifecycleControllerOptions
PersistentVolumeBinderController *PersistentVolumeBinderControllerOptions
PodGCController *PodGCControllerOptions
ReplicaSetController *ReplicaSetControllerOptions
ReplicationController *ReplicationControllerOptions
ResourceQuotaController *ResourceQuotaControllerOptions
SAController *SAControllerOptions
TTLAfterFinishedController *TTLAfterFinishedControllerOptions
SecureServing *apiserveroptions.SecureServingOptionsWithLoopback
// TODO: remove insecure serving mode
InsecureServing *apiserveroptions.DeprecatedInsecureServingOptionsWithLoopback
Authentication *apiserveroptions.DelegatingAuthenticationOptions
Authorization *apiserveroptions.DelegatingAuthorizationOptions
2020-08-10 17:43:49 +00:00
Metrics *metrics.Options
Logs *logs.Options
2019-01-12 04:58:27 +00:00
2020-03-26 21:07:15 +00:00
Master string
Kubeconfig string
ShowHiddenMetricsForVersion string
2019-01-12 04:58:27 +00:00
}
// NewKubeControllerManagerOptions creates a new KubeControllerManagerOptions with a default config.
func NewKubeControllerManagerOptions() (*KubeControllerManagerOptions, error) {
componentConfig, err := NewDefaultComponentConfig(ports.InsecureKubeControllerManagerPort)
if err != nil {
return nil, err
}
s := KubeControllerManagerOptions{
2019-04-07 17:07:55 +00:00
Generic: cmoptions.NewGenericControllerManagerConfigurationOptions(&componentConfig.Generic),
KubeCloudShared: cpoptions.NewKubeCloudSharedOptions(&componentConfig.KubeCloudShared),
ServiceController: &cpoptions.ServiceControllerOptions{
2019-04-07 17:07:55 +00:00
ServiceControllerConfiguration: &componentConfig.ServiceController,
},
2019-01-12 04:58:27 +00:00
AttachDetachController: &AttachDetachControllerOptions{
2019-04-07 17:07:55 +00:00
&componentConfig.AttachDetachController,
2019-01-12 04:58:27 +00:00
},
CSRSigningController: &CSRSigningControllerOptions{
2019-04-07 17:07:55 +00:00
&componentConfig.CSRSigningController,
2019-01-12 04:58:27 +00:00
},
DaemonSetController: &DaemonSetControllerOptions{
2019-04-07 17:07:55 +00:00
&componentConfig.DaemonSetController,
2019-01-12 04:58:27 +00:00
},
DeploymentController: &DeploymentControllerOptions{
2019-04-07 17:07:55 +00:00
&componentConfig.DeploymentController,
2019-01-12 04:58:27 +00:00
},
2019-09-27 21:51:53 +00:00
StatefulSetController: &StatefulSetControllerOptions{
&componentConfig.StatefulSetController,
},
2019-01-12 04:58:27 +00:00
DeprecatedFlags: &DeprecatedControllerOptions{
2019-04-07 17:07:55 +00:00
&componentConfig.DeprecatedController,
2019-01-12 04:58:27 +00:00
},
EndpointController: &EndpointControllerOptions{
2019-04-07 17:07:55 +00:00
&componentConfig.EndpointController,
2019-01-12 04:58:27 +00:00
},
2019-09-27 21:51:53 +00:00
EndpointSliceController: &EndpointSliceControllerOptions{
&componentConfig.EndpointSliceController,
},
2020-08-10 17:43:49 +00:00
EndpointSliceMirroringController: &EndpointSliceMirroringControllerOptions{
&componentConfig.EndpointSliceMirroringController,
},
2019-01-12 04:58:27 +00:00
GarbageCollectorController: &GarbageCollectorControllerOptions{
2019-04-07 17:07:55 +00:00
&componentConfig.GarbageCollectorController,
2019-01-12 04:58:27 +00:00
},
HPAController: &HPAControllerOptions{
2019-04-07 17:07:55 +00:00
&componentConfig.HPAController,
2019-01-12 04:58:27 +00:00
},
JobController: &JobControllerOptions{
2019-04-07 17:07:55 +00:00
&componentConfig.JobController,
2019-01-12 04:58:27 +00:00
},
CronJobController: &CronJobControllerOptions{
&componentConfig.CronJobController,
},
2019-01-12 04:58:27 +00:00
NamespaceController: &NamespaceControllerOptions{
2019-04-07 17:07:55 +00:00
&componentConfig.NamespaceController,
2019-01-12 04:58:27 +00:00
},
NodeIPAMController: &NodeIPAMControllerOptions{
2019-04-07 17:07:55 +00:00
&componentConfig.NodeIPAMController,
2019-01-12 04:58:27 +00:00
},
NodeLifecycleController: &NodeLifecycleControllerOptions{
2019-04-07 17:07:55 +00:00
&componentConfig.NodeLifecycleController,
2019-01-12 04:58:27 +00:00
},
PersistentVolumeBinderController: &PersistentVolumeBinderControllerOptions{
2019-04-07 17:07:55 +00:00
&componentConfig.PersistentVolumeBinderController,
2019-01-12 04:58:27 +00:00
},
PodGCController: &PodGCControllerOptions{
2019-04-07 17:07:55 +00:00
&componentConfig.PodGCController,
2019-01-12 04:58:27 +00:00
},
ReplicaSetController: &ReplicaSetControllerOptions{
2019-04-07 17:07:55 +00:00
&componentConfig.ReplicaSetController,
2019-01-12 04:58:27 +00:00
},
ReplicationController: &ReplicationControllerOptions{
2019-04-07 17:07:55 +00:00
&componentConfig.ReplicationController,
2019-01-12 04:58:27 +00:00
},
ResourceQuotaController: &ResourceQuotaControllerOptions{
2019-04-07 17:07:55 +00:00
&componentConfig.ResourceQuotaController,
2019-01-12 04:58:27 +00:00
},
SAController: &SAControllerOptions{
2019-04-07 17:07:55 +00:00
&componentConfig.SAController,
2019-01-12 04:58:27 +00:00
},
TTLAfterFinishedController: &TTLAfterFinishedControllerOptions{
2019-04-07 17:07:55 +00:00
&componentConfig.TTLAfterFinishedController,
2019-01-12 04:58:27 +00:00
},
SecureServing: apiserveroptions.NewSecureServingOptions().WithLoopback(),
InsecureServing: (&apiserveroptions.DeprecatedInsecureServingOptions{
BindAddress: net.ParseIP(componentConfig.Generic.Address),
BindPort: int(componentConfig.Generic.Port),
BindNetwork: "tcp",
}).WithLoopback(),
Authentication: apiserveroptions.NewDelegatingAuthenticationOptions(),
Authorization: apiserveroptions.NewDelegatingAuthorizationOptions(),
2020-08-10 17:43:49 +00:00
Metrics: metrics.NewOptions(),
Logs: logs.NewOptions(),
2019-01-12 04:58:27 +00:00
}
s.Authentication.RemoteKubeConfigFileOptional = true
s.Authorization.RemoteKubeConfigFileOptional = true
// Set the PairName but leave certificate directory blank to generate in-memory by default
s.SecureServing.ServerCert.CertDirectory = ""
s.SecureServing.ServerCert.PairName = "kube-controller-manager"
s.SecureServing.BindPort = ports.KubeControllerManagerPort
2019-08-30 18:33:25 +00:00
gcIgnoredResources := make([]garbagecollectorconfig.GroupResource, 0, len(garbagecollector.DefaultIgnoredResources()))
2019-01-12 04:58:27 +00:00
for r := range garbagecollector.DefaultIgnoredResources() {
2019-08-30 18:33:25 +00:00
gcIgnoredResources = append(gcIgnoredResources, garbagecollectorconfig.GroupResource{Group: r.Group, Resource: r.Resource})
2019-01-12 04:58:27 +00:00
}
s.GarbageCollectorController.GCIgnoredResources = gcIgnoredResources
2019-09-27 21:51:53 +00:00
s.Generic.LeaderElection.ResourceName = "kube-controller-manager"
s.Generic.LeaderElection.ResourceNamespace = "kube-system"
2019-01-12 04:58:27 +00:00
return &s, nil
}
// NewDefaultComponentConfig returns kube-controller manager configuration object.
func NewDefaultComponentConfig(insecurePort int32) (kubectrlmgrconfig.KubeControllerManagerConfiguration, error) {
versioned := kubectrlmgrconfigv1alpha1.KubeControllerManagerConfiguration{}
2019-04-07 17:07:55 +00:00
kubectrlmgrconfigscheme.Scheme.Default(&versioned)
2019-01-12 04:58:27 +00:00
internal := kubectrlmgrconfig.KubeControllerManagerConfiguration{}
2019-04-07 17:07:55 +00:00
if err := kubectrlmgrconfigscheme.Scheme.Convert(&versioned, &internal, nil); err != nil {
2019-01-12 04:58:27 +00:00
return internal, err
}
internal.Generic.Port = insecurePort
return internal, nil
}
// Flags returns flags for a specific APIServer by section name
2019-04-07 17:07:55 +00:00
func (s *KubeControllerManagerOptions) Flags(allControllers []string, disabledByDefaultControllers []string) cliflag.NamedFlagSets {
fss := cliflag.NamedFlagSets{}
2019-01-12 04:58:27 +00:00
s.Generic.AddFlags(&fss, allControllers, disabledByDefaultControllers)
s.KubeCloudShared.AddFlags(fss.FlagSet("generic"))
s.ServiceController.AddFlags(fss.FlagSet("service controller"))
s.SecureServing.AddFlags(fss.FlagSet("secure serving"))
s.InsecureServing.AddUnqualifiedFlags(fss.FlagSet("insecure serving"))
s.Authentication.AddFlags(fss.FlagSet("authentication"))
s.Authorization.AddFlags(fss.FlagSet("authorization"))
s.AttachDetachController.AddFlags(fss.FlagSet("attachdetach controller"))
s.CSRSigningController.AddFlags(fss.FlagSet("csrsigning controller"))
s.DeploymentController.AddFlags(fss.FlagSet("deployment controller"))
2019-09-27 21:51:53 +00:00
s.StatefulSetController.AddFlags(fss.FlagSet("statefulset controller"))
2019-01-12 04:58:27 +00:00
s.DaemonSetController.AddFlags(fss.FlagSet("daemonset controller"))
s.DeprecatedFlags.AddFlags(fss.FlagSet("deprecated"))
s.EndpointController.AddFlags(fss.FlagSet("endpoint controller"))
2019-09-27 21:51:53 +00:00
s.EndpointSliceController.AddFlags(fss.FlagSet("endpointslice controller"))
2020-08-10 17:43:49 +00:00
s.EndpointSliceMirroringController.AddFlags(fss.FlagSet("endpointslicemirroring controller"))
2019-01-12 04:58:27 +00:00
s.GarbageCollectorController.AddFlags(fss.FlagSet("garbagecollector controller"))
s.HPAController.AddFlags(fss.FlagSet("horizontalpodautoscaling controller"))
s.JobController.AddFlags(fss.FlagSet("job controller"))
s.CronJobController.AddFlags(fss.FlagSet("cronjob controller"))
2019-01-12 04:58:27 +00:00
s.NamespaceController.AddFlags(fss.FlagSet("namespace controller"))
s.NodeIPAMController.AddFlags(fss.FlagSet("nodeipam controller"))
s.NodeLifecycleController.AddFlags(fss.FlagSet("nodelifecycle controller"))
s.PersistentVolumeBinderController.AddFlags(fss.FlagSet("persistentvolume-binder controller"))
s.PodGCController.AddFlags(fss.FlagSet("podgc controller"))
s.ReplicaSetController.AddFlags(fss.FlagSet("replicaset controller"))
s.ReplicationController.AddFlags(fss.FlagSet("replicationcontroller"))
s.ResourceQuotaController.AddFlags(fss.FlagSet("resourcequota controller"))
s.SAController.AddFlags(fss.FlagSet("serviceaccount controller"))
s.TTLAfterFinishedController.AddFlags(fss.FlagSet("ttl-after-finished controller"))
2020-08-10 17:43:49 +00:00
s.Metrics.AddFlags(fss.FlagSet("metrics"))
s.Logs.AddFlags(fss.FlagSet("logs"))
2019-01-12 04:58:27 +00:00
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.")
2019-04-07 17:07:55 +00:00
utilfeature.DefaultMutableFeatureGate.AddFlag(fss.FlagSet("generic"))
2019-01-12 04:58:27 +00:00
return fss
}
// ApplyTo fills up controller manager config with options.
func (s *KubeControllerManagerOptions) ApplyTo(c *kubecontrollerconfig.Config) error {
if err := s.Generic.ApplyTo(&c.ComponentConfig.Generic); err != nil {
return err
}
if err := s.KubeCloudShared.ApplyTo(&c.ComponentConfig.KubeCloudShared); err != nil {
return err
}
if err := s.AttachDetachController.ApplyTo(&c.ComponentConfig.AttachDetachController); err != nil {
return err
}
if err := s.CSRSigningController.ApplyTo(&c.ComponentConfig.CSRSigningController); err != nil {
return err
}
if err := s.DaemonSetController.ApplyTo(&c.ComponentConfig.DaemonSetController); err != nil {
return err
}
if err := s.DeploymentController.ApplyTo(&c.ComponentConfig.DeploymentController); err != nil {
return err
}
2019-09-27 21:51:53 +00:00
if err := s.StatefulSetController.ApplyTo(&c.ComponentConfig.StatefulSetController); err != nil {
return err
}
2019-01-12 04:58:27 +00:00
if err := s.DeprecatedFlags.ApplyTo(&c.ComponentConfig.DeprecatedController); err != nil {
return err
}
if err := s.EndpointController.ApplyTo(&c.ComponentConfig.EndpointController); err != nil {
return err
}
2019-09-27 21:51:53 +00:00
if err := s.EndpointSliceController.ApplyTo(&c.ComponentConfig.EndpointSliceController); err != nil {
return err
}
2020-08-10 17:43:49 +00:00
if err := s.EndpointSliceMirroringController.ApplyTo(&c.ComponentConfig.EndpointSliceMirroringController); err != nil {
return err
}
2019-01-12 04:58:27 +00:00
if err := s.GarbageCollectorController.ApplyTo(&c.ComponentConfig.GarbageCollectorController); err != nil {
return err
}
if err := s.HPAController.ApplyTo(&c.ComponentConfig.HPAController); err != nil {
return err
}
if err := s.JobController.ApplyTo(&c.ComponentConfig.JobController); err != nil {
return err
}
if err := s.CronJobController.ApplyTo(&c.ComponentConfig.CronJobController); err != nil {
return err
}
2019-01-12 04:58:27 +00:00
if err := s.NamespaceController.ApplyTo(&c.ComponentConfig.NamespaceController); err != nil {
return err
}
if err := s.NodeIPAMController.ApplyTo(&c.ComponentConfig.NodeIPAMController); err != nil {
return err
}
if err := s.NodeLifecycleController.ApplyTo(&c.ComponentConfig.NodeLifecycleController); err != nil {
return err
}
if err := s.PersistentVolumeBinderController.ApplyTo(&c.ComponentConfig.PersistentVolumeBinderController); err != nil {
return err
}
if err := s.PodGCController.ApplyTo(&c.ComponentConfig.PodGCController); err != nil {
return err
}
if err := s.ReplicaSetController.ApplyTo(&c.ComponentConfig.ReplicaSetController); err != nil {
return err
}
if err := s.ReplicationController.ApplyTo(&c.ComponentConfig.ReplicationController); err != nil {
return err
}
if err := s.ResourceQuotaController.ApplyTo(&c.ComponentConfig.ResourceQuotaController); err != nil {
return err
}
if err := s.SAController.ApplyTo(&c.ComponentConfig.SAController); err != nil {
return err
}
if err := s.ServiceController.ApplyTo(&c.ComponentConfig.ServiceController); err != nil {
return err
}
if err := s.TTLAfterFinishedController.ApplyTo(&c.ComponentConfig.TTLAfterFinishedController); err != nil {
return err
}
if err := s.InsecureServing.ApplyTo(&c.InsecureServing, &c.LoopbackClientConfig); err != nil {
return err
}
if err := s.SecureServing.ApplyTo(&c.SecureServing, &c.LoopbackClientConfig); err != nil {
return err
}
if s.SecureServing.BindPort != 0 || s.SecureServing.Listener != nil {
2019-08-30 18:33:25 +00:00
if err := s.Authentication.ApplyTo(&c.Authentication, c.SecureServing, nil); err != nil {
2019-01-12 04:58:27 +00:00
return err
}
if err := s.Authorization.ApplyTo(&c.Authorization); err != nil {
return err
}
}
// sync back to component config
// TODO: find more elegant way than syncing back the values.
c.ComponentConfig.Generic.Port = int32(s.InsecureServing.BindPort)
c.ComponentConfig.Generic.Address = s.InsecureServing.BindAddress.String()
return nil
}
// Validate is used to validate the options and config before launching the controller manager
func (s *KubeControllerManagerOptions) Validate(allControllers []string, disabledByDefaultControllers []string) error {
var errs []error
errs = append(errs, s.Generic.Validate(allControllers, disabledByDefaultControllers)...)
errs = append(errs, s.KubeCloudShared.Validate()...)
errs = append(errs, s.AttachDetachController.Validate()...)
errs = append(errs, s.CSRSigningController.Validate()...)
errs = append(errs, s.DaemonSetController.Validate()...)
errs = append(errs, s.DeploymentController.Validate()...)
2019-09-27 21:51:53 +00:00
errs = append(errs, s.StatefulSetController.Validate()...)
2019-01-12 04:58:27 +00:00
errs = append(errs, s.DeprecatedFlags.Validate()...)
errs = append(errs, s.EndpointController.Validate()...)
2019-09-27 21:51:53 +00:00
errs = append(errs, s.EndpointSliceController.Validate()...)
2020-08-10 17:43:49 +00:00
errs = append(errs, s.EndpointSliceMirroringController.Validate()...)
2019-01-12 04:58:27 +00:00
errs = append(errs, s.GarbageCollectorController.Validate()...)
errs = append(errs, s.HPAController.Validate()...)
errs = append(errs, s.JobController.Validate()...)
errs = append(errs, s.CronJobController.Validate()...)
2019-01-12 04:58:27 +00:00
errs = append(errs, s.NamespaceController.Validate()...)
errs = append(errs, s.NodeIPAMController.Validate()...)
errs = append(errs, s.NodeLifecycleController.Validate()...)
errs = append(errs, s.PersistentVolumeBinderController.Validate()...)
errs = append(errs, s.PodGCController.Validate()...)
errs = append(errs, s.ReplicaSetController.Validate()...)
errs = append(errs, s.ReplicationController.Validate()...)
errs = append(errs, s.ResourceQuotaController.Validate()...)
errs = append(errs, s.SAController.Validate()...)
errs = append(errs, s.ServiceController.Validate()...)
errs = append(errs, s.TTLAfterFinishedController.Validate()...)
errs = append(errs, s.SecureServing.Validate()...)
errs = append(errs, s.InsecureServing.Validate()...)
errs = append(errs, s.Authentication.Validate()...)
errs = append(errs, s.Authorization.Validate()...)
2020-08-10 17:43:49 +00:00
errs = append(errs, s.Metrics.Validate()...)
errs = append(errs, s.Logs.Validate()...)
2019-01-12 04:58:27 +00:00
// TODO: validate component config, master and kubeconfig
return utilerrors.NewAggregate(errs)
}
// Config return a controller manager config objective
func (s KubeControllerManagerOptions) Config(allControllers []string, disabledByDefaultControllers []string) (*kubecontrollerconfig.Config, error) {
if err := s.Validate(allControllers, disabledByDefaultControllers); err != nil {
return nil, err
}
if err := s.SecureServing.MaybeDefaultWithSelfSignedCerts("localhost", nil, []net.IP{net.ParseIP("127.0.0.1")}); err != nil {
return nil, fmt.Errorf("error creating self-signed certificates: %v", err)
}
kubeconfig, err := clientcmd.BuildConfigFromFlags(s.Master, s.Kubeconfig)
if err != nil {
return nil, err
}
2019-09-27 21:51:53 +00:00
kubeconfig.DisableCompression = true
2019-12-12 01:27:03 +00:00
kubeconfig.ContentConfig.AcceptContentTypes = s.Generic.ClientConnection.AcceptContentTypes
2019-01-12 04:58:27 +00:00
kubeconfig.ContentConfig.ContentType = s.Generic.ClientConnection.ContentType
kubeconfig.QPS = s.Generic.ClientConnection.QPS
kubeconfig.Burst = int(s.Generic.ClientConnection.Burst)
client, err := clientset.NewForConfig(restclient.AddUserAgent(kubeconfig, KubeControllerManagerUserAgent))
if err != nil {
return nil, err
}
eventRecorder := createRecorder(client, KubeControllerManagerUserAgent)
c := &kubecontrollerconfig.Config{
Client: client,
Kubeconfig: kubeconfig,
EventRecorder: eventRecorder,
2019-01-12 04:58:27 +00:00
}
if err := s.ApplyTo(c); err != nil {
return nil, err
}
2020-08-10 17:43:49 +00:00
s.Metrics.Apply()
2019-01-12 04:58:27 +00:00
2020-08-10 17:43:49 +00:00
s.Logs.Apply()
2020-03-26 21:07:15 +00:00
2019-01-12 04:58:27 +00:00
return c, nil
}
func createRecorder(kubeClient clientset.Interface, userAgent string) record.EventRecorder {
eventBroadcaster := record.NewBroadcaster()
2020-08-10 17:43:49 +00:00
eventBroadcaster.StartStructuredLogging(0)
2019-01-12 04:58:27 +00:00
eventBroadcaster.StartRecordingToSink(&v1core.EventSinkImpl{Interface: kubeClient.CoreV1().Events("")})
2019-04-07 17:07:55 +00:00
return eventBroadcaster.NewRecorder(clientgokubescheme.Scheme, v1.EventSource{Component: userAgent})
2019-01-12 04:58:27 +00:00
}