Skip to content

Commit

Permalink
add service port
Browse files Browse the repository at this point in the history
  • Loading branch information
chenyu.jiang committed Jul 6, 2022
1 parent 15cdd55 commit ae8f98a
Show file tree
Hide file tree
Showing 10 changed files with 234 additions and 156 deletions.
4 changes: 4 additions & 0 deletions apiserver/pkg/model/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ func FromCrdToApiCluster(cluster *v1alpha1.RayCluster, events []v1.Event) *api.C
pbCluster.Events = append(pbCluster.Events, clusterEvent)
}

pbCluster.ServiceEndpoint = map[string]string{}
for name, port := range cluster.Status.Endpoints {
pbCluster.ServiceEndpoint[name] = port
}
return pbCluster
}

Expand Down
3 changes: 3 additions & 0 deletions proto/cluster.proto
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ message Cluster {

// Output. The list related to the cluster.
repeated ClusterEvent events = 10;

// Output. The service endpoint of the cluster
map<string, string> service_endpoint = 11;
}

message ClusterSpec {
Expand Down
320 changes: 170 additions & 150 deletions proto/go_client/cluster.pb.go

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions proto/swagger/cluster.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,13 @@
"$ref": "#/definitions/protoClusterEvent"
},
"description": "Output. The list related to the cluster."
},
"serviceEndpoint": {
"type": "object",
"additionalProperties": {
"type": "string"
},
"title": "Output. The service endpoint of the cluster"
}
}
},
Expand Down
2 changes: 2 additions & 0 deletions ray-operator/apis/ray/v1alpha1/raycluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ type RayClusterStatus struct {
// LastUpdateTime indicates last update timestamp for this cluster status.
// +nullable
LastUpdateTime *metav1.Time `json:"lastUpdateTime,omitempty"`
// Service Endpoints
Endpoints map[string]string `json:"endpoints,omitempty"`
}

// RayNodeType the type of a ray node: head/worker
Expand Down
7 changes: 7 additions & 0 deletions ray-operator/apis/ray/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions ray-operator/config/crd/bases/ray.io_rayclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10987,6 +10987,11 @@ spec:
claimed by the user at the cluster level.
format: int32
type: integer
endpoints:
additionalProperties:
type: string
description: Service Endpoints
type: object
lastUpdateTime:
description: LastUpdateTime indicates last update timestamp for this
cluster status.
Expand Down
16 changes: 10 additions & 6 deletions ray-operator/controllers/ray/common/constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package common

const (
// Belows used as label key
RayServiceLabelKey = "ray.io/service"
RayClusterLabelKey = "ray.io/cluster"
RayNodeTypeLabelKey = "ray.io/node-type"
RayNodeGroupLabelKey = "ray.io/group"
RayNodeLabelKey = "ray.io/is-ray-node"
RayIDLabelKey = "ray.io/identifier"
RayServiceLabelKey = "ray.io/service"
RayClusterLabelKey = "ray.io/cluster"
RayNodeTypeLabelKey = "ray.io/node-type"
RayNodeGroupLabelKey = "ray.io/group"
RayNodeLabelKey = "ray.io/is-ray-node"
RayIDLabelKey = "ray.io/identifier"
RayServiceTypeLabelKey = "ray.io/service-type"

KubernetesApplicationNameLabelKey = "app.kubernetes.io/name"
KubernetesCreatedByLabelKey = "app.kubernetes.io/created-by"
Expand All @@ -32,6 +33,9 @@ const (
// The default name for kuberay operator
ComponentName = "kuberay-operator"

// The name for ray head service
HeadServiceName = "head-node-service"

// Check node if ready by checking the path exists or not
PodReadyFilepath = "POD_READY_FILEPATH"

Expand Down
1 change: 1 addition & 0 deletions ray-operator/controllers/ray/common/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ func BuildServiceForHeadPod(cluster rayiov1alpha1.RayCluster) (*corev1.Service,
RayIDLabelKey: utils.CheckLabel(utils.GenerateIdentifier(cluster.Name, rayiov1alpha1.HeadNode)),
KubernetesApplicationNameLabelKey: ApplicationName,
KubernetesCreatedByLabelKey: ComponentName,
RayServiceTypeLabelKey: DefaultHeadService,
}

service := &corev1.Service{
Expand Down
25 changes: 25 additions & 0 deletions ray-operator/controllers/ray/raycluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,31 @@ func (r *RayClusterReconciler) updateStatus(instance *rayiov1alpha1.RayCluster)
}
}

rayHeadSvc := corev1.ServiceList{}
filterLabels = client.MatchingLabels{
common.RayClusterLabelKey: instance.Name,
common.RayNodeTypeLabelKey: "head",
common.RayServiceTypeLabelKey: common.HeadServiceName,
}
// TODO: (@scarlet25151) for now there would be several kubernetes serivces related to
// one raycluster, we have used the label to select the headservice and pick the first one.
// we may need use Get method to select by name.
if err := r.List(context.TODO(), &rayHeadSvc, client.InNamespace(instance.Namespace), filterLabels); err != nil {
return err
}
if len(rayHeadSvc.Items) != 0 {
svc := rayHeadSvc.Items[0]
if instance.Status.Endpoints == nil {
instance.Status.Endpoints = map[string]string{}
}
for _, port := range svc.Spec.Ports {
if len(port.Name) == 0 {
r.Log.Info("updateStatus", "service port name is empty", port)
continue
}
instance.Status.Endpoints[port.Name] = fmt.Sprintf("%d", port.NodePort)
}
}
timeNow := metav1.Now()
instance.Status.LastUpdateTime = &timeNow
if err := r.Status().Update(context.Background(), instance); err != nil {
Expand Down

0 comments on commit ae8f98a

Please sign in to comment.