@@ -30,6 +30,7 @@ import (
30
30
apiserveroptions "k8s.io/apiserver/pkg/server/options"
31
31
componentbaseconfig "k8s.io/component-base/config"
32
32
cmoptions "k8s.io/kubernetes/cmd/controller-manager/app/options"
33
+ kubecontrollerconfig "k8s.io/kubernetes/cmd/kube-controller-manager/app/config"
33
34
kubectrlmgrconfig "k8s.io/kubernetes/pkg/controller/apis/config"
34
35
csrsigningconfig "k8s.io/kubernetes/pkg/controller/certificates/signer/config"
35
36
daemonconfig "k8s.io/kubernetes/pkg/controller/daemon/config"
@@ -54,95 +55,96 @@ import (
54
55
persistentvolumeconfig "k8s.io/kubernetes/pkg/controller/volume/persistentvolume/config"
55
56
)
56
57
58
+ var args = []string {
59
+ "--address=192.168.4.10" ,
60
+ "--allocate-node-cidrs=true" ,
61
+ "--attach-detach-reconcile-sync-period=30s" ,
62
+ "--cidr-allocator-type=CloudAllocator" ,
63
+ "--cloud-config=/cloud-config" ,
64
+ "--cloud-provider=gce" ,
65
+ "--cluster-cidr=1.2.3.4/24" ,
66
+ "--cluster-name=k8s" ,
67
+ "--cluster-signing-cert-file=/cluster-signing-cert" ,
68
+ "--cluster-signing-key-file=/cluster-signing-key" ,
69
+ "--concurrent-deployment-syncs=10" ,
70
+ "--concurrent-statefulset-syncs=15" ,
71
+ "--concurrent-endpoint-syncs=10" ,
72
+ "--concurrent-service-endpoint-syncs=10" ,
73
+ "--concurrent-gc-syncs=30" ,
74
+ "--concurrent-namespace-syncs=20" ,
75
+ "--concurrent-replicaset-syncs=10" ,
76
+ "--concurrent-resource-quota-syncs=10" ,
77
+ "--concurrent-service-syncs=2" ,
78
+ "--concurrent-serviceaccount-token-syncs=10" ,
79
+ "--concurrent_rc_syncs=10" ,
80
+ "--configure-cloud-routes=false" ,
81
+ "--contention-profiling=true" ,
82
+ "--controller-start-interval=2m" ,
83
+ "--controllers=foo,bar" ,
84
+ "--deployment-controller-sync-period=45s" ,
85
+ "--disable-attach-detach-reconcile-sync=true" ,
86
+ "--enable-dynamic-provisioning=false" ,
87
+ "--enable-garbage-collector=false" ,
88
+ "--enable-hostpath-provisioner=true" ,
89
+ "--enable-taint-manager=false" ,
90
+ "--experimental-cluster-signing-duration=10h" ,
91
+ "--flex-volume-plugin-dir=/flex-volume-plugin" ,
92
+ "--horizontal-pod-autoscaler-downscale-delay=2m" ,
93
+ "--horizontal-pod-autoscaler-sync-period=45s" ,
94
+ "--horizontal-pod-autoscaler-upscale-delay=1m" ,
95
+ "--horizontal-pod-autoscaler-downscale-stabilization=3m" ,
96
+ "--horizontal-pod-autoscaler-cpu-initialization-period=90s" ,
97
+ "--horizontal-pod-autoscaler-initial-readiness-delay=50s" ,
98
+ "--http2-max-streams-per-connection=47" ,
99
+ "--kube-api-burst=100" ,
100
+ "--kube-api-content-type=application/json" ,
101
+ "--kube-api-qps=50.0" ,
102
+ "--kubeconfig=/kubeconfig" ,
103
+ "--large-cluster-size-threshold=100" ,
104
+ "--leader-elect=false" ,
105
+ "--leader-elect-lease-duration=30s" ,
106
+ "--leader-elect-renew-deadline=15s" ,
107
+ "--leader-elect-resource-lock=configmap" ,
108
+ "--leader-elect-retry-period=5s" ,
109
+ "--master=192.168.4.20" ,
110
+ "--max-endpoints-per-slice=200" ,
111
+ "--min-resync-period=8h" ,
112
+ "--namespace-sync-period=10m" ,
113
+ "--node-cidr-mask-size=48" ,
114
+ "--node-cidr-mask-size-ipv4=48" ,
115
+ "--node-cidr-mask-size-ipv6=108" ,
116
+ "--node-eviction-rate=0.2" ,
117
+ "--node-monitor-grace-period=30s" ,
118
+ "--node-monitor-period=10s" ,
119
+ "--node-startup-grace-period=30s" ,
120
+ "--pod-eviction-timeout=2m" ,
121
+ "--port=10000" ,
122
+ "--profiling=false" ,
123
+ "--pv-recycler-increment-timeout-nfs=45" ,
124
+ "--pv-recycler-minimum-timeout-hostpath=45" ,
125
+ "--pv-recycler-minimum-timeout-nfs=200" ,
126
+ "--pv-recycler-timeout-increment-hostpath=45" ,
127
+ "--pvclaimbinder-sync-period=30s" ,
128
+ "--resource-quota-sync-period=10m" ,
129
+ "--route-reconciliation-period=30s" ,
130
+ "--secondary-node-eviction-rate=0.05" ,
131
+ "--service-account-private-key-file=/service-account-private-key" ,
132
+ "--terminated-pod-gc-threshold=12000" ,
133
+ "--unhealthy-zone-threshold=0.6" ,
134
+ "--use-service-account-credentials=true" ,
135
+ "--cert-dir=/a/b/c" ,
136
+ "--bind-address=192.168.4.21" ,
137
+ "--secure-port=10001" ,
138
+ "--concurrent-ttl-after-finished-syncs=8" ,
139
+ }
140
+
57
141
func TestAddFlags (t * testing.T ) {
58
142
fs := pflag .NewFlagSet ("addflagstest" , pflag .ContinueOnError )
59
143
s , _ := NewKubeControllerManagerOptions ()
60
144
for _ , f := range s .Flags ([]string {"" }, []string {"" }).FlagSets {
61
145
fs .AddFlagSet (f )
62
146
}
63
147
64
- args := []string {
65
- "--address=192.168.4.10" ,
66
- "--allocate-node-cidrs=true" ,
67
- "--attach-detach-reconcile-sync-period=30s" ,
68
- "--cidr-allocator-type=CloudAllocator" ,
69
- "--cloud-config=/cloud-config" ,
70
- "--cloud-provider=gce" ,
71
- "--cluster-cidr=1.2.3.4/24" ,
72
- "--cluster-name=k8s" ,
73
- "--cluster-signing-cert-file=/cluster-signing-cert" ,
74
- "--cluster-signing-key-file=/cluster-signing-key" ,
75
- "--concurrent-deployment-syncs=10" ,
76
- "--concurrent-statefulset-syncs=15" ,
77
- "--concurrent-endpoint-syncs=10" ,
78
- "--concurrent-service-endpoint-syncs=10" ,
79
- "--concurrent-gc-syncs=30" ,
80
- "--concurrent-namespace-syncs=20" ,
81
- "--concurrent-replicaset-syncs=10" ,
82
- "--concurrent-resource-quota-syncs=10" ,
83
- "--concurrent-service-syncs=2" ,
84
- "--concurrent-serviceaccount-token-syncs=10" ,
85
- "--concurrent_rc_syncs=10" ,
86
- "--configure-cloud-routes=false" ,
87
- "--contention-profiling=true" ,
88
- "--controller-start-interval=2m" ,
89
- "--controllers=foo,bar" ,
90
- "--deployment-controller-sync-period=45s" ,
91
- "--disable-attach-detach-reconcile-sync=true" ,
92
- "--enable-dynamic-provisioning=false" ,
93
- "--enable-garbage-collector=false" ,
94
- "--enable-hostpath-provisioner=true" ,
95
- "--enable-taint-manager=false" ,
96
- "--experimental-cluster-signing-duration=10h" ,
97
- "--flex-volume-plugin-dir=/flex-volume-plugin" ,
98
- "--horizontal-pod-autoscaler-downscale-delay=2m" ,
99
- "--horizontal-pod-autoscaler-sync-period=45s" ,
100
- "--horizontal-pod-autoscaler-upscale-delay=1m" ,
101
- "--horizontal-pod-autoscaler-downscale-stabilization=3m" ,
102
- "--horizontal-pod-autoscaler-cpu-initialization-period=90s" ,
103
- "--horizontal-pod-autoscaler-initial-readiness-delay=50s" ,
104
- "--http2-max-streams-per-connection=47" ,
105
- "--kube-api-burst=100" ,
106
- "--kube-api-content-type=application/json" ,
107
- "--kube-api-qps=50.0" ,
108
- "--kubeconfig=/kubeconfig" ,
109
- "--large-cluster-size-threshold=100" ,
110
- "--leader-elect=false" ,
111
- "--leader-elect-lease-duration=30s" ,
112
- "--leader-elect-renew-deadline=15s" ,
113
- "--leader-elect-resource-lock=configmap" ,
114
- "--leader-elect-retry-period=5s" ,
115
- "--master=192.168.4.20" ,
116
- "--max-endpoints-per-slice=200" ,
117
- "--min-resync-period=8h" ,
118
- "--namespace-sync-period=10m" ,
119
- "--node-cidr-mask-size=48" ,
120
- "--node-cidr-mask-size-ipv4=48" ,
121
- "--node-cidr-mask-size-ipv6=108" ,
122
- "--node-eviction-rate=0.2" ,
123
- "--node-monitor-grace-period=30s" ,
124
- "--node-monitor-period=10s" ,
125
- "--node-startup-grace-period=30s" ,
126
- "--pod-eviction-timeout=2m" ,
127
- "--port=10000" ,
128
- "--profiling=false" ,
129
- "--pv-recycler-increment-timeout-nfs=45" ,
130
- "--pv-recycler-minimum-timeout-hostpath=45" ,
131
- "--pv-recycler-minimum-timeout-nfs=200" ,
132
- "--pv-recycler-timeout-increment-hostpath=45" ,
133
- "--pvclaimbinder-sync-period=30s" ,
134
- "--resource-quota-sync-period=10m" ,
135
- "--route-reconciliation-period=30s" ,
136
- "--secondary-node-eviction-rate=0.05" ,
137
- "--service-account-private-key-file=/service-account-private-key" ,
138
- "--terminated-pod-gc-threshold=12000" ,
139
- "--unhealthy-zone-threshold=0.6" ,
140
- "--use-service-account-credentials=true" ,
141
- "--cert-dir=/a/b/c" ,
142
- "--bind-address=192.168.4.21" ,
143
- "--secure-port=10001" ,
144
- "--concurrent-ttl-after-finished-syncs=8" ,
145
- }
146
148
fs .Parse (args )
147
149
// Sort GCIgnoredResources because it's built from a map, which means the
148
150
// insertion order is random.
@@ -390,6 +392,182 @@ func TestAddFlags(t *testing.T) {
390
392
}
391
393
}
392
394
395
+ func TestApplyTo (t * testing.T ) {
396
+ fs := pflag .NewFlagSet ("addflagstest" , pflag .ContinueOnError )
397
+ s , _ := NewKubeControllerManagerOptions ()
398
+ // flag set to parse the args that are required to start the kube controller manager
399
+ for _ , f := range s .Flags ([]string {"" }, []string {"" }).FlagSets {
400
+ fs .AddFlagSet (f )
401
+ }
402
+
403
+ fs .Parse (args )
404
+ // Sort GCIgnoredResources because it's built from a map, which means the
405
+ // insertion order is random.
406
+ sort .Sort (sortedGCIgnoredResources (s .GarbageCollectorController .GCIgnoredResources ))
407
+
408
+ expected := & kubecontrollerconfig.Config {
409
+ ComponentConfig : kubectrlmgrconfig.KubeControllerManagerConfiguration {
410
+ Generic : kubectrlmgrconfig.GenericControllerManagerConfiguration {
411
+ Port : 10252 , // Note: InsecureServingOptions.ApplyTo will write the flag value back into the component config
412
+ Address : "0.0.0.0" , // Note: InsecureServingOptions.ApplyTo will write the flag value back into the component config
413
+ MinResyncPeriod : metav1.Duration {Duration : 8 * time .Hour },
414
+ ClientConnection : componentbaseconfig.ClientConnectionConfiguration {
415
+ ContentType : "application/json" ,
416
+ QPS : 50.0 ,
417
+ Burst : 100 ,
418
+ },
419
+ ControllerStartInterval : metav1.Duration {Duration : 2 * time .Minute },
420
+ LeaderElection : componentbaseconfig.LeaderElectionConfiguration {
421
+ ResourceLock : "configmap" ,
422
+ LeaderElect : false ,
423
+ LeaseDuration : metav1.Duration {Duration : 30 * time .Second },
424
+ RenewDeadline : metav1.Duration {Duration : 15 * time .Second },
425
+ RetryPeriod : metav1.Duration {Duration : 5 * time .Second },
426
+ ResourceName : "kube-controller-manager" ,
427
+ ResourceNamespace : "kube-system" ,
428
+ },
429
+ Controllers : []string {"foo" , "bar" },
430
+ Debugging : componentbaseconfig.DebuggingConfiguration {
431
+ EnableProfiling : false ,
432
+ EnableContentionProfiling : true ,
433
+ },
434
+ },
435
+ KubeCloudShared : kubectrlmgrconfig.KubeCloudSharedConfiguration {
436
+ UseServiceAccountCredentials : true ,
437
+ RouteReconciliationPeriod : metav1.Duration {Duration : 30 * time .Second },
438
+ NodeMonitorPeriod : metav1.Duration {Duration : 10 * time .Second },
439
+ ClusterName : "k8s" ,
440
+ ClusterCIDR : "1.2.3.4/24" ,
441
+ AllocateNodeCIDRs : true ,
442
+ CIDRAllocatorType : "CloudAllocator" ,
443
+ ConfigureCloudRoutes : false ,
444
+ CloudProvider : kubectrlmgrconfig.CloudProviderConfiguration {
445
+ Name : "gce" ,
446
+ CloudConfigFile : "/cloud-config" ,
447
+ },
448
+ },
449
+ ServiceController : serviceconfig.ServiceControllerConfiguration {
450
+ ConcurrentServiceSyncs : 2 ,
451
+ },
452
+ AttachDetachController : attachdetachconfig.AttachDetachControllerConfiguration {
453
+ ReconcilerSyncLoopPeriod : metav1.Duration {Duration : 30 * time .Second },
454
+ DisableAttachDetachReconcilerSync : true ,
455
+ },
456
+ CSRSigningController : csrsigningconfig.CSRSigningControllerConfiguration {
457
+ ClusterSigningCertFile : "/cluster-signing-cert" ,
458
+ ClusterSigningKeyFile : "/cluster-signing-key" ,
459
+ ClusterSigningDuration : metav1.Duration {Duration : 10 * time .Hour },
460
+ },
461
+ DaemonSetController : daemonconfig.DaemonSetControllerConfiguration {
462
+ ConcurrentDaemonSetSyncs : 2 ,
463
+ },
464
+ DeploymentController : deploymentconfig.DeploymentControllerConfiguration {
465
+ ConcurrentDeploymentSyncs : 10 ,
466
+ DeploymentControllerSyncPeriod : metav1.Duration {Duration : 45 * time .Second },
467
+ },
468
+ StatefulSetController : statefulsetconfig.StatefulSetControllerConfiguration {
469
+ ConcurrentStatefulSetSyncs : 15 ,
470
+ },
471
+ DeprecatedController : kubectrlmgrconfig.DeprecatedControllerConfiguration {
472
+ DeletingPodsQPS : 0.1 ,
473
+ RegisterRetryCount : 10 ,
474
+ },
475
+ EndpointController : endpointconfig.EndpointControllerConfiguration {
476
+ ConcurrentEndpointSyncs : 10 ,
477
+ },
478
+ EndpointSliceController : endpointsliceconfig.EndpointSliceControllerConfiguration {
479
+ ConcurrentServiceEndpointSyncs : 10 ,
480
+ MaxEndpointsPerSlice : 200 ,
481
+ },
482
+ GarbageCollectorController : garbagecollectorconfig.GarbageCollectorControllerConfiguration {
483
+ ConcurrentGCSyncs : 30 ,
484
+ GCIgnoredResources : []garbagecollectorconfig.GroupResource {
485
+ {Group : "" , Resource : "events" },
486
+ },
487
+ EnableGarbageCollector : false ,
488
+ },
489
+ HPAController : poautosclerconfig.HPAControllerConfiguration {
490
+ HorizontalPodAutoscalerSyncPeriod : metav1.Duration {Duration : 45 * time .Second },
491
+ HorizontalPodAutoscalerUpscaleForbiddenWindow : metav1.Duration {Duration : 1 * time .Minute },
492
+ HorizontalPodAutoscalerDownscaleForbiddenWindow : metav1.Duration {Duration : 2 * time .Minute },
493
+ HorizontalPodAutoscalerDownscaleStabilizationWindow : metav1.Duration {Duration : 3 * time .Minute },
494
+ HorizontalPodAutoscalerCPUInitializationPeriod : metav1.Duration {Duration : 90 * time .Second },
495
+ HorizontalPodAutoscalerInitialReadinessDelay : metav1.Duration {Duration : 50 * time .Second },
496
+ HorizontalPodAutoscalerTolerance : 0.1 ,
497
+ HorizontalPodAutoscalerUseRESTClients : true ,
498
+ },
499
+ JobController : jobconfig.JobControllerConfiguration {
500
+ ConcurrentJobSyncs : 5 ,
501
+ },
502
+ NamespaceController : namespaceconfig.NamespaceControllerConfiguration {
503
+ NamespaceSyncPeriod : metav1.Duration {Duration : 10 * time .Minute },
504
+ ConcurrentNamespaceSyncs : 20 ,
505
+ },
506
+ NodeIPAMController : nodeipamconfig.NodeIPAMControllerConfiguration {
507
+ NodeCIDRMaskSize : 48 ,
508
+ NodeCIDRMaskSizeIPv4 : 48 ,
509
+ NodeCIDRMaskSizeIPv6 : 108 ,
510
+ },
511
+ NodeLifecycleController : nodelifecycleconfig.NodeLifecycleControllerConfiguration {
512
+ EnableTaintManager : false ,
513
+ NodeEvictionRate : 0.2 ,
514
+ SecondaryNodeEvictionRate : 0.05 ,
515
+ NodeMonitorGracePeriod : metav1.Duration {Duration : 30 * time .Second },
516
+ NodeStartupGracePeriod : metav1.Duration {Duration : 30 * time .Second },
517
+ PodEvictionTimeout : metav1.Duration {Duration : 2 * time .Minute },
518
+ LargeClusterSizeThreshold : 100 ,
519
+ UnhealthyZoneThreshold : 0.6 ,
520
+ },
521
+ PersistentVolumeBinderController : persistentvolumeconfig.PersistentVolumeBinderControllerConfiguration {
522
+ PVClaimBinderSyncPeriod : metav1.Duration {Duration : 30 * time .Second },
523
+ VolumeConfiguration : persistentvolumeconfig.VolumeConfiguration {
524
+ EnableDynamicProvisioning : false ,
525
+ EnableHostPathProvisioning : true ,
526
+ FlexVolumePluginDir : "/flex-volume-plugin" ,
527
+ PersistentVolumeRecyclerConfiguration : persistentvolumeconfig.PersistentVolumeRecyclerConfiguration {
528
+ MaximumRetry : 3 ,
529
+ MinimumTimeoutNFS : 200 ,
530
+ IncrementTimeoutNFS : 45 ,
531
+ MinimumTimeoutHostPath : 45 ,
532
+ IncrementTimeoutHostPath : 45 ,
533
+ },
534
+ },
535
+ },
536
+ PodGCController : podgcconfig.PodGCControllerConfiguration {
537
+ TerminatedPodGCThreshold : 12000 ,
538
+ },
539
+ ReplicaSetController : replicasetconfig.ReplicaSetControllerConfiguration {
540
+ ConcurrentRSSyncs : 10 ,
541
+ },
542
+ ReplicationController : replicationconfig.ReplicationControllerConfiguration {
543
+ ConcurrentRCSyncs : 10 ,
544
+ },
545
+ ResourceQuotaController : resourcequotaconfig.ResourceQuotaControllerConfiguration {
546
+ ResourceQuotaSyncPeriod : metav1.Duration {Duration : 10 * time .Minute },
547
+ ConcurrentResourceQuotaSyncs : 10 ,
548
+ },
549
+ SAController : serviceaccountconfig.SAControllerConfiguration {
550
+ ServiceAccountKeyFile : "/service-account-private-key" ,
551
+ ConcurrentSATokenSyncs : 10 ,
552
+ },
553
+ TTLAfterFinishedController : ttlafterfinishedconfig.TTLAfterFinishedControllerConfiguration {
554
+ ConcurrentTTLSyncs : 8 ,
555
+ },
556
+ },
557
+ }
558
+
559
+ // Sort GCIgnoredResources because it's built from a map, which means the
560
+ // insertion order is random.
561
+ sort .Sort (sortedGCIgnoredResources (expected .ComponentConfig .GarbageCollectorController .GCIgnoredResources ))
562
+
563
+ c := & kubecontrollerconfig.Config {}
564
+ s .ApplyTo (c )
565
+
566
+ if ! reflect .DeepEqual (expected .ComponentConfig , c .ComponentConfig ) {
567
+ t .Errorf ("Got different configuration than expected.\n Difference detected on:\n %s" , diff .ObjectReflectDiff (expected .ComponentConfig , c .ComponentConfig ))
568
+ }
569
+ }
570
+
393
571
type sortedGCIgnoredResources []garbagecollectorconfig.GroupResource
394
572
395
573
func (r sortedGCIgnoredResources ) Len () int {
0 commit comments