func getReplicaIndex()

in ray-on-gke/tpu/kuberay-tpu-webhook/main.go [443:467]


func getReplicaIndex(sliceToWorkerIDs map[slice][]int, clusterName string, groupName string, namespace string) int {
	// first pod created in cluster
	if len(sliceToWorkerIDs) == 0 {
		return 0
	}
	nextLowestId := math.MaxInt32
	numReplicas := 0 // tracks # of replicas in worker group created so far
	for slice, workerList := range sliceToWorkerIDs {
		if slice.clusterName == clusterName && slice.groupName == groupName && slice.namespace == namespace {
			numReplicas++
			createdPods := len(workerList)
			if createdPods < int(slice.numOfHosts) {
				if slice.replicaIndex < nextLowestId {
					nextLowestId = slice.replicaIndex
				}
			}
		}
	}
	// first pod of new slice in cluster
	if nextLowestId == math.MaxInt32 {
		nextLowestId = numReplicas
	}
	klog.V(1).InfoS("getReplicaIndex", "RayCluster", namespace+"/"+clusterName, "Worker Group", groupName, "Replica Index", nextLowestId)
	return nextLowestId
}