Skip to content

Commit

Permalink
address PR feedback: only count running worker Pods as available
Browse files Browse the repository at this point in the history
  • Loading branch information
davidxia committed Feb 3, 2023
1 parent 9a943ae commit 5f403d0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
4 changes: 2 additions & 2 deletions ray-operator/controllers/ray/utils/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,14 +202,14 @@ func CalculateMaxReplicas(cluster *rayiov1alpha1.RayCluster) int32 {
}

// CalculateAvailableReplicas calculates available worker replicas at the cluster level
// A worker is available if its Pod is running or pending.
// A worker is available if its Pod is running
func CalculateAvailableReplicas(pods corev1.PodList) int32 {
count := int32(0)
for _, pod := range pods.Items {
if val, ok := pod.Labels["ray.io/node-type"]; !ok || val != string(rayiov1alpha1.WorkerNode) {
continue
}
if pod.Status.Phase == corev1.PodPending || pod.Status.Phase == corev1.PodRunning {
if pod.Status.Phase == corev1.PodRunning {
count++
}
}
Expand Down
22 changes: 22 additions & 0 deletions ray-operator/controllers/ray/utils/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,28 @@ func TestCalculateAvailableReplicas(t *testing.T) {
Phase: corev1.PodRunning,
},
},
{
ObjectMeta: metav1.ObjectMeta{
Name: "pod2",
Labels: map[string]string{
"ray.io/node-type": string(rayiov1alpha1.WorkerNode),
},
},
Status: corev1.PodStatus{
Phase: corev1.PodPending,
},
},
{
ObjectMeta: metav1.ObjectMeta{
Name: "pod2",
Labels: map[string]string{
"ray.io/node-type": string(rayiov1alpha1.WorkerNode),
},
},
Status: corev1.PodStatus{
Phase: corev1.PodFailed,
},
},
},
}
count := CalculateAvailableReplicas(podList)
Expand Down

0 comments on commit 5f403d0

Please sign in to comment.