mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-21 10:51:29 +00:00
Move assertCleanup() to e2e kubectl (#89452)
* Move assertCleanup() to e2e kubectl * Update test/e2e/kubectl/kubectl.go Co-Authored-By: SataQiu <1527062125@qq.com> Co-authored-by: SataQiu <1527062125@qq.com>
This commit is contained in:
parent
d00f9c7c10
commit
68a4b7d621
@ -530,36 +530,6 @@ func RandomSuffix() string {
|
||||
return strconv.Itoa(rand.Intn(10000))
|
||||
}
|
||||
|
||||
// AssertCleanup asserts that cleanup of a namespace wrt selectors occurred.
|
||||
func AssertCleanup(ns string, selectors ...string) {
|
||||
var nsArg string
|
||||
if ns != "" {
|
||||
nsArg = fmt.Sprintf("--namespace=%s", ns)
|
||||
}
|
||||
|
||||
var e error
|
||||
verifyCleanupFunc := func() (bool, error) {
|
||||
e = nil
|
||||
for _, selector := range selectors {
|
||||
resources := RunKubectlOrDie(ns, "get", "rc,svc", "-l", selector, "--no-headers", nsArg)
|
||||
if resources != "" {
|
||||
e = fmt.Errorf("Resources left running after stop:\n%s", resources)
|
||||
return false, nil
|
||||
}
|
||||
pods := RunKubectlOrDie(ns, "get", "pods", "-l", selector, nsArg, "-o", "go-template={{ range .items }}{{ if not .metadata.deletionTimestamp }}{{ .metadata.name }}{{ \"\\n\" }}{{ end }}{{ end }}")
|
||||
if pods != "" {
|
||||
e = fmt.Errorf("Pods left unterminated after stop:\n%s", pods)
|
||||
return false, nil
|
||||
}
|
||||
}
|
||||
return true, nil
|
||||
}
|
||||
err := wait.PollImmediate(500*time.Millisecond, 1*time.Minute, verifyCleanupFunc)
|
||||
if err != nil {
|
||||
Failf(e.Error())
|
||||
}
|
||||
}
|
||||
|
||||
// LookForStringInPodExec looks for the given string in the output of a command
|
||||
// executed in a specific pod container.
|
||||
// TODO(alejandrox1): move to pod/ subpkg once kubectl methods are refactored.
|
||||
|
@ -174,7 +174,37 @@ func cleanupKubectlInputs(fileContents string, ns string, selectors ...string) {
|
||||
// support backward compatibility : file paths or raw json - since we are removing file path
|
||||
// dependencies from this test.
|
||||
framework.RunKubectlOrDieInput(ns, fileContents, "delete", "--grace-period=0", "--force", "-f", "-", nsArg)
|
||||
framework.AssertCleanup(ns, selectors...)
|
||||
assertCleanup(ns, selectors...)
|
||||
}
|
||||
|
||||
// assertCleanup asserts that cleanup of a namespace wrt selectors occurred.
|
||||
func assertCleanup(ns string, selectors ...string) {
|
||||
var nsArg string
|
||||
if ns != "" {
|
||||
nsArg = fmt.Sprintf("--namespace=%s", ns)
|
||||
}
|
||||
|
||||
var e error
|
||||
verifyCleanupFunc := func() (bool, error) {
|
||||
e = nil
|
||||
for _, selector := range selectors {
|
||||
resources := framework.RunKubectlOrDie(ns, "get", "rc,svc", "-l", selector, "--no-headers", nsArg)
|
||||
if resources != "" {
|
||||
e = fmt.Errorf("Resources left running after stop:\n%s", resources)
|
||||
return false, nil
|
||||
}
|
||||
pods := framework.RunKubectlOrDie(ns, "get", "pods", "-l", selector, nsArg, "-o", "go-template={{ range .items }}{{ if not .metadata.deletionTimestamp }}{{ .metadata.name }}{{ \"\\n\" }}{{ end }}{{ end }}")
|
||||
if pods != "" {
|
||||
e = fmt.Errorf("Pods left unterminated after stop:\n%s", pods)
|
||||
return false, nil
|
||||
}
|
||||
}
|
||||
return true, nil
|
||||
}
|
||||
err := wait.PollImmediate(500*time.Millisecond, 1*time.Minute, verifyCleanupFunc)
|
||||
if err != nil {
|
||||
framework.Failf(e.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func readTestFileOrDie(file string) []byte {
|
||||
|
Loading…
Reference in New Issue
Block a user