mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-28 14:07:14 +00:00
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:
commit
623b4ef618
@ -130,7 +130,8 @@ func startVolumeServer(client clientset.Interface, config VolumeTestConfig) *v1.
|
|||||||
i++
|
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 := new(bool)
|
||||||
*privileged = true
|
*privileged = true
|
||||||
serverPod := &v1.Pod{
|
serverPod := &v1.Pod{
|
||||||
@ -139,16 +140,16 @@ func startVolumeServer(client clientset.Interface, config VolumeTestConfig) *v1.
|
|||||||
APIVersion: "v1",
|
APIVersion: "v1",
|
||||||
},
|
},
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: config.prefix + "-server",
|
Name: serverPodName,
|
||||||
Labels: map[string]string{
|
Labels: map[string]string{
|
||||||
"role": config.prefix + "-server",
|
"role": serverPodName,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
Spec: v1.PodSpec{
|
Spec: v1.PodSpec{
|
||||||
Containers: []v1.Container{
|
Containers: []v1.Container{
|
||||||
{
|
{
|
||||||
Name: config.prefix + "-server",
|
Name: serverPodName,
|
||||||
Image: config.serverImage,
|
Image: config.serverImage,
|
||||||
SecurityContext: &v1.SecurityContext{
|
SecurityContext: &v1.SecurityContext{
|
||||||
Privileged: privileged,
|
Privileged: privileged,
|
||||||
@ -161,17 +162,31 @@ func startVolumeServer(client clientset.Interface, config VolumeTestConfig) *v1.
|
|||||||
Volumes: volumes,
|
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))
|
framework.ExpectNoError(framework.WaitForPodRunningInNamespace(client, serverPod))
|
||||||
|
|
||||||
By("locating the server pod")
|
if pod == nil {
|
||||||
pod, err := podClient.Get(serverPod.Name, metav1.GetOptions{})
|
By(fmt.Sprintf("locating the %q server pod", serverPodName))
|
||||||
framework.ExpectNoError(err, "Cannot locate the server pod %v: %v", serverPod.Name, err)
|
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
|
return pod
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user