@@ -434,6 +434,7 @@ func TestCreateConfig(t *testing.T) {
434
434
435
435
// Don't check
436
436
c .SecureServing = nil
437
+ assert .NotNil (t , c .WebhookSecureServing , "webhook secureserving shouldn't be nil" )
437
438
c .WebhookSecureServing = nil
438
439
c .Authentication = apiserver.AuthenticationInfo {}
439
440
c .Authorization = apiserver.AuthorizationInfo {}
@@ -451,6 +452,143 @@ func TestCreateConfig(t *testing.T) {
451
452
}
452
453
}
453
454
455
+ func TestCreateConfigWithoutWebHooks (t * testing.T ) {
456
+ fs := pflag .NewFlagSet ("addflagstest" , pflag .ContinueOnError )
457
+
458
+ s , err := NewCloudControllerManagerOptions ()
459
+ if err != nil {
460
+ t .Errorf ("unexpected err: %v" , err )
461
+ }
462
+
463
+ for _ , f := range s .Flags ([]string {"" }, []string {"" }, nil , []string {"" }, []string {"" }).FlagSets {
464
+ fs .AddFlagSet (f )
465
+ }
466
+
467
+ tmpdir , err := os .MkdirTemp ("" , "options_test" )
468
+ if err != nil {
469
+ t .Fatalf ("%s" , err )
470
+ }
471
+ defer func () {
472
+ if err := os .RemoveAll (tmpdir ); err != nil {
473
+ t .Error (err )
474
+ }
475
+ }()
476
+
477
+ args := []string {
478
+ "--allocate-node-cidrs=true" ,
479
+ "--authorization-always-allow-paths=" ,
480
+ "--bind-address=0.0.0.0" ,
481
+ "--secure-port=10200" ,
482
+ fmt .Sprintf ("--cert-dir=%s/certs" , tmpdir ),
483
+ "--cloud-provider=aws" ,
484
+ "--cluster-cidr=1.2.3.4/24" ,
485
+ "--cluster-name=k8s" ,
486
+ "--configure-cloud-routes=false" ,
487
+ "--contention-profiling=true" ,
488
+ "--controller-start-interval=2m" ,
489
+ "--controllers=foo,bar" ,
490
+ "--concurrent-node-syncs=1" ,
491
+ "--http2-max-streams-per-connection=47" ,
492
+ "--kube-api-burst=101" ,
493
+ "--kube-api-content-type=application/vnd.kubernetes.protobuf" ,
494
+ "--kube-api-qps=50.0" ,
495
+ "--leader-elect=false" ,
496
+ "--leader-elect-lease-duration=30s" ,
497
+ "--leader-elect-renew-deadline=15s" ,
498
+ "--leader-elect-resource-lock=configmap" ,
499
+ "--leader-elect-retry-period=5s" ,
500
+ "--master=192.168.4.20" ,
501
+ "--min-resync-period=100m" ,
502
+ "--node-status-update-frequency=10m" ,
503
+ "--profiling=false" ,
504
+ "--route-reconciliation-period=30s" ,
505
+ "--use-service-account-credentials=false" ,
506
+ }
507
+ err = fs .Parse (args )
508
+ if err != nil {
509
+ t .Errorf ("error parsing the arguments, error : %v" , err )
510
+ }
511
+
512
+ fs .VisitAll (func (f * pflag.Flag ) {
513
+ fmt .Printf ("%s: %s\n " , f .Name , f .Value )
514
+ })
515
+
516
+ c , err := s .Config ([]string {"foo" , "bar" }, []string {}, nil , []string {"foo" , "bar" , "baz" }, []string {})
517
+ if err != nil {
518
+ t .Errorf ("error generating config, error : %v" , err )
519
+ }
520
+
521
+ expected := & appconfig.Config {
522
+ ComponentConfig : cpconfig.CloudControllerManagerConfiguration {
523
+ Generic : cmconfig.GenericControllerManagerConfiguration {
524
+ Address : "0.0.0.0" ,
525
+ MinResyncPeriod : metav1.Duration {Duration : 100 * time .Minute },
526
+ ClientConnection : componentbaseconfig.ClientConnectionConfiguration {
527
+ ContentType : "application/vnd.kubernetes.protobuf" ,
528
+ QPS : 50.0 ,
529
+ Burst : 101 ,
530
+ },
531
+ ControllerStartInterval : metav1.Duration {Duration : 2 * time .Minute },
532
+ LeaderElection : componentbaseconfig.LeaderElectionConfiguration {
533
+ ResourceLock : "configmap" ,
534
+ LeaderElect : false ,
535
+ LeaseDuration : metav1.Duration {Duration : 30 * time .Second },
536
+ RenewDeadline : metav1.Duration {Duration : 15 * time .Second },
537
+ RetryPeriod : metav1.Duration {Duration : 5 * time .Second },
538
+ ResourceName : "cloud-controller-manager" ,
539
+ ResourceNamespace : "kube-system" ,
540
+ },
541
+ Controllers : []string {"foo" , "bar" },
542
+ Debugging : componentbaseconfig.DebuggingConfiguration {
543
+ EnableProfiling : false ,
544
+ EnableContentionProfiling : true ,
545
+ },
546
+ LeaderMigration : cmconfig.LeaderMigrationConfiguration {},
547
+ },
548
+ KubeCloudShared : cpconfig.KubeCloudSharedConfiguration {
549
+ RouteReconciliationPeriod : metav1.Duration {Duration : 30 * time .Second },
550
+ NodeMonitorPeriod : metav1.Duration {Duration : 5 * time .Second },
551
+ ClusterName : "k8s" ,
552
+ ClusterCIDR : "1.2.3.4/24" ,
553
+ AllocateNodeCIDRs : true ,
554
+ CIDRAllocatorType : "RangeAllocator" ,
555
+ ConfigureCloudRoutes : false ,
556
+ CloudProvider : cpconfig.CloudProviderConfiguration {
557
+ Name : "aws" ,
558
+ CloudConfigFile : "" ,
559
+ },
560
+ },
561
+ ServiceController : serviceconfig.ServiceControllerConfiguration {
562
+ ConcurrentServiceSyncs : 1 ,
563
+ },
564
+ NodeController : nodeconfig.NodeControllerConfiguration {ConcurrentNodeSyncs : 1 },
565
+ NodeStatusUpdateFrequency : metav1.Duration {Duration : 10 * time .Minute },
566
+ Webhook : cpconfig.WebhookConfiguration {},
567
+ },
568
+ SecureServing : nil ,
569
+ WebhookSecureServing : nil ,
570
+ Authentication : apiserver.AuthenticationInfo {},
571
+ Authorization : apiserver.AuthorizationInfo {},
572
+ }
573
+
574
+ // Don't check
575
+ c .SecureServing = nil
576
+ c .Authentication = apiserver.AuthenticationInfo {}
577
+ c .Authorization = apiserver.AuthorizationInfo {}
578
+ c .SharedInformers = nil
579
+ c .VersionedClient = nil
580
+ c .ClientBuilder = nil
581
+ c .EventRecorder = nil
582
+ c .EventBroadcaster = nil
583
+ c .Kubeconfig = nil
584
+ c .Client = nil
585
+ c .LoopbackClientConfig = nil
586
+
587
+ if ! reflect .DeepEqual (expected , c ) {
588
+ t .Errorf ("Got different config than expected.\n Difference detected on:\n %s" , cmp .Diff (expected , c ))
589
+ }
590
+ }
591
+
454
592
func TestCloudControllerManagerAliases (t * testing.T ) {
455
593
opts , err := NewCloudControllerManagerOptions ()
456
594
if err != nil {
0 commit comments