-
Notifications
You must be signed in to change notification settings - Fork 616
feat: add RayCluster.status.readyWorkerReplicas
#1930
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -400,13 +400,22 @@ func (r *RayClusterReconciler) inconsistentRayClusterStatus(ctx context.Context, | |
oldStatus.State, newStatus.State, oldStatus.Reason, newStatus.Reason)) | ||
return true | ||
} | ||
if oldStatus.AvailableWorkerReplicas != newStatus.AvailableWorkerReplicas || oldStatus.DesiredWorkerReplicas != newStatus.DesiredWorkerReplicas || | ||
oldStatus.MinWorkerReplicas != newStatus.MinWorkerReplicas || oldStatus.MaxWorkerReplicas != newStatus.MaxWorkerReplicas { | ||
if oldStatus.ReadyWorkerReplicas != newStatus.ReadyWorkerReplicas || | ||
oldStatus.AvailableWorkerReplicas != newStatus.AvailableWorkerReplicas || | ||
oldStatus.DesiredWorkerReplicas != newStatus.DesiredWorkerReplicas || | ||
oldStatus.MinWorkerReplicas != newStatus.MinWorkerReplicas || | ||
oldStatus.MaxWorkerReplicas != newStatus.MaxWorkerReplicas { | ||
logger.Info("inconsistentRayClusterStatus", "detect inconsistency", fmt.Sprintf( | ||
"old AvailableWorkerReplicas: %d, new AvailableWorkerReplicas: %d, old DesiredWorkerReplicas: %d, new DesiredWorkerReplicas: %d, "+ | ||
"old MinWorkerReplicas: %d, new MinWorkerReplicas: %d, old MaxWorkerReplicas: %d, new MaxWorkerReplicas: %d", | ||
oldStatus.AvailableWorkerReplicas, newStatus.AvailableWorkerReplicas, oldStatus.DesiredWorkerReplicas, newStatus.DesiredWorkerReplicas, | ||
oldStatus.MinWorkerReplicas, newStatus.MinWorkerReplicas, oldStatus.MaxWorkerReplicas, newStatus.MaxWorkerReplicas)) | ||
"old ReadyWorkerReplicas: %d, new ReadyWorkerReplicas: %d, "+ | ||
"old AvailableWorkerReplicas: %d, new AvailableWorkerReplicas: %d, "+ | ||
"old DesiredWorkerReplicas: %d, new DesiredWorkerReplicas: %d, "+ | ||
"old MinWorkerReplicas: %d, new MinWorkerReplicas: %d, "+ | ||
"old MaxWorkerReplicas: %d, new MaxWorkerReplicas: %d", | ||
oldStatus.ReadyWorkerReplicas, newStatus.ReadyWorkerReplicas, | ||
oldStatus.AvailableWorkerReplicas, newStatus.AvailableWorkerReplicas, | ||
oldStatus.DesiredWorkerReplicas, newStatus.DesiredWorkerReplicas, | ||
oldStatus.MinWorkerReplicas, newStatus.MinWorkerReplicas, | ||
oldStatus.MaxWorkerReplicas, newStatus.MaxWorkerReplicas)) | ||
return true | ||
} | ||
if !reflect.DeepEqual(oldStatus.Endpoints, newStatus.Endpoints) || !reflect.DeepEqual(oldStatus.Head, newStatus.Head) { | ||
|
@@ -1222,6 +1231,7 @@ func (r *RayClusterReconciler) calculateStatus(ctx context.Context, instance *ra | |
return nil, err | ||
} | ||
|
||
newInstance.Status.ReadyWorkerReplicas = utils.CalculateReadyReplicas(runtimePods) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just for my own understanding, we can't use the existing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes |
||
newInstance.Status.AvailableWorkerReplicas = utils.CalculateAvailableReplicas(runtimePods) | ||
newInstance.Status.DesiredWorkerReplicas = utils.CalculateDesiredReplicas(ctx, newInstance) | ||
newInstance.Status.MinWorkerReplicas = utils.CalculateMinReplicas(newInstance) | ||
|
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -290,6 +290,25 @@ func CalculateMaxReplicas(cluster *rayv1.RayCluster) int32 { | |||
return count | ||||
} | ||||
|
||||
// CalculateReadyReplicas calculates ready worker replicas at the cluster level | ||||
// A worker is ready if its Pod has a PodCondition with type == Ready and status == True | ||||
func CalculateReadyReplicas(pods corev1.PodList) int32 { | ||||
count := int32(0) | ||||
for _, pod := range pods.Items { | ||||
if val, ok := pod.Labels["ray.io/node-type"]; !ok || val != string(rayv1.WorkerNode) { | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use |
||||
continue | ||||
} | ||||
for _, cond := range pod.Status.Conditions { | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use
|
||||
if cond.Type == corev1.PodReady && cond.Status == corev1.ConditionTrue { | ||||
count++ | ||||
break | ||||
} | ||||
} | ||||
} | ||||
|
||||
return count | ||||
} | ||||
|
||||
// CalculateAvailableReplicas calculates available worker replicas at the cluster level | ||||
// A worker is available if its Pod is running | ||||
func CalculateAvailableReplicas(pods corev1.PodList) int32 { | ||||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: KubeRay introduced structured logging in KubeRay v1.1.0, which logs messages in JSON format. Hence, we are trying to reduce the use of
fmt.Sprintf
. Instead, we want to use key-value pairs. For example,so that the logging tools can extract the information from the JSON easily. This is not the scope of this PR. It is not necessary to update this in this PR.