mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-28 14:07:14 +00:00
Add retry to AssertCleanup
This commit is contained in:
parent
b651ed5ea7
commit
eeda67232c
@ -2066,16 +2066,33 @@ func AssertCleanup(ns string, selectors ...string) {
|
|||||||
if ns != "" {
|
if ns != "" {
|
||||||
nsArg = fmt.Sprintf("--namespace=%s", ns)
|
nsArg = fmt.Sprintf("--namespace=%s", ns)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
backoff := wait.Backoff{
|
||||||
|
Duration: 5 * time.Second,
|
||||||
|
Factor: 2,
|
||||||
|
Steps: 3,
|
||||||
|
}
|
||||||
|
var e error
|
||||||
|
verifyCleanupFunc := func() (bool, error) {
|
||||||
|
e = nil
|
||||||
for _, selector := range selectors {
|
for _, selector := range selectors {
|
||||||
resources := RunKubectlOrDie("get", "rc,svc", "-l", selector, "--no-headers", nsArg)
|
resources := RunKubectlOrDie("get", "rc,svc", "-l", selector, "--no-headers", nsArg)
|
||||||
if resources != "" {
|
if resources != "" {
|
||||||
Failf("Resources left running after stop:\n%s", resources)
|
e = fmt.Errorf("Resources left running after stop:\n%s", resources)
|
||||||
|
return false, nil
|
||||||
}
|
}
|
||||||
pods := RunKubectlOrDie("get", "pods", "-l", selector, nsArg, "-o", "go-template={{ range .items }}{{ if not .metadata.deletionTimestamp }}{{ .metadata.name }}{{ \"\\n\" }}{{ end }}{{ end }}")
|
pods := RunKubectlOrDie("get", "pods", "-l", selector, nsArg, "-o", "go-template={{ range .items }}{{ if not .metadata.deletionTimestamp }}{{ .metadata.name }}{{ \"\\n\" }}{{ end }}{{ end }}")
|
||||||
if pods != "" {
|
if pods != "" {
|
||||||
Failf("Pods left unterminated after stop:\n%s", pods)
|
e = fmt.Errorf("Pods left unterminated after stop:\n%s", pods)
|
||||||
|
return false, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
err := wait.ExponentialBackoff(backoff, verifyCleanupFunc)
|
||||||
|
if err != nil {
|
||||||
|
Failf(e.Error())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// KubectlCmd runs the kubectl executable through the wrapper script.
|
// KubectlCmd runs the kubectl executable through the wrapper script.
|
||||||
|
Loading…
Reference in New Issue
Block a user