mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-03 19:58:17 +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:
		@@ -481,7 +481,7 @@ func (f *Framework) WriteFileViaContainer(podName, containerName string, path st
 | 
			
		||||
			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)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		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"
 | 
			
		||||
	"k8s.io/apimachinery/pkg/api/resource"
 | 
			
		||||
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
 | 
			
		||||
	"k8s.io/apimachinery/pkg/labels"
 | 
			
		||||
	"k8s.io/apimachinery/pkg/types"
 | 
			
		||||
	"k8s.io/apimachinery/pkg/util/uuid"
 | 
			
		||||
	"k8s.io/apimachinery/pkg/util/wait"
 | 
			
		||||
@@ -40,6 +41,7 @@ import (
 | 
			
		||||
	v1core "k8s.io/client-go/kubernetes/typed/core/v1"
 | 
			
		||||
	"k8s.io/kubernetes/test/e2e/framework"
 | 
			
		||||
	e2enode "k8s.io/kubernetes/test/e2e/framework/node"
 | 
			
		||||
	e2epod "k8s.io/kubernetes/test/e2e/framework/pod"
 | 
			
		||||
	"k8s.io/kubernetes/test/e2e/framework/providers/gce"
 | 
			
		||||
	e2epv "k8s.io/kubernetes/test/e2e/framework/pv"
 | 
			
		||||
	"k8s.io/kubernetes/test/e2e/storage/utils"
 | 
			
		||||
@@ -52,7 +54,6 @@ const (
 | 
			
		||||
	nodeStatusTimeout   = 10 * time.Minute
 | 
			
		||||
	nodeStatusPollTime  = 1 * time.Second
 | 
			
		||||
	podEvictTimeout     = 2 * time.Minute
 | 
			
		||||
	maxReadRetry        = 3
 | 
			
		||||
	minNodes            = 2
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
@@ -188,6 +189,8 @@ var _ = utils.SIGDescribe("Pod Disks", func() {
 | 
			
		||||
					ginkgo.By("deleting host0Pod") // delete this pod before creating next pod
 | 
			
		||||
					framework.ExpectNoError(podClient.Delete(host0Pod.Name, podDelOpt), "Failed to delete host0Pod")
 | 
			
		||||
					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")
 | 
			
		||||
@@ -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) {
 | 
			
		||||
	for filePath, expectedContents := range fileAndContentToVerify {
 | 
			
		||||
		var value string
 | 
			
		||||
		// Add a retry to avoid temporal failure in reading the content
 | 
			
		||||
		for i := 0; i < maxReadRetry; i++ {
 | 
			
		||||
		// No retry loop as there should not be temporal based failures
 | 
			
		||||
		v, err := f.ReadFileViaContainer(podName, containerName, filePath)
 | 
			
		||||
			value = v
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				framework.Logf("Error reading file: %v", err)
 | 
			
		||||
			}
 | 
			
		||||
			framework.ExpectNoError(err)
 | 
			
		||||
			framework.Logf("Read file %q with content: %v (iteration %d)", filePath, v, i)
 | 
			
		||||
		framework.ExpectNoError(err, "Error reading file %s via container %s", filePath, containerName)
 | 
			
		||||
		framework.Logf("Read file %q with content: %v", filePath, v)
 | 
			
		||||
		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.Failf("Read content <%q> does not match execpted content <%q>.", v, expectedContents)
 | 
			
		||||
		}
 | 
			
		||||
				framework.Logf("Check file %q size: %q", filePath, size)
 | 
			
		||||
			} else {
 | 
			
		||||
				break
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		framework.ExpectEqual(strings.TrimSpace(value), strings.TrimSpace(expectedContents))
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user