func()

in tpu-provisioner/internal/controller/creation_controller.go [62:94]


func (r *CreationReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
	lg := ctrllog.FromContext(ctx)

	lg.V(3).Info("Reconciling Pod")

	var pod corev1.Pod
	if err := r.Get(ctx, req.NamespacedName, &pod); err != nil {
		if apierrors.IsNotFound(err) {
			// Don't requeue, Pod no longer exists.
			return ctrl.Result{}, nil
		}
		return ctrl.Result{}, fmt.Errorf("getting pod: %w", err)
	}

	lg.Info("Ensuring node pool for unschedulable pod")
	if err := r.Provider.EnsureNodePoolForPod(&pod, "pod is currently unschedulable"); err != nil {
		if errors.Is(err, cloud.ErrDuplicateRequest) {
			lg.V(3).Info("Ignoring duplicate request to create node pool", "message", err.Error())
		} else if errors.Is(err, cloud.ErrNodePoolStopping) {
			wait := 5 * time.Second
			lg.Info("Attempted to create a node pool that is currently undergoing deletion, retrying soon",
				"wait", wait)
			return ctrl.Result{RequeueAfter: wait}, nil
		} else if errors.Is(err, cloud.ErrNodePoolDeletedToBeRecreated) {
			lg.Info("Deleted a node pool that is to be recreated, requeuing")
			return ctrl.Result{Requeue: true}, nil
		} else {
			return ctrl.Result{}, err
		}
	}

	return ctrl.Result{}, nil
}