Skip to content

Commit

Permalink
Add ray head service endpoints in status (#341)
Browse files Browse the repository at this point in the history
Co-authored-by: chenyu.jiang <[email protected]>
  • Loading branch information
scarlet25151 and chenyu.jiang authored Jul 7, 2022
1 parent 267473f commit 3093d78
Show file tree
Hide file tree
Showing 9 changed files with 232 additions and 150 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
10 changes: 10 additions & 0 deletions ray-operator/config/crd/bases/ray.io_rayservices.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11589,6 +11589,11 @@ spec:
replicas 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 Expand Up @@ -11683,6 +11688,11 @@ spec:
replicas 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
24 changes: 24 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,30 @@ func (r *RayClusterReconciler) updateStatus(instance *rayiov1alpha1.RayCluster)
}
}

rayHeadSvc := corev1.ServiceList{}
filterLabels = client.MatchingLabels{
common.RayClusterLabelKey: instance.Name,
common.RayNodeTypeLabelKey: "head",
}
// 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 3093d78

Please sign in to comment.