@@ -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,46 @@ 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
+
407
+ expectedArgs = append (expectedArgs , "--status-sync-interval=60s" , "--kube-api-qps=20" , "--kube-api-burst=60" ,
408
+ "--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
+ func assertRegistrationDeployment (t * testing.T , actions []clienttesting.Action , verb , serverURL , clusterName string , replica int32 , awsAuth bool ) {
378
418
deployment := getDeployments (actions , verb , "registration-agent" )
379
419
if deployment == nil {
380
420
t .Errorf ("registration deployment not found" )
@@ -402,7 +442,9 @@ func assertRegistrationDeployment(t *testing.T, actions []clienttesting.Action,
402
442
}
403
443
404
444
expectedArgs = append (expectedArgs , "--kube-api-qps=10" , "--kube-api-burst=60" )
405
-
445
+ if awsAuth {
446
+ expectedArgs = append (expectedArgs , "--registration-auth=awsirsa" , "--hub-cluster-arn=arneks:us-west-2:123456789012:cluster/hub-cluster1" )
447
+ }
406
448
if ! equality .Semantic .DeepEqual (args , expectedArgs ) {
407
449
t .Errorf ("Expect args %v, but got %v" , expectedArgs , args )
408
450
return
@@ -944,6 +986,67 @@ func TestGetServersFromKlusterlet(t *testing.T) {
944
986
}
945
987
}
946
988
989
+ func TestAWSIrsaAuthInSingletonMode (t * testing.T ) {
990
+ klusterlet := newKlusterlet ("klusterlet" , "testns" , "cluster1" )
991
+ awsIrsaRegistrationDriver := operatorapiv1.RegistrationDriver {
992
+ AuthType : AwsIrsaAuthType ,
993
+ AwsIrsa : & operatorapiv1.AwsIrsa {
994
+ HubClusterArn : "arneks:us-west-2:123456789012:cluster/hub-cluster1" ,
995
+ },
996
+ }
997
+ klusterlet .Spec .RegistrationConfiguration .RegistrationDriver = awsIrsaRegistrationDriver
998
+ klusterlet .Spec .DeployOption .Mode = operatorapiv1 .InstallModeSingleton
999
+ hubSecret := newSecret (helpers .HubKubeConfig , "testns" )
1000
+ hubSecret .Data ["kubeconfig" ] = []byte ("dummuykubeconnfig" )
1001
+ hubSecret .Data ["cluster-name" ] = []byte ("cluster1" )
1002
+ objects := []runtime.Object {
1003
+ newNamespace ("testns" ),
1004
+ newSecret (helpers .BootstrapHubKubeConfig , "testns" ),
1005
+ hubSecret ,
1006
+ }
1007
+
1008
+ syncContext := testingcommon .NewFakeSyncContext (t , "klusterlet" )
1009
+ controller := newTestController (t , klusterlet , syncContext .Recorder (), nil , false ,
1010
+ objects ... )
1011
+
1012
+ err := controller .controller .sync (context .TODO (), syncContext )
1013
+ if err != nil {
1014
+ t .Errorf ("Expected non error when sync, %v" , err )
1015
+ }
1016
+
1017
+ assertKlusterletDeployment (t , controller .kubeClient .Actions (), createVerb , "" , "cluster1" )
1018
+ }
1019
+
1020
+ func TestAWSIrsaAuthInNonSingletonMode (t * testing.T ) {
1021
+ klusterlet := newKlusterlet ("klusterlet" , "testns" , "cluster1" )
1022
+ awsIrsaRegistrationDriver := operatorapiv1.RegistrationDriver {
1023
+ AuthType : AwsIrsaAuthType ,
1024
+ AwsIrsa : & operatorapiv1.AwsIrsa {
1025
+ HubClusterArn : "arneks:us-west-2:123456789012:cluster/hub-cluster1" ,
1026
+ },
1027
+ }
1028
+ klusterlet .Spec .RegistrationConfiguration .RegistrationDriver = awsIrsaRegistrationDriver
1029
+ hubSecret := newSecret (helpers .HubKubeConfig , "testns" )
1030
+ hubSecret .Data ["kubeconfig" ] = []byte ("dummuykubeconnfig" )
1031
+ hubSecret .Data ["cluster-name" ] = []byte ("cluster1" )
1032
+ objects := []runtime.Object {
1033
+ newNamespace ("testns" ),
1034
+ newSecret (helpers .BootstrapHubKubeConfig , "testns" ),
1035
+ hubSecret ,
1036
+ }
1037
+
1038
+ syncContext := testingcommon .NewFakeSyncContext (t , "klusterlet" )
1039
+ controller := newTestController (t , klusterlet , syncContext .Recorder (), nil , false ,
1040
+ objects ... )
1041
+
1042
+ err := controller .controller .sync (context .TODO (), syncContext )
1043
+ if err != nil {
1044
+ t .Errorf ("Expected non error when sync, %v" , err )
1045
+ }
1046
+
1047
+ assertRegistrationDeployment (t , controller .kubeClient .Actions (), createVerb , "" , "cluster1" , 1 , true )
1048
+ }
1049
+
947
1050
func TestReplica (t * testing.T ) {
948
1051
klusterlet := newKlusterlet ("klusterlet" , "testns" , "cluster1" )
949
1052
hubSecret := newSecret (helpers .HubKubeConfig , "testns" )
@@ -965,7 +1068,7 @@ func TestReplica(t *testing.T) {
965
1068
}
966
1069
967
1070
// should have 1 replica for registration deployment and 0 for work
968
- assertRegistrationDeployment (t , controller .kubeClient .Actions (), createVerb , "" , "cluster1" , 1 )
1071
+ assertRegistrationDeployment (t , controller .kubeClient .Actions (), createVerb , "" , "cluster1" , 1 , false )
969
1072
assertWorkDeployment (t , controller .kubeClient .Actions (), createVerb , "cluster1" , operatorapiv1 .InstallModeDefault , 0 )
970
1073
971
1074
klusterlet = newKlusterlet ("klusterlet" , "testns" , "cluster1" )
@@ -1010,7 +1113,7 @@ func TestReplica(t *testing.T) {
1010
1113
}
1011
1114
1012
1115
// should have 3 replicas for clusters with multiple nodes
1013
- assertRegistrationDeployment (t , controller .kubeClient .Actions (), "update" , "" , "cluster1" , 3 )
1116
+ assertRegistrationDeployment (t , controller .kubeClient .Actions (), "update" , "" , "cluster1" , 3 , false )
1014
1117
assertWorkDeployment (t , controller .kubeClient .Actions (), "update" , "cluster1" , operatorapiv1 .InstallModeDefault , 3 )
1015
1118
}
1016
1119
@@ -1031,7 +1134,7 @@ func TestClusterNameChange(t *testing.T) {
1031
1134
}
1032
1135
1033
1136
// Check if deployment has the right cluster name set
1034
- assertRegistrationDeployment (t , controller .kubeClient .Actions (), createVerb , "" , "cluster1" , 1 )
1137
+ assertRegistrationDeployment (t , controller .kubeClient .Actions (), createVerb , "" , "cluster1" , 1 , false )
1035
1138
1036
1139
operatorAction := controller .operatorClient .Actions ()
1037
1140
testingcommon .AssertActions (t , operatorAction , "patch" )
@@ -1061,7 +1164,7 @@ func TestClusterNameChange(t *testing.T) {
1061
1164
if err != nil {
1062
1165
t .Errorf ("Expected non error when sync, %v" , err )
1063
1166
}
1064
- assertRegistrationDeployment (t , controller .kubeClient .Actions (), "update" , "" , "" , 1 )
1167
+ assertRegistrationDeployment (t , controller .kubeClient .Actions (), "update" , "" , "" , 1 , false )
1065
1168
1066
1169
// Update hubconfigsecret and sync again
1067
1170
hubSecret .Data ["cluster-name" ] = []byte ("cluster2" )
@@ -1099,7 +1202,7 @@ func TestClusterNameChange(t *testing.T) {
1099
1202
if err != nil {
1100
1203
t .Errorf ("Expected non error when sync, %v" , err )
1101
1204
}
1102
- assertRegistrationDeployment (t , controller .kubeClient .Actions (), "update" , "https://localhost" , "cluster3" , 1 )
1205
+ assertRegistrationDeployment (t , controller .kubeClient .Actions (), "update" , "https://localhost" , "cluster3" , 1 , false )
1103
1206
assertWorkDeployment (t , controller .kubeClient .Actions (), "update" , "cluster3" , "" , 0 )
1104
1207
}
1105
1208
0 commit comments