|
97 | 97 | },
|
98 | 98 | },
|
99 | 99 | }
|
100 |
| - instanceForServeSvc = &rayv1.RayCluster{ |
| 100 | + instanceForSvc = &rayv1.RayCluster{ |
101 | 101 | ObjectMeta: metav1.ObjectMeta{
|
102 | 102 | Name: "raycluster-sample-svc",
|
103 | 103 | Namespace: "default",
|
@@ -450,6 +450,49 @@ func TestBuildServiceForHeadPodPortsOrder(t *testing.T) {
|
450 | 450 | }
|
451 | 451 | }
|
452 | 452 |
|
| 453 | +func TestBuildHeadlessServiceForRayCluster(t *testing.T) { |
| 454 | + svc := BuildHeadlessServiceForRayCluster(*instanceForSvc) |
| 455 | + |
| 456 | + actualSelector := svc.Spec.Selector[utils.RayClusterLabelKey] |
| 457 | + expectedSelector := instanceForSvc.Name |
| 458 | + if !reflect.DeepEqual(expectedSelector, actualSelector) { |
| 459 | + t.Fatalf("Expected `%v` but got `%v`", expectedSelector, actualSelector) |
| 460 | + } |
| 461 | + |
| 462 | + actualSelector = svc.Spec.Selector[utils.RayNodeTypeLabelKey] |
| 463 | + expectedSelector = string(rayv1.WorkerNode) |
| 464 | + if !reflect.DeepEqual(expectedSelector, actualSelector) { |
| 465 | + t.Fatalf("Expected `%v` but got `%v`", expectedSelector, actualSelector) |
| 466 | + } |
| 467 | + |
| 468 | + actualLabel := svc.Labels[utils.RayClusterHeadlessServiceLabelKey] |
| 469 | + expectedLabel := instanceForSvc.Name |
| 470 | + if !reflect.DeepEqual(expectedLabel, actualLabel) { |
| 471 | + t.Fatalf("Expected `%v` but got `%v`", expectedLabel, actualLabel) |
| 472 | + } |
| 473 | + |
| 474 | + actualType := svc.Spec.Type |
| 475 | + expectedType := corev1.ServiceTypeClusterIP |
| 476 | + if !reflect.DeepEqual(expectedType, actualType) { |
| 477 | + t.Fatalf("Expected `%v` but got `%v`", expectedType, actualType) |
| 478 | + } |
| 479 | + |
| 480 | + actualClusterIP := svc.Spec.ClusterIP |
| 481 | + expectedClusterIP := corev1.ClusterIPNone |
| 482 | + if !reflect.DeepEqual(expectedClusterIP, actualClusterIP) { |
| 483 | + t.Fatalf("Expected `%v` but got `%v`", expectedClusterIP, actualClusterIP) |
| 484 | + } |
| 485 | + |
| 486 | + actualPublishNotReadyAddresses := svc.Spec.PublishNotReadyAddresses |
| 487 | + expectedPublishNotReadyAddresses := true |
| 488 | + if !reflect.DeepEqual(expectedClusterIP, actualClusterIP) { |
| 489 | + t.Fatalf("Expected `%v` but got `%v`", expectedPublishNotReadyAddresses, actualPublishNotReadyAddresses) |
| 490 | + } |
| 491 | + |
| 492 | + expectedName := fmt.Sprintf("%s-%s", instanceForSvc.Name, utils.HeadlessServiceSuffix) |
| 493 | + validateNameAndNamespaceForUserSpecifiedService(svc, serviceInstance.ObjectMeta.Namespace, expectedName, t) |
| 494 | +} |
| 495 | + |
453 | 496 | func TestBuildServeServiceForRayService(t *testing.T) {
|
454 | 497 | svc, err := BuildServeServiceForRayService(context.Background(), *serviceInstance, *instanceWithWrongSvc)
|
455 | 498 | assert.Nil(t, err)
|
@@ -483,30 +526,30 @@ func TestBuildServeServiceForRayService(t *testing.T) {
|
483 | 526 | }
|
484 | 527 |
|
485 | 528 | func TestBuildServeServiceForRayCluster(t *testing.T) {
|
486 |
| - svc, err := BuildServeServiceForRayCluster(context.Background(), *instanceForServeSvc) |
| 529 | + svc, err := BuildServeServiceForRayCluster(context.Background(), *instanceForSvc) |
487 | 530 | assert.Nil(t, err)
|
488 | 531 |
|
489 | 532 | actualResult := svc.Spec.Selector[utils.RayClusterLabelKey]
|
490 |
| - expectedResult := instanceForServeSvc.Name |
| 533 | + expectedResult := instanceForSvc.Name |
491 | 534 | if !reflect.DeepEqual(expectedResult, actualResult) {
|
492 | 535 | t.Fatalf("Expected `%v` but got `%v`", expectedResult, actualResult)
|
493 | 536 | }
|
494 | 537 |
|
495 | 538 | actualLabel := svc.Labels[utils.RayOriginatedFromCRNameLabelKey]
|
496 |
| - expectedLabel := instanceForServeSvc.Name |
| 539 | + expectedLabel := instanceForSvc.Name |
497 | 540 | assert.Equal(t, expectedLabel, actualLabel)
|
498 | 541 |
|
499 | 542 | actualLabel = svc.Labels[utils.RayOriginatedFromCRDLabelKey]
|
500 | 543 | expectedLabel = utils.RayOriginatedFromCRDLabelValue(utils.RayClusterCRD)
|
501 | 544 | assert.Equal(t, expectedLabel, actualLabel)
|
502 | 545 |
|
503 | 546 | actualType := svc.Spec.Type
|
504 |
| - expectedType := instanceForServeSvc.Spec.HeadGroupSpec.ServiceType |
| 547 | + expectedType := instanceForSvc.Spec.HeadGroupSpec.ServiceType |
505 | 548 | if !reflect.DeepEqual(expectedType, actualType) {
|
506 | 549 | t.Fatalf("Expected `%v` but got `%v`", expectedType, actualType)
|
507 | 550 | }
|
508 | 551 |
|
509 |
| - expectedName := fmt.Sprintf("%s-%s-%s", instanceForServeSvc.Name, "serve", "svc") |
| 552 | + expectedName := fmt.Sprintf("%s-%s-%s", instanceForSvc.Name, "serve", "svc") |
510 | 553 | validateNameAndNamespaceForUserSpecifiedService(svc, serviceInstance.ObjectMeta.Namespace, expectedName, t)
|
511 | 554 | }
|
512 | 555 |
|
|
0 commit comments