From 874b3249e50601d6bbf35e2997a3e608b15028ba Mon Sep 17 00:00:00 2001 From: chenyixiang <283158956@qq.com> Date: Wed, 3 Jul 2019 23:28:02 +0800 Subject: [PATCH] Get the pdb when conflict instead of relisting Change-Id: I50ff6fede509c9b4f81db62718d2150a3c45522f --- pkg/registry/core/pod/storage/eviction.go | 30 +++++++++++++++++------ 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/pkg/registry/core/pod/storage/eviction.go b/pkg/registry/core/pod/storage/eviction.go index 386244451b0..b74e79a728b 100644 --- a/pkg/registry/core/pod/storage/eviction.go +++ b/pkg/registry/core/pod/storage/eviction.go @@ -133,7 +133,7 @@ func (r *EvictionREST) Create(ctx context.Context, obj runtime.Object, createVal } var rtStatus *metav1.Status var pdbName string - err = retry.RetryOnConflict(EvictionsRetry, func() error { + err = func() error { pdbs, err := r.getPodDisruptionBudgets(ctx, pod) if err != nil { return err @@ -146,19 +146,33 @@ func (r *EvictionREST) Create(ctx context.Context, obj runtime.Object, createVal Code: 500, } return nil - } else if len(pdbs) == 1 { - pdb := pdbs[0] - pdbName = pdb.Name + } + if len(pdbs) == 0 { + return nil + } + + pdb := &pdbs[0] + pdbName = pdb.Name + refresh := false + err = retry.RetryOnConflict(EvictionsRetry, func() error { + if refresh { + pdb, err = r.podDisruptionBudgetClient.PodDisruptionBudgets(pod.Namespace).Get(pdbName, metav1.GetOptions{}) + if err != nil { + return err + } + } // Try to verify-and-decrement // If it was false already, or if it becomes false during the course of our retries, // raise an error marked as a 429. - if err := r.checkAndDecrement(pod.Namespace, pod.Name, pdb, dryrun.IsDryRun(deletionOptions.DryRun)); err != nil { + if err = r.checkAndDecrement(pod.Namespace, pod.Name, *pdb, dryrun.IsDryRun(deletionOptions.DryRun)); err != nil { + refresh = true return err } - } - return nil - }) + return nil + }) + return err + }() if err == wait.ErrWaitTimeout { err = errors.NewTimeoutError(fmt.Sprintf("couldn't update PodDisruptionBudget %q due to conflicts", pdbName), 10) }