Merge pull request #34357 from bowei/flake-fix-27023

Automatic merge from submit-queue

Add retry loop around check for /etc/hosts contents to work around issue #34256

See https://github.com/kubernetes/kubernetes/issues/34256

fixes #27023
pull/6/head
Kubernetes Submit Queue 2016-10-08 15:11:20 -07:00 committed by GitHub
commit c8668df048
1 changed files with 14 additions and 27 deletions

View File

@ -87,31 +87,25 @@ func (config *KubeletManagedHostConfig) createPodWithHostNetwork() {
func assertManagedStatus(
config *KubeletManagedHostConfig, podName string, expectedIsManaged bool, name string) {
// See https://github.com/kubernetes/kubernetes/issues/27023
// TODO: workaround for https://github.com/kubernetes/kubernetes/issues/34256
//
// Retry until timeout for the right contents of /etc/hosts to show
// up. There may be a low probability race here. We still fail the
// test if retry was necessary, but at least we will know whether or
// not it resolves or seems to be a permanent condition.
//
// If /etc/hosts is properly mounted, then this will succeed
// immediately.
// Retry until timeout for the contents of /etc/hosts to show
// up. Note: if /etc/hosts is properly mounted, then this will
// succeed immediately.
const retryTimeout = 30 * time.Second
retryCount := 0
etcHostsContent := ""
matched := false
for startTime := time.Now(); time.Since(startTime) < retryTimeout; {
etcHostsContent = config.getEtcHostsContent(podName, name)
isManaged := strings.Contains(etcHostsContent, etcHostsPartialContent)
if expectedIsManaged == isManaged {
matched = true
break
return
}
glog.Errorf(
glog.Warningf(
"For pod: %s, name: %s, expected %t, actual %t (/etc/hosts was %q), retryCount: %d",
podName, name, expectedIsManaged, isManaged, etcHostsContent, retryCount)
@ -119,21 +113,14 @@ func assertManagedStatus(
time.Sleep(100 * time.Millisecond)
}
if retryCount > 0 {
if matched {
conditionText := "should"
if !expectedIsManaged {
conditionText = "should not"
}
if expectedIsManaged {
framework.Failf(
"/etc/hosts file %s be kubelet managed (name: %s, retries: %d). /etc/hosts contains %q",
conditionText, name, retryCount, etcHostsContent)
"/etc/hosts file should be kubelet managed (name: %s, retries: %d). /etc/hosts contains %q",
name, retryCount, etcHostsContent)
} else {
framework.Failf(
"had to retry %d times to get matching content in /etc/hosts (name: %s)",
retryCount, name)
}
"/etc/hosts file should no be kubelet managed (name: %s, retries: %d). /etc/hosts contains %q",
name, retryCount, etcHostsContent)
}
}