Merge pull request #42641 from deads2k/api-09-patch

Automatic merge from submit-queue

deflake TestPatch by waiting for cache

Fixes #39471

Rather than retry on conflicts for an unknown number of times, we have the resource version after the previous patch and we can use that to wait for a GET response that is at least as current as that resourceVersion.

@kubernetes/sig-api-machinery-pr-reviews @liggitt @wojtek-t
pull/6/head
Kubernetes Submit Queue 2017-03-07 08:11:07 -08:00 committed by GitHub
commit cf1160702b
1 changed files with 19 additions and 0 deletions

View File

@ -28,6 +28,7 @@ import (
"time"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/fields"
"k8s.io/apimachinery/pkg/labels"
@ -285,6 +286,24 @@ func TestPatch(t *testing.T) {
} else {
t.Logf("%v", string(jsonObj))
}
obj, err := result.Get()
if err != nil {
t.Fatal(err)
}
metadata, err := meta.Accessor(obj)
if err != nil {
t.Fatal(err)
}
// this call waits for the resourceVersion to be reached in the cache before returning. We need to do this because
// the patch gets its initial object from the storage, and the cache serves that. If it is out of date,
// then our initial patch is applied to an old resource version, which conflicts and then the updated object shows
// a conflicting diff, which permanently fails the patch. This gives expected stability in the patch without
// retrying on an known number of conflicts below in the test.
if _, err := c.Core().Pods(ns.Name).Get(name, metav1.GetOptions{ResourceVersion: metadata.GetResourceVersion()}); err != nil {
t.Fatal(err)
}
return nil
}