Skip to content

Commit

Permalink
remain consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
evalaiyc98 committed Apr 10, 2024
1 parent e4ebfe8 commit 8858022
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 14 deletions.
9 changes: 2 additions & 7 deletions ray-operator/controllers/ray/common/association.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,8 @@ func RayClusterAllPodsAssociationOptions(instance *rayv1.RayCluster) Association

func HeadServiceAssociationOptions(instance *rayv1.RayCluster) AssociationOptions {
return AssociationOptions{
client.MatchingLabels{
utils.RayClusterLabelKey: instance.Name,
utils.RayNodeTypeLabelKey: string(rayv1.HeadNode),
utils.RayIDLabelKey: utils.CheckLabel(utils.GenerateIdentifier(instance.Name, rayv1.HeadNode)),
utils.KubernetesApplicationNameLabelKey: utils.ApplicationName,
utils.KubernetesCreatedByLabelKey: utils.ComponentName,
},
client.InNamespace(instance.Namespace),
client.MatchingLabels(HeadServiceLabels(*instance)),
}
}

Expand Down
15 changes: 12 additions & 3 deletions ray-operator/controllers/ray/common/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import (
"fmt"
"sort"

"sigs.k8s.io/controller-runtime/pkg/client"

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
ctrl "sigs.k8s.io/controller-runtime"
Expand All @@ -15,6 +13,17 @@ import (
"github.com/ray-project/kuberay/ray-operator/controllers/ray/utils"
)

// HeadServiceLabels returns the default labels for a cluster's head service.
func HeadServiceLabels(cluster rayv1.RayCluster) map[string]string {
return map[string]string{
utils.RayClusterLabelKey: cluster.Name,
utils.RayNodeTypeLabelKey: string(rayv1.HeadNode),
utils.RayIDLabelKey: utils.CheckLabel(utils.GenerateIdentifier(cluster.Name, rayv1.HeadNode)),
utils.KubernetesApplicationNameLabelKey: utils.ApplicationName,
utils.KubernetesCreatedByLabelKey: utils.ComponentName,
}
}

// BuildServiceForHeadPod Builds the service for a pod. Currently, there is only one service that allows
// the worker nodes to connect to the head node.
func BuildServiceForHeadPod(ctx context.Context, cluster rayv1.RayCluster, labels map[string]string, annotations map[string]string) (*corev1.Service, error) {
Expand All @@ -24,7 +33,7 @@ func BuildServiceForHeadPod(ctx context.Context, cluster rayv1.RayCluster, label
labels = make(map[string]string)
}

default_labels := HeadServiceAssociationOptions(&cluster)[0].(client.MatchingLabels)
default_labels := HeadServiceLabels(cluster)

// selector consists of *only* the keys in default_labels, updated with the values in labels if they exist
selector := make(map[string]string)
Expand Down
4 changes: 1 addition & 3 deletions ray-operator/controllers/ray/common/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import (
"reflect"
"testing"

"sigs.k8s.io/controller-runtime/pkg/client"

rayv1 "github.com/ray-project/kuberay/ray-operator/apis/ray/v1"
"github.com/ray-project/kuberay/ray-operator/controllers/ray/utils"

Expand Down Expand Up @@ -295,7 +293,7 @@ func TestUserSpecifiedHeadService(t *testing.T) {

// The selector field should only use the keys from the five default labels. The values should be updated with the values from the template labels.
// The user-provided HeadService labels should be ignored for the purposes of the selector field. The user-provided Selector field should be ignored.
default_labels := HeadServiceAssociationOptions(testRayClusterWithHeadService)[0].(client.MatchingLabels)
default_labels := HeadServiceLabels(*testRayClusterWithHeadService)
// Make sure this test isn't spuriously passing. Check that RayClusterLabelKey is in the default labels.
if _, ok := default_labels[utils.RayClusterLabelKey]; !ok {
t.Errorf("utils.RayClusterLabelKey=%s should be in the default labels", utils.RayClusterLabelKey)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1372,7 +1372,7 @@ func TestGetHeadServiceIP(t *testing.T) {
ObjectMeta: metav1.ObjectMeta{
Name: "unexpectedExtraHeadService",
Namespace: namespaceStr,
Labels: common.HeadServiceAssociationOptions(testRayCluster)[0].(client.MatchingLabels),
Labels: common.HeadServiceLabels(*testRayCluster),
},
}

Expand Down

0 comments on commit 8858022

Please sign in to comment.