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