@@ -134,6 +134,7 @@ func newKlusterlet(name, namespace, clustername string) *operatorapiv1.Klusterle
134
134
135
135
func newKlusterletHosted (name , namespace , clustername string ) * operatorapiv1.Klusterlet {
136
136
klusterlet := newKlusterlet (name , namespace , clustername )
137
+ klusterlet .Spec .RegistrationConfiguration .RegistrationDriver = operatorapiv1.RegistrationDriver {}
137
138
klusterlet .Spec .DeployOption .Mode = operatorapiv1 .InstallModeHosted
138
139
klusterlet .Finalizers = append (klusterlet .Finalizers , klusterletHostedFinalizer )
139
140
return klusterlet
@@ -374,7 +375,47 @@ func getDeployments(actions []clienttesting.Action, verb, suffix string) *appsv1
374
375
return nil
375
376
}
376
377
377
- func assertRegistrationDeployment (t * testing.T , actions []clienttesting.Action , verb , serverURL , clusterName string , replica int32 ) {
378
+ func assertKlusterletDeployment (t * testing.T , actions []clienttesting.Action , verb , serverURL , clusterName string ) {
379
+ deployment := getDeployments (actions , verb , "agent" )
380
+ if deployment == nil {
381
+ t .Errorf ("klusterlet deployment not found" )
382
+ return
383
+ }
384
+ if len (deployment .Spec .Template .Spec .Containers ) != 1 {
385
+ t .Errorf ("Expect 1 containers in deployment spec, actual %d" , len (deployment .Spec .Template .Spec .Containers ))
386
+ return
387
+ }
388
+
389
+ args := deployment .Spec .Template .Spec .Containers [0 ].Args
390
+ expectedArgs := []string {
391
+ "/registration-operator" ,
392
+ "agent" ,
393
+ fmt .Sprintf ("--spoke-cluster-name=%s" , clusterName ),
394
+ "--bootstrap-kubeconfig=/spoke/bootstrap/kubeconfig" ,
395
+ }
396
+
397
+ if serverURL != "" {
398
+ expectedArgs = append (expectedArgs , fmt .Sprintf ("--spoke-external-server-urls=%s" , serverURL ))
399
+ }
400
+
401
+ expectedArgs = append (expectedArgs , "--agent-id=" , "--workload-source-driver=kube" , "--workload-source-config=/spoke/hub-kubeconfig/kubeconfig" )
402
+
403
+ if * deployment .Spec .Replicas == 1 {
404
+ expectedArgs = append (expectedArgs , "--disable-leader-election" )
405
+ }
406
+ expectedArgs = append (expectedArgs , "--status-sync-interval=60s" )
407
+ expectedArgs = append (expectedArgs , "--kube-api-qps=20" , "--kube-api-burst=60" )
408
+ expectedArgs = append (expectedArgs , "--registration-auth=awsirsa" , "--hub-cluster-arn=arneks:us-west-2:123456789012:cluster/hub-cluster1" )
409
+
410
+ if ! equality .Semantic .DeepEqual (args , expectedArgs ) {
411
+ t .Errorf ("Expect args %v, but got %v" , expectedArgs , args )
412
+ return
413
+ }
414
+
415
+ }
416
+
417
+
418
+ func assertRegistrationDeployment (t * testing.T , actions []clienttesting.Action , verb , serverURL , clusterName string , replica int32 , awsAuth bool ) {
378
419
deployment := getDeployments (actions , verb , "registration-agent" )
379
420
if deployment == nil {
380
421
t .Errorf ("registration deployment not found" )
@@ -402,7 +443,9 @@ func assertRegistrationDeployment(t *testing.T, actions []clienttesting.Action,
402
443
}
403
444
404
445
expectedArgs = append (expectedArgs , "--kube-api-qps=10" , "--kube-api-burst=60" )
405
-
446
+ if awsAuth {
447
+ expectedArgs = append (expectedArgs , "--registration-auth=awsirsa" , "--hub-cluster-arn=arneks:us-west-2:123456789012:cluster/hub-cluster1" )
448
+ }
406
449
if ! equality .Semantic .DeepEqual (args , expectedArgs ) {
407
450
t .Errorf ("Expect args %v, but got %v" , expectedArgs , args )
408
451
return
@@ -944,6 +987,68 @@ func TestGetServersFromKlusterlet(t *testing.T) {
944
987
}
945
988
}
946
989
990
+ func TestAWSIrsaAuthInSingletonMode (t * testing.T ) {
991
+ klusterlet := newKlusterlet ("klusterlet" , "testns" , "cluster1" )
992
+ awsIrsaRegistrationDriver := operatorapiv1.RegistrationDriver {
993
+ AuthType : AwsIrsaAuthType ,
994
+ AwsIrsa : & operatorapiv1.AwsIrsa {
995
+ HubClusterArn : "arneks:us-west-2:123456789012:cluster/hub-cluster1" ,
996
+ },
997
+ }
998
+ klusterlet .Spec .RegistrationConfiguration .RegistrationDriver = awsIrsaRegistrationDriver
999
+ klusterlet .Spec .DeployOption .Mode = operatorapiv1 .InstallModeSingleton
1000
+ hubSecret := newSecret (helpers .HubKubeConfig , "testns" )
1001
+ hubSecret .Data ["kubeconfig" ] = []byte ("dummuykubeconnfig" )
1002
+ hubSecret .Data ["cluster-name" ] = []byte ("cluster1" )
1003
+ objects := []runtime.Object {
1004
+ newNamespace ("testns" ),
1005
+ newSecret (helpers .BootstrapHubKubeConfig , "testns" ),
1006
+ hubSecret ,
1007
+ }
1008
+
1009
+ syncContext := testingcommon .NewFakeSyncContext (t , "klusterlet" )
1010
+ controller := newTestController (t , klusterlet , syncContext .Recorder (), nil , false ,
1011
+ objects ... )
1012
+
1013
+ err := controller .controller .sync (context .TODO (), syncContext )
1014
+ if err != nil {
1015
+ t .Errorf ("Expected non error when sync, %v" , err )
1016
+ }
1017
+
1018
+ assertKlusterletDeployment (t , controller .kubeClient .Actions (), createVerb , "" , "cluster1" )
1019
+ }
1020
+
1021
+ func TestAWSIrsaAuthInNonSingletonMode (t * testing.T ) {
1022
+ klusterlet := newKlusterlet ("klusterlet" , "testns" , "cluster1" )
1023
+ awsIrsaRegistrationDriver := operatorapiv1.RegistrationDriver {
1024
+ AuthType : AwsIrsaAuthType ,
1025
+ AwsIrsa : & operatorapiv1.AwsIrsa {
1026
+ HubClusterArn : "arneks:us-west-2:123456789012:cluster/hub-cluster1" ,
1027
+ },
1028
+ }
1029
+ klusterlet .Spec .RegistrationConfiguration .RegistrationDriver = awsIrsaRegistrationDriver
1030
+ hubSecret := newSecret (helpers .HubKubeConfig , "testns" )
1031
+ hubSecret .Data ["kubeconfig" ] = []byte ("dummuykubeconnfig" )
1032
+ hubSecret .Data ["cluster-name" ] = []byte ("cluster1" )
1033
+ objects := []runtime.Object {
1034
+ newNamespace ("testns" ),
1035
+ newSecret (helpers .BootstrapHubKubeConfig , "testns" ),
1036
+ hubSecret ,
1037
+ }
1038
+
1039
+ syncContext := testingcommon .NewFakeSyncContext (t , "klusterlet" )
1040
+ controller := newTestController (t , klusterlet , syncContext .Recorder (), nil , false ,
1041
+ objects ... )
1042
+
1043
+ err := controller .controller .sync (context .TODO (), syncContext )
1044
+ if err != nil {
1045
+ t .Errorf ("Expected non error when sync, %v" , err )
1046
+ }
1047
+
1048
+ assertRegistrationDeployment (t , controller .kubeClient .Actions (), createVerb , "" , "cluster1" , 1 , true )
1049
+ }
1050
+
1051
+
947
1052
func TestReplica (t * testing.T ) {
948
1053
klusterlet := newKlusterlet ("klusterlet" , "testns" , "cluster1" )
949
1054
hubSecret := newSecret (helpers .HubKubeConfig , "testns" )
@@ -965,7 +1070,7 @@ func TestReplica(t *testing.T) {
965
1070
}
966
1071
967
1072
// should have 1 replica for registration deployment and 0 for work
968
- assertRegistrationDeployment (t , controller .kubeClient .Actions (), createVerb , "" , "cluster1" , 1 )
1073
+ assertRegistrationDeployment (t , controller .kubeClient .Actions (), createVerb , "" , "cluster1" , 1 , false )
969
1074
assertWorkDeployment (t , controller .kubeClient .Actions (), createVerb , "cluster1" , operatorapiv1 .InstallModeDefault , 0 )
970
1075
971
1076
klusterlet = newKlusterlet ("klusterlet" , "testns" , "cluster1" )
@@ -1010,7 +1115,7 @@ func TestReplica(t *testing.T) {
1010
1115
}
1011
1116
1012
1117
// should have 3 replicas for clusters with multiple nodes
1013
- assertRegistrationDeployment (t , controller .kubeClient .Actions (), "update" , "" , "cluster1" , 3 )
1118
+ assertRegistrationDeployment (t , controller .kubeClient .Actions (), "update" , "" , "cluster1" , 3 , false )
1014
1119
assertWorkDeployment (t , controller .kubeClient .Actions (), "update" , "cluster1" , operatorapiv1 .InstallModeDefault , 3 )
1015
1120
}
1016
1121
@@ -1031,7 +1136,7 @@ func TestClusterNameChange(t *testing.T) {
1031
1136
}
1032
1137
1033
1138
// Check if deployment has the right cluster name set
1034
- assertRegistrationDeployment (t , controller .kubeClient .Actions (), createVerb , "" , "cluster1" , 1 )
1139
+ assertRegistrationDeployment (t , controller .kubeClient .Actions (), createVerb , "" , "cluster1" , 1 , false )
1035
1140
1036
1141
operatorAction := controller .operatorClient .Actions ()
1037
1142
testingcommon .AssertActions (t , operatorAction , "patch" )
@@ -1061,7 +1166,7 @@ func TestClusterNameChange(t *testing.T) {
1061
1166
if err != nil {
1062
1167
t .Errorf ("Expected non error when sync, %v" , err )
1063
1168
}
1064
- assertRegistrationDeployment (t , controller .kubeClient .Actions (), "update" , "" , "" , 1 )
1169
+ assertRegistrationDeployment (t , controller .kubeClient .Actions (), "update" , "" , "" , 1 , false )
1065
1170
1066
1171
// Update hubconfigsecret and sync again
1067
1172
hubSecret .Data ["cluster-name" ] = []byte ("cluster2" )
@@ -1099,7 +1204,7 @@ func TestClusterNameChange(t *testing.T) {
1099
1204
if err != nil {
1100
1205
t .Errorf ("Expected non error when sync, %v" , err )
1101
1206
}
1102
- assertRegistrationDeployment (t , controller .kubeClient .Actions (), "update" , "https://localhost" , "cluster3" , 1 )
1207
+ assertRegistrationDeployment (t , controller .kubeClient .Actions (), "update" , "https://localhost" , "cluster3" , 1 , false )
1103
1208
assertWorkDeployment (t , controller .kubeClient .Actions (), "update" , "cluster3" , "" , 0 )
1104
1209
}
1105
1210
0 commit comments