Skip to content

Commit

Permalink
Add check for RayCluster name in getReplicaIndex
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanaoleary committed Mar 7, 2024
1 parent 691f2bd commit 6019491
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions applications/ray/kuberay-tpu-webhook/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (

// our representation of a pod slice
type slice struct {
rayClusterName string
clusterName string
groupName string
replicaIndex int
numOfHosts int32
Expand Down Expand Up @@ -295,21 +295,23 @@ func getEnvironmentVariable(varName string, container corev1.Container) string {
}

// get next replica ID to assign a pod to
func getReplicaIndex() int {
func getReplicaIndex(clusterName string) int {
if sliceToWorkers == nil {
return 0
}
next_lowest_id := math.MaxInt32
for slice, workerList := range sliceToWorkers {
runningPods := 0
for _, worker := range workerList {
if worker.isRunning {
runningPods++
if slice.clusterName == clusterName {
runningPods := 0
for _, worker := range workerList {
if worker.isRunning {
runningPods++
}
}
}
if runningPods < int(slice.numOfHosts) {
if slice.replicaIndex < next_lowest_id {
next_lowest_id = slice.replicaIndex
if runningPods < int(slice.numOfHosts) {
if slice.replicaIndex < next_lowest_id {
next_lowest_id = slice.replicaIndex
}
}
}
}
Expand Down Expand Up @@ -394,7 +396,7 @@ func mutatePod(admissionReview *admissionv1.AdmissionReview) (*admissionv1.Admis
if containerRequestingTPUs(containers...) {
// assign worker to the next unique ID in the pod slice and update map
numOfHosts, _ := getNumTPUHostsFromTopology(topology) // ignore error here because topology may not be set yet
replicaIndex := getReplicaIndex()
replicaIndex := getReplicaIndex(clusterName)
podSlice := slice{clusterName, groupName, replicaIndex, numOfHosts}
tpuWorkerID := getNextWorkerID(podSlice, replicaIndex)

Expand Down

0 comments on commit 6019491

Please sign in to comment.