Skip to content

Commit

Permalink
Use evict instead of delete when updating image
Browse files Browse the repository at this point in the history
* Make sure failed to evict pods get unquiesced
  • Loading branch information
David Amsallem authored and damsallem committed Jul 16, 2024
1 parent a81d4bc commit 7070bd4
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions controllers/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -437,10 +437,21 @@ func (r *SingleClusterReconciler) deletePodAndEnsureImageUpdated(
return reconcileError(err)
}

failedEvictedPods := make([]*corev1.Pod, 0)

// Delete pods
for _, p := range podsToUpdate {
if err := r.Client.Delete(context.TODO(), p); err != nil {
return reconcileError(err)
if err := r.KubeClient.CoreV1().Pods(p.Namespace).Evict(context.TODO(),
&policyv1beta1.Eviction{
ObjectMeta: metav1.ObjectMeta{
Name: p.Name,
Namespace: p.Namespace,
},
}); err != nil {
r.Log.Error(err, fmt.Sprintf("Not evictable pod %s in ns %s. Will QuiesceUndo and retry. Error: %s", p.Name, p.Namespace, err.Error()))

Check failure on line 451 in controllers/pod.go

View workflow job for this annotation

GitHub Actions / lint (.)

line is 138 characters (lll)
// in case of error during the eviction, unquiesce the node since it has been quiesced.
failedEvictedPods = append(failedEvictedPods, p)
continue
}

r.Log.V(1).Info("Pod deleted", "podName", p.Name)
Expand All @@ -450,6 +461,12 @@ func (r *SingleClusterReconciler) deletePodAndEnsureImageUpdated(
)
}

if len(failedEvictedPods) > 0 {
if err := r.quiesceUndoPods(r.getClientPolicy(), failedEvictedPods); err != nil {
r.Log.Error(err, "Unexpected error during quiesce-undo command")
}
}

return r.ensurePodsImageUpdated(podsToUpdate)
}

Expand Down

0 comments on commit 7070bd4

Please sign in to comment.