Add standard UpdatePod function in framework, and change

the test to use it.
This commit is contained in:
Random-Liu
2016-07-05 19:05:53 -07:00
parent 203e1e9663
commit be8c7536ae
3 changed files with 44 additions and 67 deletions

View File

@@ -17,10 +17,14 @@ limitations under the License.
package framework
import (
"fmt"
"sync"
"time"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/errors"
"k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/util/wait"
. "github.com/onsi/gomega"
)
@@ -70,3 +74,26 @@ func (f *Framework) MungePodSpec(pod *api.Pod) {
pod.Spec.NodeName = TestContext.NodeName
}
}
// UpdatePod updates the pod object. It retries if there is a conflict, throw out error if
// there is any other errors. name is the pod name, updateFn is the function updating the
// pod object.
func (f *Framework) UpdatePod(name string, updateFn func(pod *api.Pod)) {
ExpectNoError(wait.Poll(time.Millisecond*500, time.Second*30, func() (bool, error) {
pod, err := f.PodClient().Get(name)
if err != nil {
return false, fmt.Errorf("failed to get pod %q: %v", name, err)
}
updateFn(pod)
_, err = f.PodClient().Update(pod)
if err == nil {
Logf("Successfully updated pod %q", name)
return true, nil
}
if errors.IsConflict(err) {
Logf("Conflicting update to pod %q, re-get and re-update: %v", name, err)
return false, nil
}
return false, fmt.Errorf("failed to update pod %q: %v", name, err)
}))
}