-
Notifications
You must be signed in to change notification settings - Fork 372
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add integration tests around k0s reset
Have a "full-fledged" integration test called reset which should cover all aspects of k0s reset for the default CRI. Also add a check to byocri to verify that k0s reset terminates the Docker containers. Signed-off-by: Tom Wieczorek <[email protected]> (cherry picked from commit 9237a87)
- Loading branch information
1 parent
5c35f5d
commit 1964179
Showing
7 changed files
with
185 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
Copyright 2024 k0s authors | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package reset | ||
|
||
import ( | ||
"testing" | ||
|
||
testifysuite "github.com/stretchr/testify/suite" | ||
|
||
"github.com/k0sproject/k0s/inttest/common" | ||
) | ||
|
||
type suite struct { | ||
common.BootlooseSuite | ||
} | ||
|
||
func (s *suite) TestReset() { | ||
ctx := s.Context() | ||
workerNode := s.WorkerNode(0) | ||
|
||
if ok := s.Run("k0s gets up", func() { | ||
s.Require().NoError(s.InitController(0, "--disable-components=konnectivity-server,metrics-server")) | ||
s.Require().NoError(s.RunWorkers()) | ||
|
||
kc, err := s.KubeClient(s.ControllerNode(0)) | ||
s.Require().NoError(err) | ||
|
||
err = s.WaitForNodeReady(workerNode, kc) | ||
s.NoError(err) | ||
|
||
s.T().Log("waiting to see CNI pods ready") | ||
s.NoError(common.WaitForKubeRouterReady(ctx, kc), "CNI did not start") | ||
}); !ok { | ||
return | ||
} | ||
|
||
s.Run("k0s reset", func() { | ||
ssh, err := s.SSH(ctx, workerNode) | ||
s.Require().NoError(err) | ||
defer ssh.Disconnect() | ||
|
||
s.NoError(ssh.Exec(ctx, "test -d /var/lib/k0s", common.SSHStreams{}), "/var/lib/k0s is not a directory") | ||
s.NoError(ssh.Exec(ctx, "test -d /run/k0s", common.SSHStreams{}), "/run/k0s is not a directory") | ||
|
||
s.NoError(ssh.Exec(ctx, "pidof containerd-shim-runc-v2 >&2", common.SSHStreams{}), "Expected some running containerd shims") | ||
|
||
s.NoError(s.StopWorker(workerNode), "Failed to stop k0s") | ||
|
||
streams, flushStreams := common.TestLogStreams(s.T(), "reset") | ||
err = ssh.Exec(ctx, "k0s reset --debug", streams) | ||
flushStreams() | ||
s.NoError(err, "k0s reset didn't exit cleanly") | ||
|
||
// /var/lib/k0s is a mount point in the Docker container and can't be deleted, so it must be empty | ||
s.NoError(ssh.Exec(ctx, `x="$(ls -A /var/lib/k0s)" && echo "$x" >&2 && [ -z "$x" ]`, common.SSHStreams{}), "/var/lib/k0s is not empty") | ||
s.NoError(ssh.Exec(ctx, "! test -e /run/k0s", common.SSHStreams{}), "/run/k0s still exists") | ||
s.NoError(ssh.Exec(ctx, "! pidof containerd-shim-runc-v2 >&2", common.SSHStreams{}), "Expected no running containerd shims") | ||
}) | ||
} | ||
|
||
func TestResetSuite(t *testing.T) { | ||
testifysuite.Run(t, &suite{ | ||
common.BootlooseSuite{ | ||
ControllerCount: 1, | ||
WorkerCount: 1, | ||
}, | ||
}) | ||
} |