func()

in ray-on-gke/tpu/kuberay-tpu-webhook/main.go [766:798]


func (t *TPUWebhookServer) isLastAdmittedPod(pod *corev1.Pod) (bool, error) {
	if pod.Spec.Containers == nil || !containerRequestingTPUs(pod.Spec.Containers...) {
		// Pod does not use TPUs
		return false, nil
	}
	replicaIndex := pod.Labels["replicaIndex"]
	if replicaIndex == "" {
		// Pod was not mutated by the webhook
		return false, nil
	}
	clusterName := pod.Labels["ray.io/cluster"]
	if clusterName == "" {
		return false, errors.New("Ray Pod created by KubeRay missing RayCluster label")
	}
	namespace := pod.Namespace
	for _, container := range pod.Spec.Containers {
		if !containerRequestingTPUs(container) {
			// Skip to the next container
			continue
		}
		tpuWorkerID := getEnvironmentVariable("TPU_WORKER_ID", container)
		if tpuWorkerID == "" {
			// TPU pod was not intercepted by the webhook
			return false, nil
		}
		uniquePodID := fmt.Sprintf("%s-%s-%s-%s", namespace, clusterName, replicaIndex, tpuWorkerID)
		if uniquePodID == t.lastAdmitted {
			// Pod matches the last TPU worker Pod intercepted by the webhook server
			return true, nil
		}
	}
	return false, nil
}