Skip to content

Commit

Permalink
Pod IsAlreadyExists non-terminal error.
Browse files Browse the repository at this point in the history
Signed-off-by: Ville Aikas <[email protected]>
  • Loading branch information
vaikas committed Apr 7, 2022
1 parent faf4c25 commit ea1b381
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions pkg/reconciler/taskrun/taskrun.go
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,8 @@ func (c *Reconciler) handlePodCreationError(ctx context.Context, tr *v1beta1.Tas
tr.Status.MarkResourceOngoing(podconvert.ReasonExceededResourceQuota, fmt.Sprint("TaskRun Pod exceeded available resources: ", err))
case isTaskRunValidationFailed(err):
tr.Status.MarkResourceFailed(podconvert.ReasonFailedValidation, err)
case k8serrors.IsAlreadyExists(err):
tr.Status.MarkResourceOngoing(podconvert.ReasonPending, fmt.Sprint("tried to create pod, but it already exists"))
default:
// The pod creation failed with unknown reason. The most likely
// reason is that something is wrong with the spec of the Task, that we could
Expand Down Expand Up @@ -702,12 +704,23 @@ func (c *Reconciler) createPod(ctx context.Context, tr *v1beta1.TaskRun, rtr *re
return nil, fmt.Errorf("translating TaskSpec to Pod: %w", err)
}

// Stash the podname in case there's create conflict so that we can try
// to fetch it.
podName := pod.Name
pod, err = c.KubeClientSet.CoreV1().Pods(tr.Namespace).Create(ctx, pod, metav1.CreateOptions{})
if err == nil && willOverwritePodSetAffinity(tr) {
if recorder := controller.GetEventRecorder(ctx); recorder != nil {
recorder.Eventf(tr, corev1.EventTypeWarning, "PodAffinityOverwrite", "Pod template affinity is overwritten by affinity assistant for pod %q", pod.Name)
}
}
// If the pod failed to be created because it already exists, try to fetch
// from the informer and return if successful. Otherwise, return the
// original error.
if err != nil && k8serrors.IsAlreadyExists(err) {
if p, getErr := c.podLister.Pods(tr.Namespace).Get(podName); getErr == nil {
return p, nil
}
}
return pod, err
}

Expand Down

0 comments on commit ea1b381

Please sign in to comment.