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