mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-21 19:01:49 +00:00
Force file sync after writing file via container and wait for pod to
disappear after removal in test
This commit is contained in:
parent
b6c8f4916d
commit
e3d2432e01
@ -481,7 +481,7 @@ func (f *Framework) WriteFileViaContainer(podName, containerName string, path st
|
|||||||
return fmt.Errorf("Unsupported character in string to write: %v", c)
|
return fmt.Errorf("Unsupported character in string to write: %v", c)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
command := fmt.Sprintf("echo '%s' > '%s'", contents, path)
|
command := fmt.Sprintf("echo '%s' > '%s'; sync", contents, path)
|
||||||
stdout, stderr, err := kubectlExecWithRetry(f.Namespace.Name, podName, containerName, "--", "/bin/sh", "-c", command)
|
stdout, stderr, err := kubectlExecWithRetry(f.Namespace.Name, podName, containerName, "--", "/bin/sh", "-c", command)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Logf("error running kubectl exec to write file: %v\nstdout=%v\nstderr=%v)", err, string(stdout), string(stderr))
|
Logf("error running kubectl exec to write file: %v\nstdout=%v\nstderr=%v)", err, string(stdout), string(stderr))
|
||||||
|
@ -33,6 +33,7 @@ import (
|
|||||||
policyv1beta1 "k8s.io/api/policy/v1beta1"
|
policyv1beta1 "k8s.io/api/policy/v1beta1"
|
||||||
"k8s.io/apimachinery/pkg/api/resource"
|
"k8s.io/apimachinery/pkg/api/resource"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
|
"k8s.io/apimachinery/pkg/labels"
|
||||||
"k8s.io/apimachinery/pkg/types"
|
"k8s.io/apimachinery/pkg/types"
|
||||||
"k8s.io/apimachinery/pkg/util/uuid"
|
"k8s.io/apimachinery/pkg/util/uuid"
|
||||||
"k8s.io/apimachinery/pkg/util/wait"
|
"k8s.io/apimachinery/pkg/util/wait"
|
||||||
@ -40,6 +41,7 @@ import (
|
|||||||
v1core "k8s.io/client-go/kubernetes/typed/core/v1"
|
v1core "k8s.io/client-go/kubernetes/typed/core/v1"
|
||||||
"k8s.io/kubernetes/test/e2e/framework"
|
"k8s.io/kubernetes/test/e2e/framework"
|
||||||
e2enode "k8s.io/kubernetes/test/e2e/framework/node"
|
e2enode "k8s.io/kubernetes/test/e2e/framework/node"
|
||||||
|
e2epod "k8s.io/kubernetes/test/e2e/framework/pod"
|
||||||
"k8s.io/kubernetes/test/e2e/framework/providers/gce"
|
"k8s.io/kubernetes/test/e2e/framework/providers/gce"
|
||||||
e2epv "k8s.io/kubernetes/test/e2e/framework/pv"
|
e2epv "k8s.io/kubernetes/test/e2e/framework/pv"
|
||||||
"k8s.io/kubernetes/test/e2e/storage/utils"
|
"k8s.io/kubernetes/test/e2e/storage/utils"
|
||||||
@ -52,7 +54,6 @@ const (
|
|||||||
nodeStatusTimeout = 10 * time.Minute
|
nodeStatusTimeout = 10 * time.Minute
|
||||||
nodeStatusPollTime = 1 * time.Second
|
nodeStatusPollTime = 1 * time.Second
|
||||||
podEvictTimeout = 2 * time.Minute
|
podEvictTimeout = 2 * time.Minute
|
||||||
maxReadRetry = 3
|
|
||||||
minNodes = 2
|
minNodes = 2
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -188,6 +189,8 @@ var _ = utils.SIGDescribe("Pod Disks", func() {
|
|||||||
ginkgo.By("deleting host0Pod") // delete this pod before creating next pod
|
ginkgo.By("deleting host0Pod") // delete this pod before creating next pod
|
||||||
framework.ExpectNoError(podClient.Delete(host0Pod.Name, podDelOpt), "Failed to delete host0Pod")
|
framework.ExpectNoError(podClient.Delete(host0Pod.Name, podDelOpt), "Failed to delete host0Pod")
|
||||||
framework.Logf("deleted host0Pod %q", host0Pod.Name)
|
framework.Logf("deleted host0Pod %q", host0Pod.Name)
|
||||||
|
e2epod.WaitForPodToDisappear(cs, host0Pod.Namespace, host0Pod.Name, labels.Everything(), framework.Poll, framework.PodDeleteTimeout)
|
||||||
|
framework.Logf("deleted host0Pod %q disappeared", host0Pod.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
ginkgo.By("creating host1Pod on node1")
|
ginkgo.By("creating host1Pod on node1")
|
||||||
@ -452,28 +455,13 @@ func countReadyNodes(c clientset.Interface, hostName types.NodeName) int {
|
|||||||
|
|
||||||
func verifyPDContentsViaContainer(f *framework.Framework, podName, containerName string, fileAndContentToVerify map[string]string) {
|
func verifyPDContentsViaContainer(f *framework.Framework, podName, containerName string, fileAndContentToVerify map[string]string) {
|
||||||
for filePath, expectedContents := range fileAndContentToVerify {
|
for filePath, expectedContents := range fileAndContentToVerify {
|
||||||
var value string
|
// No retry loop as there should not be temporal based failures
|
||||||
// Add a retry to avoid temporal failure in reading the content
|
v, err := f.ReadFileViaContainer(podName, containerName, filePath)
|
||||||
for i := 0; i < maxReadRetry; i++ {
|
framework.ExpectNoError(err, "Error reading file %s via container %s", filePath, containerName)
|
||||||
v, err := f.ReadFileViaContainer(podName, containerName, filePath)
|
framework.Logf("Read file %q with content: %v", filePath, v)
|
||||||
value = v
|
if strings.TrimSpace(v) != strings.TrimSpace(expectedContents) {
|
||||||
if err != nil {
|
framework.Failf("Read content <%q> does not match execpted content <%q>.", v, expectedContents)
|
||||||
framework.Logf("Error reading file: %v", err)
|
|
||||||
}
|
|
||||||
framework.ExpectNoError(err)
|
|
||||||
framework.Logf("Read file %q with content: %v (iteration %d)", filePath, v, i)
|
|
||||||
if strings.TrimSpace(v) != strings.TrimSpace(expectedContents) {
|
|
||||||
framework.Logf("Warning: read content <%q> does not match execpted content <%q>.", v, expectedContents)
|
|
||||||
size, err := f.CheckFileSizeViaContainer(podName, containerName, filePath)
|
|
||||||
if err != nil {
|
|
||||||
framework.Logf("Error checking file size: %v", err)
|
|
||||||
}
|
|
||||||
framework.Logf("Check file %q size: %q", filePath, size)
|
|
||||||
} else {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
framework.ExpectEqual(strings.TrimSpace(value), strings.TrimSpace(expectedContents))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user