@@ -797,26 +797,26 @@ func Test_GenDNSHostnames(t *testing.T) {
797
797
clusterName : "test-cluster" ,
798
798
replicaIndex : 0 ,
799
799
numOfHosts : int32 (1 ),
800
- expectedHostnames : fmt .Sprintf ("%s-%d-%d.%s-%s" , "test-group" , 0 , 0 , "test-cluster" , headlessServiceSuffix ),
800
+ expectedHostnames : fmt .Sprintf ("%s-%d-%d.%s-%s" , "test-group" , 0 , 0 , "test-cluster" , utils . HeadlessServiceSuffix ),
801
801
},
802
802
"genDNSHostnames with NumOfHosts > 1" : {
803
803
// multi-host worker group, should return a string list of DNS hostnames for the given replica
804
804
clusterName : "test-cluster" ,
805
805
replicaIndex : 1 ,
806
806
numOfHosts : int32 (4 ),
807
- expectedHostnames : strings .Join ([]string {fmt .Sprintf ("%s-%d-%d.%s-%s" , "test-group" , 1 , 0 , "test-cluster" , headlessServiceSuffix ),
808
- fmt .Sprintf ("%s-%d-%d.%s-%s" , "test-group" , 1 , 1 , "test-cluster" , headlessServiceSuffix ),
809
- fmt .Sprintf ("%s-%d-%d.%s-%s" , "test-group" , 1 , 2 , "test-cluster" , headlessServiceSuffix ),
810
- fmt .Sprintf ("%s-%d-%d.%s-%s" , "test-group" , 1 , 3 , "test-cluster" , headlessServiceSuffix ),
807
+ expectedHostnames : strings .Join ([]string {fmt .Sprintf ("%s-%d-%d.%s-%s" , "test-group" , 1 , 0 , "test-cluster" , utils . HeadlessServiceSuffix ),
808
+ fmt .Sprintf ("%s-%d-%d.%s-%s" , "test-group" , 1 , 1 , "test-cluster" , utils . HeadlessServiceSuffix ),
809
+ fmt .Sprintf ("%s-%d-%d.%s-%s" , "test-group" , 1 , 2 , "test-cluster" , utils . HeadlessServiceSuffix ),
810
+ fmt .Sprintf ("%s-%d-%d.%s-%s" , "test-group" , 1 , 3 , "test-cluster" , utils . HeadlessServiceSuffix ),
811
811
}, "," ),
812
812
},
813
813
"genDNSHostnames with long RayCluster name" : {
814
814
// Multi-host worker group in a RayCluster with a name that will be truncated
815
815
clusterName : "long-raycluster-name-to-be-truncated" ,
816
816
replicaIndex : 1 ,
817
817
numOfHosts : int32 (2 ),
818
- expectedHostnames : strings .Join ([]string {fmt .Sprintf ("%s-%d-%d.%s-%s" , "test-group" , 1 , 0 , "aycluster-name-to-be-truncated" , headlessServiceSuffix ),
819
- fmt .Sprintf ("%s-%d-%d.%s-%s" , "test-group" , 1 , 1 , "aycluster-name-to-be-truncated" , headlessServiceSuffix ),
818
+ expectedHostnames : strings .Join ([]string {fmt .Sprintf ("%s-%d-%d.%s-%s" , "test-group" , 1 , 0 , "aycluster-name-to-be-truncated" , utils . HeadlessServiceSuffix ),
819
+ fmt .Sprintf ("%s-%d-%d.%s-%s" , "test-group" , 1 , 1 , "aycluster-name-to-be-truncated" , utils . HeadlessServiceSuffix ),
820
820
}, "," ),
821
821
},
822
822
}
@@ -846,23 +846,23 @@ func Test_InjectHostnames(t *testing.T) {
846
846
// This function is only called for multi-host TPU worker groups.
847
847
clusterName : "test-cluster" ,
848
848
groupName : "test-group-name" ,
849
- expectedSubdomain : fmt .Sprintf ("%s-%s" , "test-cluster" , headlessServiceSuffix ),
850
- expectedHostnames : strings .Join ([]string {fmt .Sprintf ("%s-%d-%d.%s-%s" , "test-group" , 1 , 0 , "test-cluster" , headlessServiceSuffix ),
851
- fmt .Sprintf ("%s-%d-%d.%s-%s" , "test-group" , 1 , 1 , "test-cluster" , headlessServiceSuffix ),
852
- fmt .Sprintf ("%s-%d-%d.%s-%s" , "test-group" , 1 , 2 , "test-cluster" , headlessServiceSuffix ),
853
- fmt .Sprintf ("%s-%d-%d.%s-%s" , "test-group" , 1 , 3 , "test-cluster" , headlessServiceSuffix ),
849
+ expectedSubdomain : fmt .Sprintf ("%s-%s" , "test-cluster" , utils . HeadlessServiceSuffix ),
850
+ expectedHostnames : strings .Join ([]string {fmt .Sprintf ("%s-%d-%d.%s-%s" , "test-group" , 1 , 0 , "test-cluster" , utils . HeadlessServiceSuffix ),
851
+ fmt .Sprintf ("%s-%d-%d.%s-%s" , "test-group" , 1 , 1 , "test-cluster" , utils . HeadlessServiceSuffix ),
852
+ fmt .Sprintf ("%s-%d-%d.%s-%s" , "test-group" , 1 , 2 , "test-cluster" , utils . HeadlessServiceSuffix ),
853
+ fmt .Sprintf ("%s-%d-%d.%s-%s" , "test-group" , 1 , 3 , "test-cluster" , utils . HeadlessServiceSuffix ),
854
854
}, "," ),
855
855
},
856
856
"injectHostnames for multi-host worker group with truncated service name" : {
857
857
// Should create a patch to set the subdomain and TPU_WORKER_HOSTNAMES for all hosts, with the
858
858
// correct subdomain truncated to match the created service name.
859
859
clusterName : "extremely-long-test-raycluster-name" ,
860
860
groupName : "test-group-name" ,
861
- expectedSubdomain : fmt .Sprintf ("%s-%s" , "mely-long-test-raycluster-name" , headlessServiceSuffix ),
862
- expectedHostnames : strings .Join ([]string {fmt .Sprintf ("%s-%d-%d.%s-%s" , "test-group" , 1 , 0 , "mely-long-test-raycluster-name" , headlessServiceSuffix ),
863
- fmt .Sprintf ("%s-%d-%d.%s-%s" , "test-group" , 1 , 1 , "mely-long-test-raycluster-name" , headlessServiceSuffix ),
864
- fmt .Sprintf ("%s-%d-%d.%s-%s" , "test-group" , 1 , 2 , "mely-long-test-raycluster-name" , headlessServiceSuffix ),
865
- fmt .Sprintf ("%s-%d-%d.%s-%s" , "test-group" , 1 , 3 , "mely-long-test-raycluster-name" , headlessServiceSuffix ),
861
+ expectedSubdomain : fmt .Sprintf ("%s-%s" , "mely-long-test-raycluster-name" , utils . HeadlessServiceSuffix ),
862
+ expectedHostnames : strings .Join ([]string {fmt .Sprintf ("%s-%d-%d.%s-%s" , "test-group" , 1 , 0 , "mely-long-test-raycluster-name" , utils . HeadlessServiceSuffix ),
863
+ fmt .Sprintf ("%s-%d-%d.%s-%s" , "test-group" , 1 , 1 , "mely-long-test-raycluster-name" , utils . HeadlessServiceSuffix ),
864
+ fmt .Sprintf ("%s-%d-%d.%s-%s" , "test-group" , 1 , 2 , "mely-long-test-raycluster-name" , utils . HeadlessServiceSuffix ),
865
+ fmt .Sprintf ("%s-%d-%d.%s-%s" , "test-group" , 1 , 3 , "mely-long-test-raycluster-name" , utils . HeadlessServiceSuffix ),
866
866
}, "," ),
867
867
},
868
868
}
@@ -1154,7 +1154,7 @@ func Test_GetEnvironmentVariable(t *testing.T) {
1154
1154
}
1155
1155
workerHostnames := corev1.EnvVar {
1156
1156
Name : "TPU_WORKER_HOSTNAMES" ,
1157
- Value : fmt .Sprintf ("%s-%d-%d.%s-%s" , "test-group" , 0 , 0 , "test-cluster" , headlessServiceSuffix ),
1157
+ Value : fmt .Sprintf ("%s-%d-%d.%s-%s" , "test-group" , 0 , 0 , "test-cluster" , utils . HeadlessServiceSuffix ),
1158
1158
}
1159
1159
podContainer .Env = []corev1.EnvVar {workerID , workerName , workerHostnames }
1160
1160
@@ -1179,7 +1179,7 @@ func Test_GetEnvironmentVariable(t *testing.T) {
1179
1179
// returns TPU_WORKER_HOSTNAMES env var value
1180
1180
variableName : "TPU_WORKER_HOSTNAMES" ,
1181
1181
container : podContainer ,
1182
- expectedValue : fmt .Sprintf ("%s-%d-%d.%s-%s" , "test-group" , 0 , 0 , "test-cluster" , headlessServiceSuffix ),
1182
+ expectedValue : fmt .Sprintf ("%s-%d-%d.%s-%s" , "test-group" , 0 , 0 , "test-cluster" , utils . HeadlessServiceSuffix ),
1183
1183
},
1184
1184
}
1185
1185
@@ -1369,10 +1369,10 @@ func Test_MutatePod(t *testing.T) {
1369
1369
expectedWorkerID : "0" ,
1370
1370
expectedReplicaID : 0 ,
1371
1371
expectedWorkerName : fmt .Sprintf ("%s-%d" , "test-group" , 0 ),
1372
- expectedHostnames : strings .Join ([]string {fmt .Sprintf ("%s-%d-%d.%s-%s" , "test-group" , 0 , 0 , "test-cluster" , headlessServiceSuffix ),
1373
- fmt .Sprintf ("%s-%d-%d.%s-%s" , "test-group" , 0 , 1 , "test-cluster" , headlessServiceSuffix ),
1374
- fmt .Sprintf ("%s-%d-%d.%s-%s" , "test-group" , 0 , 2 , "test-cluster" , headlessServiceSuffix ),
1375
- fmt .Sprintf ("%s-%d-%d.%s-%s" , "test-group" , 0 , 3 , "test-cluster" , headlessServiceSuffix ),
1372
+ expectedHostnames : strings .Join ([]string {fmt .Sprintf ("%s-%d-%d.%s-%s" , "test-group" , 0 , 0 , "test-cluster" , utils . HeadlessServiceSuffix ),
1373
+ fmt .Sprintf ("%s-%d-%d.%s-%s" , "test-group" , 0 , 1 , "test-cluster" , utils . HeadlessServiceSuffix ),
1374
+ fmt .Sprintf ("%s-%d-%d.%s-%s" , "test-group" , 0 , 2 , "test-cluster" , utils . HeadlessServiceSuffix ),
1375
+ fmt .Sprintf ("%s-%d-%d.%s-%s" , "test-group" , 0 , 3 , "test-cluster" , utils . HeadlessServiceSuffix ),
1376
1376
}, "," ),
1377
1377
expectedReplicaLabel : fmt .Sprintf ("%s-%d" , "test-group" , 0 ),
1378
1378
},
@@ -1386,10 +1386,10 @@ func Test_MutatePod(t *testing.T) {
1386
1386
expectedWorkerID : "3" ,
1387
1387
expectedReplicaID : 0 ,
1388
1388
expectedWorkerName : fmt .Sprintf ("%s-%d" , "test-group" , 0 ),
1389
- expectedHostnames : strings .Join ([]string {fmt .Sprintf ("%s-%d-%d.%s-%s" , "test-group" , 0 , 0 , "test-cluster" , headlessServiceSuffix ),
1390
- fmt .Sprintf ("%s-%d-%d.%s-%s" , "test-group" , 0 , 1 , "test-cluster" , headlessServiceSuffix ),
1391
- fmt .Sprintf ("%s-%d-%d.%s-%s" , "test-group" , 0 , 2 , "test-cluster" , headlessServiceSuffix ),
1392
- fmt .Sprintf ("%s-%d-%d.%s-%s" , "test-group" , 0 , 3 , "test-cluster" , headlessServiceSuffix ),
1389
+ expectedHostnames : strings .Join ([]string {fmt .Sprintf ("%s-%d-%d.%s-%s" , "test-group" , 0 , 0 , "test-cluster" , utils . HeadlessServiceSuffix ),
1390
+ fmt .Sprintf ("%s-%d-%d.%s-%s" , "test-group" , 0 , 1 , "test-cluster" , utils . HeadlessServiceSuffix ),
1391
+ fmt .Sprintf ("%s-%d-%d.%s-%s" , "test-group" , 0 , 2 , "test-cluster" , utils . HeadlessServiceSuffix ),
1392
+ fmt .Sprintf ("%s-%d-%d.%s-%s" , "test-group" , 0 , 3 , "test-cluster" , utils . HeadlessServiceSuffix ),
1393
1393
}, "," ),
1394
1394
expectedReplicaLabel : fmt .Sprintf ("%s-%d" , "test-group" , 0 ),
1395
1395
},
@@ -1403,10 +1403,10 @@ func Test_MutatePod(t *testing.T) {
1403
1403
expectedWorkerID : "0" ,
1404
1404
expectedReplicaID : 1 ,
1405
1405
expectedWorkerName : fmt .Sprintf ("%s-%d" , "test-group" , 1 ),
1406
- expectedHostnames : strings .Join ([]string {fmt .Sprintf ("%s-%d-%d.%s-%s" , "test-group" , 1 , 0 , "test-cluster" , headlessServiceSuffix ),
1407
- fmt .Sprintf ("%s-%d-%d.%s-%s" , "test-group" , 1 , 1 , "test-cluster" , headlessServiceSuffix ),
1408
- fmt .Sprintf ("%s-%d-%d.%s-%s" , "test-group" , 1 , 2 , "test-cluster" , headlessServiceSuffix ),
1409
- fmt .Sprintf ("%s-%d-%d.%s-%s" , "test-group" , 1 , 3 , "test-cluster" , headlessServiceSuffix ),
1406
+ expectedHostnames : strings .Join ([]string {fmt .Sprintf ("%s-%d-%d.%s-%s" , "test-group" , 1 , 0 , "test-cluster" , utils . HeadlessServiceSuffix ),
1407
+ fmt .Sprintf ("%s-%d-%d.%s-%s" , "test-group" , 1 , 1 , "test-cluster" , utils . HeadlessServiceSuffix ),
1408
+ fmt .Sprintf ("%s-%d-%d.%s-%s" , "test-group" , 1 , 2 , "test-cluster" , utils . HeadlessServiceSuffix ),
1409
+ fmt .Sprintf ("%s-%d-%d.%s-%s" , "test-group" , 1 , 3 , "test-cluster" , utils . HeadlessServiceSuffix ),
1410
1410
}, "," ),
1411
1411
expectedReplicaLabel : fmt .Sprintf ("%s-%d" , "test-group" , 1 ),
1412
1412
},
@@ -1420,10 +1420,10 @@ func Test_MutatePod(t *testing.T) {
1420
1420
expectedWorkerID : "1" ,
1421
1421
expectedReplicaID : 1 ,
1422
1422
expectedWorkerName : fmt .Sprintf ("%s-%d" , "test-group" , 1 ),
1423
- expectedHostnames : strings .Join ([]string {fmt .Sprintf ("%s-%d-%d.%s-%s" , "test-group" , 1 , 0 , "test-cluster" , headlessServiceSuffix ),
1424
- fmt .Sprintf ("%s-%d-%d.%s-%s" , "test-group" , 1 , 1 , "test-cluster" , headlessServiceSuffix ),
1425
- fmt .Sprintf ("%s-%d-%d.%s-%s" , "test-group" , 1 , 2 , "test-cluster" , headlessServiceSuffix ),
1426
- fmt .Sprintf ("%s-%d-%d.%s-%s" , "test-group" , 1 , 3 , "test-cluster" , headlessServiceSuffix ),
1423
+ expectedHostnames : strings .Join ([]string {fmt .Sprintf ("%s-%d-%d.%s-%s" , "test-group" , 1 , 0 , "test-cluster" , utils . HeadlessServiceSuffix ),
1424
+ fmt .Sprintf ("%s-%d-%d.%s-%s" , "test-group" , 1 , 1 , "test-cluster" , utils . HeadlessServiceSuffix ),
1425
+ fmt .Sprintf ("%s-%d-%d.%s-%s" , "test-group" , 1 , 2 , "test-cluster" , utils . HeadlessServiceSuffix ),
1426
+ fmt .Sprintf ("%s-%d-%d.%s-%s" , "test-group" , 1 , 3 , "test-cluster" , utils . HeadlessServiceSuffix ),
1427
1427
}, "," ),
1428
1428
expectedReplicaLabel : fmt .Sprintf ("%s-%d" , "test-group" , 1 ),
1429
1429
},
@@ -1474,7 +1474,7 @@ func Test_MutatePod(t *testing.T) {
1474
1474
expectedHostnamesPatch := []interface {}([]interface {}{map [string ]interface {}{"name" : "TPU_WORKER_HOSTNAMES" , "value" : tc .expectedHostnames }})
1475
1475
assert .Equal (t , tc .expectedReplicaLabel , patches [0 ]["value" ])
1476
1476
assert .Equal (t , fmt .Sprintf ("%s-%s" , tc .expectedReplicaLabel , tc .expectedWorkerID ), patches [1 ]["value" ])
1477
- assert .Equal (t , fmt .Sprintf ("%s-%s" , "test-cluster" , headlessServiceSuffix ), patches [3 ]["value" ])
1477
+ assert .Equal (t , fmt .Sprintf ("%s-%s" , "test-cluster" , utils . HeadlessServiceSuffix ), patches [3 ]["value" ])
1478
1478
assert .Equal (t , expectedHostnamesPatch , patches [4 ]["value" ])
1479
1479
assert .Equal (t , expectedIDPatch , patches [5 ]["value" ])
1480
1480
assert .Equal (t , expectedNamePatch , patches [6 ]["value" ])
@@ -1489,13 +1489,13 @@ func Test_GenerateHeadlessServiceName(t *testing.T) {
1489
1489
testRayClusterName string
1490
1490
expectedServiceName string
1491
1491
}{
1492
- "RayCluster name + headless-worker-svc is less than 50 chars, no truncation" : {
1493
- testRayClusterName : "test-raycluster" , // 15 chars
1494
- expectedServiceName : " test-raycluster-headless-worker-svc " , // 35 chars
1492
+ "RayCluster name + -{HEADLESS_SERVICE_SUFFIX} is less than 50 chars, no truncation" : {
1493
+ testRayClusterName : "test-raycluster" , // 15 chars
1494
+ expectedServiceName : utils . CheckName ( fmt . Sprintf ( "%s-%s" , " test-raycluster" , utils . HeadlessServiceSuffix )),
1495
1495
},
1496
- "RayCluster name + headless-worker-svc is more than 50 chars, name is truncated" : {
1497
- testRayClusterName : "extremely-long-test-raycluster-name" , // 35 chars
1498
- expectedServiceName : "mely- long-test-raycluster-name-headless-worker-svc " , // 50 chars
1496
+ "RayCluster name + -{HEADLESS_SERVICE_SUFFIX} is more than 50 chars, name is truncated" : {
1497
+ testRayClusterName : "extremely-really-really- long-test-raycluster-name" , // 49 chars
1498
+ expectedServiceName : utils . CheckName ( fmt . Sprintf ( "%s-%s" , "extremely-really-really- long-test-raycluster-name" , utils . HeadlessServiceSuffix )),
1499
1499
},
1500
1500
}
1501
1501
0 commit comments