diff --git a/cmd/cloud-controller-manager/app/options/options.go b/cmd/cloud-controller-manager/app/options/options.go index cfde5f3b7e..433d993516 100644 --- a/cmd/cloud-controller-manager/app/options/options.go +++ b/cmd/cloud-controller-manager/app/options/options.go @@ -18,24 +18,49 @@ package options import ( "fmt" - "time" + "net" + "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" utilerrors "k8s.io/apimachinery/pkg/util/errors" + apiserveroptions "k8s.io/apiserver/pkg/server/options" utilfeature "k8s.io/apiserver/pkg/util/feature" + "k8s.io/client-go/kubernetes" + clientset "k8s.io/client-go/kubernetes" + 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" cloudcontrollerconfig "k8s.io/kubernetes/cmd/cloud-controller-manager/app/config" cmoptions "k8s.io/kubernetes/cmd/controller-manager/app/options" + "k8s.io/kubernetes/pkg/api/legacyscheme" + "k8s.io/kubernetes/pkg/apis/componentconfig" + componentconfigv1alpha1 "k8s.io/kubernetes/pkg/apis/componentconfig/v1alpha1" "k8s.io/kubernetes/pkg/master/ports" - // add the kubernetes feature gates _ "k8s.io/kubernetes/pkg/features" + "github.com/golang/glog" "github.com/spf13/pflag" ) // CloudControllerManagerOptions is the main context object for the controller manager. type CloudControllerManagerOptions struct { - Generic *cmoptions.GenericControllerManagerOptions + CloudProvider *cmoptions.CloudProviderOptions + Debugging *cmoptions.DebuggingOptions + GenericComponent *cmoptions.GenericComponentConfigOptions + KubeCloudShared *cmoptions.KubeCloudSharedOptions + ServiceController *cmoptions.ServiceControllerOptions + + SecureServing *apiserveroptions.SecureServingOptions + // TODO: remove insecure serving mode + InsecureServing *cmoptions.InsecureServingOptions + Authentication *apiserveroptions.DelegatingAuthenticationOptions + Authorization *apiserveroptions.DelegatingAuthorizationOptions + + Master string + Kubeconfig string // NodeStatusUpdateFrequency is the frequency at which the controller updates nodes' status NodeStatusUpdateFrequency metav1.Duration @@ -43,37 +68,125 @@ type CloudControllerManagerOptions struct { // NewCloudControllerManagerOptions creates a new ExternalCMServer with a default config. func NewCloudControllerManagerOptions() *CloudControllerManagerOptions { - componentConfig := cmoptions.NewDefaultControllerManagerComponentConfig(ports.InsecureCloudControllerManagerPort) + componentConfig := NewDefaultComponentConfig(ports.InsecureCloudControllerManagerPort) s := CloudControllerManagerOptions{ - // The common/default are kept in 'cmd/kube-controller-manager/app/options/util.go'. - // Please make common changes there and put anything cloud specific here. - Generic: cmoptions.NewGenericControllerManagerOptions(componentConfig), - NodeStatusUpdateFrequency: metav1.Duration{Duration: 5 * time.Minute}, + CloudProvider: &cmoptions.CloudProviderOptions{}, + Debugging: &cmoptions.DebuggingOptions{}, + GenericComponent: cmoptions.NewGenericComponentConfigOptions(componentConfig.GenericComponent), + KubeCloudShared: cmoptions.NewKubeCloudSharedOptions(componentConfig.KubeCloudShared), + ServiceController: &cmoptions.ServiceControllerOptions{ + ConcurrentServiceSyncs: componentConfig.ServiceController.ConcurrentServiceSyncs, + }, + SecureServing: apiserveroptions.NewSecureServingOptions(), + InsecureServing: &cmoptions.InsecureServingOptions{ + BindAddress: net.ParseIP(componentConfig.KubeCloudShared.Address), + BindPort: int(componentConfig.KubeCloudShared.Port), + BindNetwork: "tcp", + }, + Authentication: nil, // TODO: enable with apiserveroptions.NewDelegatingAuthenticationOptions() + Authorization: nil, // TODO: enable with apiserveroptions.NewDelegatingAuthorizationOptions() + NodeStatusUpdateFrequency: componentConfig.NodeStatusUpdateFrequency, } - s.Generic.SecureServing.ServerCert.CertDirectory = "/var/run/kubernetes" - s.Generic.SecureServing.ServerCert.PairName = "cloud-controller-manager" + s.SecureServing.ServerCert.CertDirectory = "/var/run/kubernetes" + s.SecureServing.ServerCert.PairName = "cloud-controller-manager" + + // disable secure serving for now + // TODO: enable HTTPS by default + s.SecureServing.BindPort = 0 return &s } +// NewDefaultComponentConfig returns cloud-controller manager configuration object. +func NewDefaultComponentConfig(insecurePort int32) componentconfig.CloudControllerManagerConfiguration { + scheme := runtime.NewScheme() + componentconfigv1alpha1.AddToScheme(scheme) + componentconfig.AddToScheme(scheme) + + versioned := componentconfigv1alpha1.CloudControllerManagerConfiguration{} + scheme.Default(&versioned) + + internal := componentconfig.CloudControllerManagerConfiguration{} + scheme.Convert(&versioned, &internal, nil) + internal.KubeCloudShared.Port = insecurePort + return internal +} + // AddFlags adds flags for a specific ExternalCMServer to the specified FlagSet func (o *CloudControllerManagerOptions) AddFlags(fs *pflag.FlagSet) { - o.Generic.AddFlags(fs) + o.CloudProvider.AddFlags(fs) + o.Debugging.AddFlags(fs) + o.GenericComponent.AddFlags(fs) + o.KubeCloudShared.AddFlags(fs) + o.ServiceController.AddFlags(fs) + o.SecureServing.AddFlags(fs) + o.InsecureServing.AddFlags(fs) + o.Authentication.AddFlags(fs) + o.Authorization.AddFlags(fs) + + 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.DurationVar(&o.NodeStatusUpdateFrequency.Duration, "node-status-update-frequency", o.NodeStatusUpdateFrequency.Duration, "Specifies how often the controller updates nodes' status.") utilfeature.DefaultFeatureGate.AddFlag(fs) } // ApplyTo fills up cloud controller manager config with options. -func (o *CloudControllerManagerOptions) ApplyTo(c *cloudcontrollerconfig.Config) error { - if err := o.Generic.ApplyTo(&c.Generic, "cloud-controller-manager"); err != nil { +func (o *CloudControllerManagerOptions) ApplyTo(c *cloudcontrollerconfig.Config, userAgent string) error { + if err := o.CloudProvider.ApplyTo(&c.ComponentConfig.CloudProvider); err != nil { + return err + } + if err := o.Debugging.ApplyTo(&c.ComponentConfig.Debugging); err != nil { + return err + } + if err := o.GenericComponent.ApplyTo(&c.ComponentConfig.GenericComponent); err != nil { + return err + } + if err := o.KubeCloudShared.ApplyTo(&c.ComponentConfig.KubeCloudShared); err != nil { + return err + } + if err := o.ServiceController.ApplyTo(&c.ComponentConfig.ServiceController); err != nil { + return err + } + if err := o.SecureServing.ApplyTo(&c.SecureServing); err != nil { + return err + } + if err := o.InsecureServing.ApplyTo(&c.InsecureServing); err != nil { + return err + } + if err := o.Authentication.ApplyTo(&c.Authentication, c.SecureServing, nil); err != nil { + return err + } + if err := o.Authorization.ApplyTo(&c.Authorization); err != nil { return err } - c.Extra.NodeStatusUpdateFrequency = o.NodeStatusUpdateFrequency.Duration + // sync back to component config + // TODO: find more elegant way than synching back the values. + c.ComponentConfig.KubeCloudShared.Port = int32(o.InsecureServing.BindPort) + c.ComponentConfig.KubeCloudShared.Address = o.InsecureServing.BindAddress.String() + + var err error + c.Kubeconfig, err = clientcmd.BuildConfigFromFlags(o.Master, o.Kubeconfig) + if err != nil { + return err + } + c.Kubeconfig.ContentConfig.ContentType = o.GenericComponent.ContentType + c.Kubeconfig.QPS = o.GenericComponent.KubeAPIQPS + c.Kubeconfig.Burst = int(o.GenericComponent.KubeAPIBurst) + + c.Client, err = clientset.NewForConfig(restclient.AddUserAgent(c.Kubeconfig, userAgent)) + if err != nil { + return err + } + + c.LeaderElectionClient = clientset.NewForConfigOrDie(restclient.AddUserAgent(c.Kubeconfig, "leader-election")) + + c.EventRecorder = createRecorder(c.Client, userAgent) + c.ComponentConfig.NodeStatusUpdateFrequency = o.NodeStatusUpdateFrequency return nil } @@ -81,9 +194,18 @@ func (o *CloudControllerManagerOptions) ApplyTo(c *cloudcontrollerconfig.Config) // Validate is used to validate config before launching the cloud controller manager func (o *CloudControllerManagerOptions) Validate() error { errors := []error{} - errors = append(errors, o.Generic.Validate()...) - if len(o.Generic.CloudProvider.Name) == 0 { + errors = append(errors, o.CloudProvider.Validate()...) + errors = append(errors, o.Debugging.Validate()...) + errors = append(errors, o.GenericComponent.Validate()...) + errors = append(errors, o.KubeCloudShared.Validate()...) + errors = append(errors, o.ServiceController.Validate()...) + errors = append(errors, o.SecureServing.Validate()...) + errors = append(errors, o.InsecureServing.Validate()...) + errors = append(errors, o.Authentication.Validate()...) + errors = append(errors, o.Authorization.Validate()...) + + if len(o.CloudProvider.Name) == 0 { errors = append(errors, fmt.Errorf("--cloud-provider cannot be empty")) } @@ -97,9 +219,16 @@ func (o CloudControllerManagerOptions) Config() (*cloudcontrollerconfig.Config, } c := &cloudcontrollerconfig.Config{} - if err := o.ApplyTo(c); err != nil { + if err := o.ApplyTo(c, "cloud-controller-manager"); err != nil { return nil, err } return c, nil } + +func createRecorder(kubeClient kubernetes.Interface, userAgent string) record.EventRecorder { + eventBroadcaster := record.NewBroadcaster() + eventBroadcaster.StartLogging(glog.Infof) + eventBroadcaster.StartRecordingToSink(&v1core.EventSinkImpl{Interface: kubeClient.CoreV1().Events("")}) + return eventBroadcaster.NewRecorder(legacyscheme.Scheme, v1.EventSource{Component: userAgent}) +} diff --git a/cmd/cloud-controller-manager/app/options/options_test.go b/cmd/cloud-controller-manager/app/options/options_test.go index 71c14092e9..fe2f62f0b3 100644 --- a/cmd/cloud-controller-manager/app/options/options_test.go +++ b/cmd/cloud-controller-manager/app/options/options_test.go @@ -35,139 +35,57 @@ func TestDefaultFlags(t *testing.T) { s := NewCloudControllerManagerOptions() expected := &CloudControllerManagerOptions{ - Generic: &cmoptions.GenericControllerManagerOptions{ - CloudProvider: &cmoptions.CloudProviderOptions{ - Name: "", - CloudConfigFile: "", - }, - Debugging: &cmoptions.DebuggingOptions{ - EnableContentionProfiling: false, - }, - GenericComponent: &cmoptions.GenericComponentConfigOptions{ - MinResyncPeriod: metav1.Duration{Duration: 12 * time.Hour}, - ContentType: "application/vnd.kubernetes.protobuf", - KubeAPIQPS: 20.0, - KubeAPIBurst: 30, - ControllerStartInterval: metav1.Duration{Duration: 0}, - LeaderElection: componentconfig.LeaderElectionConfiguration{ - ResourceLock: "endpoints", - LeaderElect: true, - LeaseDuration: metav1.Duration{Duration: 15 * time.Second}, - RenewDeadline: metav1.Duration{Duration: 10 * time.Second}, - RetryPeriod: metav1.Duration{Duration: 2 * time.Second}, - }, - }, - KubeCloudShared: &cmoptions.KubeCloudSharedOptions{ - Port: 10253, // Note: InsecureServingOptions.ApplyTo will write the flag value back into the component config - Address: "0.0.0.0", // Note: InsecureServingOptions.ApplyTo will write the flag value back into the component config - RouteReconciliationPeriod: metav1.Duration{Duration: 10 * time.Second}, - NodeMonitorPeriod: metav1.Duration{Duration: 5 * time.Second}, - ClusterName: "kubernetes", - ClusterCIDR: "", - AllocateNodeCIDRs: false, - CIDRAllocatorType: "", - ConfigureCloudRoutes: true, - }, - AttachDetachController: &cmoptions.AttachDetachControllerOptions{ - ReconcilerSyncLoopPeriod: metav1.Duration{Duration: 1 * time.Minute}, - }, - CSRSigningController: &cmoptions.CSRSigningControllerOptions{ - ClusterSigningCertFile: "/etc/kubernetes/ca/ca.pem", - ClusterSigningKeyFile: "/etc/kubernetes/ca/ca.key", - ClusterSigningDuration: metav1.Duration{Duration: 8760 * time.Hour}, - }, - DaemonSetController: &cmoptions.DaemonSetControllerOptions{ - ConcurrentDaemonSetSyncs: 2, - }, - DeploymentController: &cmoptions.DeploymentControllerOptions{ - ConcurrentDeploymentSyncs: 5, - DeploymentControllerSyncPeriod: metav1.Duration{Duration: 30 * time.Second}, - }, - DeprecatedFlags: &cmoptions.DeprecatedControllerOptions{ - RegisterRetryCount: 10, - }, - EndPointController: &cmoptions.EndPointControllerOptions{ - ConcurrentEndpointSyncs: 5, - }, - GarbageCollectorController: &cmoptions.GarbageCollectorControllerOptions{ - EnableGarbageCollector: true, - ConcurrentGCSyncs: 20, - }, - HPAController: &cmoptions.HPAControllerOptions{ - HorizontalPodAutoscalerSyncPeriod: metav1.Duration{Duration: 30 * time.Second}, - HorizontalPodAutoscalerUpscaleForbiddenWindow: metav1.Duration{Duration: 3 * time.Minute}, - HorizontalPodAutoscalerDownscaleForbiddenWindow: metav1.Duration{Duration: 5 * time.Minute}, - HorizontalPodAutoscalerTolerance: 0.1, - HorizontalPodAutoscalerUseRESTClients: true, - }, - JobController: &cmoptions.JobControllerOptions{ - ConcurrentJobSyncs: 5, - }, - NamespaceController: &cmoptions.NamespaceControllerOptions{ - ConcurrentNamespaceSyncs: 10, - NamespaceSyncPeriod: metav1.Duration{Duration: 5 * time.Minute}, - }, - NodeIpamController: &cmoptions.NodeIpamControllerOptions{ - NodeCIDRMaskSize: 24, - }, - NodeLifecycleController: &cmoptions.NodeLifecycleControllerOptions{ - EnableTaintManager: true, - NodeMonitorGracePeriod: metav1.Duration{Duration: 40 * time.Second}, - NodeStartupGracePeriod: metav1.Duration{Duration: 1 * time.Minute}, - PodEvictionTimeout: metav1.Duration{Duration: 5 * time.Minute}, - }, - PersistentVolumeBinderController: &cmoptions.PersistentVolumeBinderControllerOptions{ - PVClaimBinderSyncPeriod: metav1.Duration{Duration: 15 * time.Second}, - VolumeConfiguration: componentconfig.VolumeConfiguration{ - EnableDynamicProvisioning: true, - EnableHostPathProvisioning: false, - FlexVolumePluginDir: "/usr/libexec/kubernetes/kubelet-plugins/volume/exec/", - PersistentVolumeRecyclerConfiguration: componentconfig.PersistentVolumeRecyclerConfiguration{ - MaximumRetry: 3, - MinimumTimeoutNFS: 300, - IncrementTimeoutNFS: 30, - MinimumTimeoutHostPath: 60, - IncrementTimeoutHostPath: 30, - }, - }, - }, - PodGCController: &cmoptions.PodGCControllerOptions{ - TerminatedPodGCThreshold: 12500, - }, - ReplicaSetController: &cmoptions.ReplicaSetControllerOptions{ - ConcurrentRSSyncs: 5, - }, - ReplicationController: &cmoptions.ReplicationControllerOptions{ - ConcurrentRCSyncs: 5, - }, - ResourceQuotaController: &cmoptions.ResourceQuotaControllerOptions{ - ResourceQuotaSyncPeriod: metav1.Duration{Duration: 5 * time.Minute}, - ConcurrentResourceQuotaSyncs: 5, - }, - SAController: &cmoptions.SAControllerOptions{ - ConcurrentSATokenSyncs: 5, - }, - ServiceController: &cmoptions.ServiceControllerOptions{ - ConcurrentServiceSyncs: 1, - }, - Controllers: []string{"*"}, - SecureServing: &apiserveroptions.SecureServingOptions{ - BindPort: 0, - BindAddress: net.ParseIP("0.0.0.0"), - ServerCert: apiserveroptions.GeneratableKeyCert{ - CertDirectory: "/var/run/kubernetes", - PairName: "cloud-controller-manager", - }, - HTTP2MaxStreamsPerConnection: 0, - }, - InsecureServing: &cmoptions.InsecureServingOptions{ - BindAddress: net.ParseIP("0.0.0.0"), - BindPort: int(10253), - BindNetwork: "tcp", - }, - Kubeconfig: "", - Master: "", + CloudProvider: &cmoptions.CloudProviderOptions{ + Name: "", + CloudConfigFile: "", }, + Debugging: &cmoptions.DebuggingOptions{ + EnableContentionProfiling: false, + }, + GenericComponent: &cmoptions.GenericComponentConfigOptions{ + MinResyncPeriod: metav1.Duration{Duration: 12 * time.Hour}, + ContentType: "application/vnd.kubernetes.protobuf", + KubeAPIQPS: 20.0, + KubeAPIBurst: 30, + ControllerStartInterval: metav1.Duration{Duration: 0}, + LeaderElection: componentconfig.LeaderElectionConfiguration{ + ResourceLock: "endpoints", + LeaderElect: true, + LeaseDuration: metav1.Duration{Duration: 15 * time.Second}, + RenewDeadline: metav1.Duration{Duration: 10 * time.Second}, + RetryPeriod: metav1.Duration{Duration: 2 * time.Second}, + }, + }, + KubeCloudShared: &cmoptions.KubeCloudSharedOptions{ + Port: 10253, // Note: InsecureServingOptions.ApplyTo will write the flag value back into the component config + Address: "0.0.0.0", // Note: InsecureServingOptions.ApplyTo will write the flag value back into the component config + RouteReconciliationPeriod: metav1.Duration{Duration: 10 * time.Second}, + NodeMonitorPeriod: metav1.Duration{Duration: 5 * time.Second}, + ClusterName: "kubernetes", + ClusterCIDR: "", + AllocateNodeCIDRs: false, + CIDRAllocatorType: "", + ConfigureCloudRoutes: true, + }, + ServiceController: &cmoptions.ServiceControllerOptions{ + ConcurrentServiceSyncs: 1, + }, + SecureServing: &apiserveroptions.SecureServingOptions{ + BindPort: 0, + BindAddress: net.ParseIP("0.0.0.0"), + ServerCert: apiserveroptions.GeneratableKeyCert{ + CertDirectory: "/var/run/kubernetes", + PairName: "cloud-controller-manager", + }, + HTTP2MaxStreamsPerConnection: 0, + }, + InsecureServing: &cmoptions.InsecureServingOptions{ + BindAddress: net.ParseIP("0.0.0.0"), + BindPort: int(10253), + BindNetwork: "tcp", + }, + Kubeconfig: "", + Master: "", NodeStatusUpdateFrequency: metav1.Duration{Duration: 5 * time.Minute}, } if !reflect.DeepEqual(expected, s) { @@ -216,139 +134,57 @@ func TestAddFlags(t *testing.T) { f.Parse(args) expected := &CloudControllerManagerOptions{ - Generic: &cmoptions.GenericControllerManagerOptions{ - CloudProvider: &cmoptions.CloudProviderOptions{ - Name: "gce", - CloudConfigFile: "/cloud-config", - }, - Debugging: &cmoptions.DebuggingOptions{ - EnableContentionProfiling: true, - }, - GenericComponent: &cmoptions.GenericComponentConfigOptions{ - MinResyncPeriod: metav1.Duration{Duration: 100 * time.Minute}, - ContentType: "application/vnd.kubernetes.protobuf", - KubeAPIQPS: 50.0, - KubeAPIBurst: 100, - ControllerStartInterval: metav1.Duration{Duration: 2 * time.Minute}, - LeaderElection: componentconfig.LeaderElectionConfiguration{ - ResourceLock: "configmap", - LeaderElect: false, - LeaseDuration: metav1.Duration{Duration: 30 * time.Second}, - RenewDeadline: metav1.Duration{Duration: 15 * time.Second}, - RetryPeriod: metav1.Duration{Duration: 5 * time.Second}, - }, - }, - KubeCloudShared: &cmoptions.KubeCloudSharedOptions{ - Port: 10253, // Note: InsecureServingOptions.ApplyTo will write the flag value back into the component config - Address: "0.0.0.0", // Note: InsecureServingOptions.ApplyTo will write the flag value back into the component config - RouteReconciliationPeriod: metav1.Duration{Duration: 30 * time.Second}, - NodeMonitorPeriod: metav1.Duration{Duration: 5 * time.Second}, - ClusterName: "k8s", - ClusterCIDR: "1.2.3.4/24", - AllocateNodeCIDRs: true, - CIDRAllocatorType: "RangeAllocator", - ConfigureCloudRoutes: false, - }, - AttachDetachController: &cmoptions.AttachDetachControllerOptions{ - ReconcilerSyncLoopPeriod: metav1.Duration{Duration: 1 * time.Minute}, - }, - CSRSigningController: &cmoptions.CSRSigningControllerOptions{ - ClusterSigningCertFile: "/etc/kubernetes/ca/ca.pem", - ClusterSigningKeyFile: "/etc/kubernetes/ca/ca.key", - ClusterSigningDuration: metav1.Duration{Duration: 8760 * time.Hour}, - }, - DaemonSetController: &cmoptions.DaemonSetControllerOptions{ - ConcurrentDaemonSetSyncs: 2, - }, - DeploymentController: &cmoptions.DeploymentControllerOptions{ - ConcurrentDeploymentSyncs: 5, - DeploymentControllerSyncPeriod: metav1.Duration{Duration: 30 * time.Second}, - }, - DeprecatedFlags: &cmoptions.DeprecatedControllerOptions{ - RegisterRetryCount: 10, - }, - EndPointController: &cmoptions.EndPointControllerOptions{ - ConcurrentEndpointSyncs: 5, - }, - GarbageCollectorController: &cmoptions.GarbageCollectorControllerOptions{ - ConcurrentGCSyncs: 20, - EnableGarbageCollector: true, - }, - HPAController: &cmoptions.HPAControllerOptions{ - HorizontalPodAutoscalerSyncPeriod: metav1.Duration{Duration: 30 * time.Second}, - HorizontalPodAutoscalerUpscaleForbiddenWindow: metav1.Duration{Duration: 3 * time.Minute}, - HorizontalPodAutoscalerDownscaleForbiddenWindow: metav1.Duration{Duration: 5 * time.Minute}, - HorizontalPodAutoscalerTolerance: 0.1, - HorizontalPodAutoscalerUseRESTClients: true, - }, - JobController: &cmoptions.JobControllerOptions{ - ConcurrentJobSyncs: 5, - }, - NamespaceController: &cmoptions.NamespaceControllerOptions{ - NamespaceSyncPeriod: metav1.Duration{Duration: 5 * time.Minute}, - ConcurrentNamespaceSyncs: 10, - }, - NodeIpamController: &cmoptions.NodeIpamControllerOptions{ - NodeCIDRMaskSize: 24, - }, - NodeLifecycleController: &cmoptions.NodeLifecycleControllerOptions{ - EnableTaintManager: true, - NodeMonitorGracePeriod: metav1.Duration{Duration: 40 * time.Second}, - NodeStartupGracePeriod: metav1.Duration{Duration: 1 * time.Minute}, - PodEvictionTimeout: metav1.Duration{Duration: 5 * time.Minute}, - }, - PersistentVolumeBinderController: &cmoptions.PersistentVolumeBinderControllerOptions{ - PVClaimBinderSyncPeriod: metav1.Duration{Duration: 15 * time.Second}, - VolumeConfiguration: componentconfig.VolumeConfiguration{ - EnableDynamicProvisioning: true, - EnableHostPathProvisioning: false, - FlexVolumePluginDir: "/usr/libexec/kubernetes/kubelet-plugins/volume/exec/", - PersistentVolumeRecyclerConfiguration: componentconfig.PersistentVolumeRecyclerConfiguration{ - MaximumRetry: 3, - MinimumTimeoutNFS: 300, - IncrementTimeoutNFS: 30, - MinimumTimeoutHostPath: 60, - IncrementTimeoutHostPath: 30, - }, - }, - }, - PodGCController: &cmoptions.PodGCControllerOptions{ - TerminatedPodGCThreshold: 12500, - }, - ReplicaSetController: &cmoptions.ReplicaSetControllerOptions{ - ConcurrentRSSyncs: 5, - }, - ReplicationController: &cmoptions.ReplicationControllerOptions{ - ConcurrentRCSyncs: 5, - }, - ResourceQuotaController: &cmoptions.ResourceQuotaControllerOptions{ - ResourceQuotaSyncPeriod: metav1.Duration{Duration: 5 * time.Minute}, - ConcurrentResourceQuotaSyncs: 5, - }, - SAController: &cmoptions.SAControllerOptions{ - ConcurrentSATokenSyncs: 5, - }, - ServiceController: &cmoptions.ServiceControllerOptions{ - ConcurrentServiceSyncs: 1, - }, - Controllers: []string{"*"}, - SecureServing: &apiserveroptions.SecureServingOptions{ - BindPort: 10001, - BindAddress: net.ParseIP("192.168.4.21"), - ServerCert: apiserveroptions.GeneratableKeyCert{ - CertDirectory: "/a/b/c", - PairName: "cloud-controller-manager", - }, - HTTP2MaxStreamsPerConnection: 47, - }, - InsecureServing: &cmoptions.InsecureServingOptions{ - BindAddress: net.ParseIP("192.168.4.10"), - BindPort: int(10000), - BindNetwork: "tcp", - }, - Kubeconfig: "/kubeconfig", - Master: "192.168.4.20", + CloudProvider: &cmoptions.CloudProviderOptions{ + Name: "gce", + CloudConfigFile: "/cloud-config", }, + Debugging: &cmoptions.DebuggingOptions{ + EnableContentionProfiling: true, + }, + GenericComponent: &cmoptions.GenericComponentConfigOptions{ + MinResyncPeriod: metav1.Duration{Duration: 100 * time.Minute}, + ContentType: "application/vnd.kubernetes.protobuf", + KubeAPIQPS: 50.0, + KubeAPIBurst: 100, + ControllerStartInterval: metav1.Duration{Duration: 2 * time.Minute}, + LeaderElection: componentconfig.LeaderElectionConfiguration{ + ResourceLock: "configmap", + LeaderElect: false, + LeaseDuration: metav1.Duration{Duration: 30 * time.Second}, + RenewDeadline: metav1.Duration{Duration: 15 * time.Second}, + RetryPeriod: metav1.Duration{Duration: 5 * time.Second}, + }, + }, + KubeCloudShared: &cmoptions.KubeCloudSharedOptions{ + Port: 10253, // Note: InsecureServingOptions.ApplyTo will write the flag value back into the component config + Address: "0.0.0.0", // Note: InsecureServingOptions.ApplyTo will write the flag value back into the component config + RouteReconciliationPeriod: metav1.Duration{Duration: 30 * time.Second}, + NodeMonitorPeriod: metav1.Duration{Duration: 5 * time.Second}, + ClusterName: "k8s", + ClusterCIDR: "1.2.3.4/24", + AllocateNodeCIDRs: true, + CIDRAllocatorType: "RangeAllocator", + ConfigureCloudRoutes: false, + }, + ServiceController: &cmoptions.ServiceControllerOptions{ + ConcurrentServiceSyncs: 1, + }, + SecureServing: &apiserveroptions.SecureServingOptions{ + BindPort: 10001, + BindAddress: net.ParseIP("192.168.4.21"), + ServerCert: apiserveroptions.GeneratableKeyCert{ + CertDirectory: "/a/b/c", + PairName: "cloud-controller-manager", + }, + HTTP2MaxStreamsPerConnection: 47, + }, + InsecureServing: &cmoptions.InsecureServingOptions{ + BindAddress: net.ParseIP("192.168.4.10"), + BindPort: int(10000), + BindNetwork: "tcp", + }, + Kubeconfig: "/kubeconfig", + Master: "192.168.4.20", NodeStatusUpdateFrequency: metav1.Duration{Duration: 10 * time.Minute}, } if !reflect.DeepEqual(expected, s) { diff --git a/cmd/controller-manager/app/options/generic.go b/cmd/controller-manager/app/options/generic.go index df9b19f8a3..d32b975691 100644 --- a/cmd/controller-manager/app/options/generic.go +++ b/cmd/controller-manager/app/options/generic.go @@ -33,6 +33,22 @@ type GenericComponentConfigOptions struct { LeaderElection componentconfig.LeaderElectionConfiguration } +// NewGenericComponentConfigOptions returns generic configuration default values for both +// the kube-controller-manager and the cloud-contoller-manager. Any common changes should +// be made here. Any individual changes should be made in that controller. +func NewGenericComponentConfigOptions(cfg componentconfig.GenericComponentConfiguration) *GenericComponentConfigOptions { + o := &GenericComponentConfigOptions{ + MinResyncPeriod: cfg.MinResyncPeriod, + ContentType: cfg.ContentType, + KubeAPIQPS: cfg.KubeAPIQPS, + KubeAPIBurst: cfg.KubeAPIBurst, + ControllerStartInterval: cfg.ControllerStartInterval, + LeaderElection: cfg.LeaderElection, + } + + return o +} + // AddFlags adds flags related to generic for controller manager to the specified FlagSet. func (o *GenericComponentConfigOptions) AddFlags(fs *pflag.FlagSet) { if o == nil { diff --git a/cmd/controller-manager/app/options/kubecloudshared.go b/cmd/controller-manager/app/options/kubecloudshared.go index 823500b364..d9607bf54b 100644 --- a/cmd/controller-manager/app/options/kubecloudshared.go +++ b/cmd/controller-manager/app/options/kubecloudshared.go @@ -40,6 +40,22 @@ type KubeCloudSharedOptions struct { NodeSyncPeriod metav1.Duration } +// NewKubeCloudSharedOptions returns common/default configuration values for both +// the kube-controller-manager and the cloud-contoller-manager. Any common changes should +// be made here. Any individual changes should be made in that controller. +func NewKubeCloudSharedOptions(cfg componentconfig.KubeCloudSharedConfiguration) *KubeCloudSharedOptions { + o := &KubeCloudSharedOptions{ + Port: cfg.Port, + Address: cfg.Address, + RouteReconciliationPeriod: cfg.RouteReconciliationPeriod, + NodeMonitorPeriod: cfg.NodeMonitorPeriod, + ClusterName: cfg.ClusterName, + ConfigureCloudRoutes: cfg.ConfigureCloudRoutes, + } + + return o +} + // AddFlags adds flags related to shared variable for controller manager to the specified FlagSet. func (o *KubeCloudSharedOptions) AddFlags(fs *pflag.FlagSet) { if o == nil {