Merge pull request #40320 from jeffvance/e2e-vol-hardening

Automatic merge from submit-queue (batch tested with PRs 40335, 40320, 40324, 39103, 40315)

add some resillency to the new volume-server func

**What this PR does / why we need it**: server-pod `Create` won't fail the test if the server pod already exists.

**Special notes for your reviewer**: Formerly this pr was part of #38214
This commit is contained in:
Kubernetes Submit Queue 2017-01-24 17:30:04 -08:00 committed by GitHub
commit 623b4ef618

View File

@ -130,7 +130,8 @@ func startVolumeServer(client clientset.Interface, config VolumeTestConfig) *v1.
i++
}
By(fmt.Sprint("creating ", config.prefix, " server pod"))
serverPodName := fmt.Sprintf("%s-server", config.prefix)
By(fmt.Sprint("creating ", serverPodName, " pod"))
privileged := new(bool)
*privileged = true
serverPod := &v1.Pod{
@ -139,16 +140,16 @@ func startVolumeServer(client clientset.Interface, config VolumeTestConfig) *v1.
APIVersion: "v1",
},
ObjectMeta: metav1.ObjectMeta{
Name: config.prefix + "-server",
Name: serverPodName,
Labels: map[string]string{
"role": config.prefix + "-server",
"role": serverPodName,
},
},
Spec: v1.PodSpec{
Containers: []v1.Container{
{
Name: config.prefix + "-server",
Name: serverPodName,
Image: config.serverImage,
SecurityContext: &v1.SecurityContext{
Privileged: privileged,
@ -161,17 +162,31 @@ func startVolumeServer(client clientset.Interface, config VolumeTestConfig) *v1.
Volumes: volumes,
},
}
serverPod, err := podClient.Create(serverPod)
framework.ExpectNoError(err, "Failed to create %s pod: %v", serverPod.Name, err)
var pod *v1.Pod
serverPod, err := podClient.Create(serverPod)
// ok if the server pod already exists. TODO: make this controllable by callers
if err != nil {
if apierrs.IsAlreadyExists(err) {
framework.Logf("Ignore \"already-exists\" error, re-get pod...")
By(fmt.Sprintf("re-getting the %q server pod", serverPodName))
serverPod, err = podClient.Get(serverPodName, metav1.GetOptions{})
framework.ExpectNoError(err, "Cannot re-get the server pod %q: %v", serverPodName, err)
pod = serverPod
} else {
framework.ExpectNoError(err, "Failed to create %q pod: %v", serverPodName, err)
}
}
framework.ExpectNoError(framework.WaitForPodRunningInNamespace(client, serverPod))
By("locating the server pod")
pod, err := podClient.Get(serverPod.Name, metav1.GetOptions{})
framework.ExpectNoError(err, "Cannot locate the server pod %v: %v", serverPod.Name, err)
if pod == nil {
By(fmt.Sprintf("locating the %q server pod", serverPodName))
pod, err = podClient.Get(serverPodName, metav1.GetOptions{})
framework.ExpectNoError(err, "Cannot locate the server pod %q: %v", serverPodName, err)
By("sleeping a bit to give the server time to start")
time.Sleep(20 * time.Second)
}
By("sleeping a bit to give the server time to start")
time.Sleep(20 * time.Second)
return pod
}