mirror of
https://github.com/k3s-io/k3s.git
synced 2024-06-07 19:41:36 +00:00
Containerd restart testlet (#6696)
* Add containerd testlet to startup integration * Fix all log dumps * Stop server gracefully Signed-off-by: Derek Nola <derek.nola@suse.com>
This commit is contained in:
parent
d78e490716
commit
674a05478f
@ -77,10 +77,15 @@ var _ = Describe("certificate rotation", Ordered, func() {
|
||||
})
|
||||
})
|
||||
|
||||
var failed bool
|
||||
var _ = AfterEach(func() {
|
||||
failed = failed || CurrentSpecReport().Failed()
|
||||
})
|
||||
|
||||
var _ = AfterSuite(func() {
|
||||
if !testutil.IsExistingServer() {
|
||||
if CurrentSpecReport().Failed() {
|
||||
testutil.K3sDumpLog(server)
|
||||
if failed {
|
||||
testutil.K3sSaveLog(server, false)
|
||||
}
|
||||
Expect(testutil.K3sKillServer(server)).To(Succeed())
|
||||
Expect(testutil.K3sCleanup(-1, "")).To(Succeed())
|
||||
|
@ -52,10 +52,15 @@ var _ = Describe("custom etcd args", Ordered, func() {
|
||||
})
|
||||
})
|
||||
|
||||
var failed bool
|
||||
var _ = AfterEach(func() {
|
||||
failed = failed || CurrentSpecReport().Failed()
|
||||
})
|
||||
|
||||
var _ = AfterSuite(func() {
|
||||
if !testutil.IsExistingServer() {
|
||||
if CurrentSpecReport().Failed() {
|
||||
testutil.K3sDumpLog(customEtcdArgsServer)
|
||||
if failed {
|
||||
testutil.K3sSaveLog(customEtcdArgsServer, false)
|
||||
}
|
||||
Expect(testutil.K3sKillServer(customEtcdArgsServer)).To(Succeed())
|
||||
Expect(testutil.K3sCleanup(testLock, "")).To(Succeed())
|
||||
|
@ -53,10 +53,15 @@ var _ = Describe("dual stack", Ordered, func() {
|
||||
})
|
||||
})
|
||||
|
||||
var failed bool
|
||||
var _ = AfterEach(func() {
|
||||
failed = failed || CurrentSpecReport().Failed()
|
||||
})
|
||||
|
||||
var _ = AfterSuite(func() {
|
||||
if !testutil.IsExistingServer() && os.Getenv("CI") != "true" {
|
||||
if CurrentSpecReport().Failed() {
|
||||
testutil.K3sDumpLog(dualStackServer)
|
||||
if failed {
|
||||
testutil.K3sSaveLog(dualStackServer, false)
|
||||
}
|
||||
Expect(testutil.K3sKillServer(dualStackServer)).To(Succeed())
|
||||
Expect(testutil.K3sCleanup(testLock, "")).To(Succeed())
|
||||
|
@ -106,10 +106,15 @@ var _ = Describe("etcd snapshot restore", Ordered, func() {
|
||||
})
|
||||
})
|
||||
|
||||
var failed bool
|
||||
var _ = AfterEach(func() {
|
||||
failed = failed || CurrentSpecReport().Failed()
|
||||
})
|
||||
|
||||
var _ = AfterSuite(func() {
|
||||
if !testutil.IsExistingServer() {
|
||||
if CurrentSpecReport().Failed() {
|
||||
testutil.K3sDumpLog(server1)
|
||||
if failed {
|
||||
testutil.K3sSaveLog(server1, false)
|
||||
}
|
||||
Expect(testutil.K3sKillServer(server1)).To(Succeed())
|
||||
Expect(testutil.K3sKillServer(server2)).To(Succeed())
|
||||
|
@ -113,10 +113,15 @@ var _ = Describe("etcd snapshots", Ordered, func() {
|
||||
})
|
||||
})
|
||||
|
||||
var failed bool
|
||||
var _ = AfterEach(func() {
|
||||
failed = failed || CurrentSpecReport().Failed()
|
||||
})
|
||||
|
||||
var _ = AfterSuite(func() {
|
||||
if !testutil.IsExistingServer() {
|
||||
if CurrentSpecReport().Failed() {
|
||||
testutil.K3sDumpLog(server)
|
||||
if failed {
|
||||
testutil.K3sSaveLog(server, false)
|
||||
}
|
||||
Expect(testutil.K3sKillServer(server)).To(Succeed())
|
||||
Expect(testutil.K3sCleanup(testLock, "")).To(Succeed())
|
||||
|
@ -229,7 +229,23 @@ func K3sStartServer(inputArgs ...string) (*K3sServer, error) {
|
||||
return &K3sServer{cmd, f}, err
|
||||
}
|
||||
|
||||
// K3sKillServer terminates the running K3s server and its children
|
||||
// K3sStopServer gracefully stops the running K3s server and does not kill its children.
|
||||
// Equivalent to stopping the K3s service
|
||||
func K3sStopServer(server *K3sServer) error {
|
||||
if server.log != nil {
|
||||
server.log.Close()
|
||||
}
|
||||
if err := server.cmd.Process.Kill(); err != nil {
|
||||
return errors.Wrap(err, "failed to kill k3s process")
|
||||
}
|
||||
if _, err := server.cmd.Process.Wait(); err != nil {
|
||||
return errors.Wrap(err, "failed to wait for k3s process exit")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// K3sKillServer terminates the running K3s server and its children.
|
||||
// Equivalent to k3s-killall.sh
|
||||
func K3sKillServer(server *K3sServer) error {
|
||||
if server.log != nil {
|
||||
server.log.Close()
|
||||
@ -292,8 +308,11 @@ func K3sCleanup(k3sTestLock int, dataDir string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func K3sDumpLog(server *K3sServer) error {
|
||||
func K3sSaveLog(server *K3sServer, dump bool) error {
|
||||
server.log.Close()
|
||||
if !dump {
|
||||
return nil
|
||||
}
|
||||
log, err := os.Open(server.log.Name())
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -82,10 +82,15 @@ var _ = Describe("local storage", func() {
|
||||
})
|
||||
})
|
||||
|
||||
var failed bool
|
||||
var _ = AfterEach(func() {
|
||||
failed = failed || CurrentSpecReport().Failed()
|
||||
})
|
||||
|
||||
var _ = AfterSuite(func() {
|
||||
if !testutil.IsExistingServer() {
|
||||
if CurrentSpecReport().Failed() {
|
||||
testutil.K3sDumpLog(localStorageServer)
|
||||
if failed {
|
||||
testutil.K3sSaveLog(localStorageServer, false)
|
||||
}
|
||||
Expect(testutil.K3sKillServer(localStorageServer)).To(Succeed())
|
||||
Expect(testutil.K3sCleanup(testLock, "")).To(Succeed())
|
||||
|
@ -141,10 +141,15 @@ var _ = Describe("secrets encryption rotation", Ordered, func() {
|
||||
})
|
||||
})
|
||||
|
||||
var failed bool
|
||||
var _ = AfterEach(func() {
|
||||
failed = failed || CurrentSpecReport().Failed()
|
||||
})
|
||||
|
||||
var _ = AfterSuite(func() {
|
||||
if !testutil.IsExistingServer() {
|
||||
if CurrentSpecReport().Failed() {
|
||||
testutil.K3sDumpLog(secretsEncryptionServer)
|
||||
if failed {
|
||||
testutil.K3sSaveLog(secretsEncryptionServer, false)
|
||||
}
|
||||
Expect(testutil.K3sKillServer(secretsEncryptionServer)).To(Succeed())
|
||||
Expect(testutil.K3sCleanup(testLock, secretsEncryptionDataDir)).To(Succeed())
|
||||
|
@ -208,12 +208,60 @@ var _ = Describe("startup tests", Ordered, func() {
|
||||
Expect(testutil.K3sCleanup(-1, "")).To(Succeed())
|
||||
})
|
||||
})
|
||||
// Check for regression of containerd restarting pods
|
||||
// https://github.com/containerd/containerd/issues/7843
|
||||
When("a server with a dummy pod", func() {
|
||||
It("is created with no arguments", func() {
|
||||
var err error
|
||||
startupServer, err = testutil.K3sStartServer(startupServerArgs...)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
})
|
||||
It("has the default pods deployed", func() {
|
||||
Eventually(func() error {
|
||||
return testutil.K3sDefaultDeployments()
|
||||
}, "120s", "5s").Should(Succeed())
|
||||
})
|
||||
It("creates a new pod", func() {
|
||||
Expect(testutil.K3sCmd("kubectl apply -f ./testdata/dummy.yaml")).
|
||||
To(ContainSubstring("pod/dummy created"))
|
||||
Eventually(func() (string, error) {
|
||||
return testutil.K3sCmd("kubectl get event -n kube-system --field-selector involvedObject.name=dummy")
|
||||
}, "60s", "5s").Should(ContainSubstring("Started container dummy"))
|
||||
})
|
||||
It("restarts the server", func() {
|
||||
var err error
|
||||
Expect(testutil.K3sStopServer(startupServer)).To(Succeed())
|
||||
startupServer, err = testutil.K3sStartServer(startupServerArgs...)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Eventually(func() error {
|
||||
return testutil.K3sDefaultDeployments()
|
||||
}, "180s", "5s").Should(Succeed())
|
||||
})
|
||||
It("has the dummy pod not restarted", func() {
|
||||
Consistently(func(g Gomega) {
|
||||
res, err := testutil.K3sCmd("kubectl get event -n kube-system --field-selector involvedObject.name=dummy")
|
||||
g.Expect(err).ToNot(HaveOccurred())
|
||||
g.Expect(res).NotTo(ContainSubstring("Pod sandbox changed, it will be killed and re-created"))
|
||||
g.Expect(res).NotTo(ContainSubstring("Stopping container dummy"))
|
||||
}, "30s", "5s").Should(Succeed())
|
||||
})
|
||||
It("dies cleanly", func() {
|
||||
Expect(testutil.K3sKillServer(startupServer)).To(Succeed())
|
||||
Expect(testutil.K3sCleanup(-1, "")).To(Succeed())
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
var failed bool
|
||||
var _ = AfterEach(func() {
|
||||
failed = failed || CurrentSpecReport().Failed()
|
||||
})
|
||||
|
||||
var _ = AfterSuite(func() {
|
||||
if !testutil.IsExistingServer() {
|
||||
if CurrentSpecReport().Failed() {
|
||||
testutil.K3sDumpLog(startupServer)
|
||||
if failed {
|
||||
testutil.K3sSaveLog(startupServer, false)
|
||||
Expect(testutil.K3sKillServer(startupServer)).To(Succeed())
|
||||
}
|
||||
Expect(testutil.K3sCleanup(testLock, "")).To(Succeed())
|
||||
}
|
||||
|
11
tests/integration/startup/testdata/dummy.yaml
vendored
Normal file
11
tests/integration/startup/testdata/dummy.yaml
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Pod
|
||||
metadata:
|
||||
name: dummy
|
||||
namespace: kube-system
|
||||
spec:
|
||||
containers:
|
||||
- name: dummy
|
||||
image: ranchertest/mytestcontainer
|
||||
imagePullPolicy: IfNotPresent
|
Loading…
Reference in New Issue
Block a user