-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a smoke-test for controller swap
Signed-off-by: Kimmo Lehto <[email protected]>
- Loading branch information
Showing
6 changed files
with
143 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
cluster: | ||
name: k0s | ||
privateKey: ./id_rsa_k0s | ||
machines: | ||
- count: 3 | ||
backend: docker | ||
spec: | ||
image: $LINUX_IMAGE | ||
name: manager%d | ||
privileged: true | ||
volumes: | ||
- type: bind | ||
source: /lib/modules | ||
destination: /lib/modules | ||
- type: volume | ||
destination: /var/lib/k0s | ||
portMappings: | ||
- containerPort: 22 | ||
hostPort: 9022 | ||
- containerPort: 443 | ||
hostPort: 443 | ||
- containerPort: 6443 | ||
hostPort: 6443 |
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,29 @@ | ||
apiVersion: k0sctl.k0sproject.io/v1beta1 | ||
kind: cluster | ||
spec: | ||
hosts: | ||
- role: controller | ||
uploadBinary: true | ||
ssh: | ||
address: "127.0.0.1" | ||
port: 9022 | ||
keyPath: ./id_rsa_k0s | ||
- role: controller | ||
uploadBinary: true | ||
ssh: | ||
address: "127.0.0.1" | ||
port: 9023 | ||
keyPath: ./id_rsa_k0s | ||
- role: controller | ||
uploadBinary: true | ||
ssh: | ||
address: "127.0.0.1" | ||
port: 9024 | ||
keyPath: ./id_rsa_k0s | ||
k0s: | ||
version: "${K0S_VERSION}" | ||
config: | ||
spec: | ||
telemetry: | ||
enabled: false | ||
|
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,59 @@ | ||
#!/usr/bin/env sh | ||
|
||
K0SCTL_CONFIG=${K0SCTL_CONFIG:-"k0sctl-controller-swap.yaml"} | ||
|
||
set -ex | ||
|
||
|
||
. ./smoke.common.sh | ||
trap cleanup EXIT | ||
|
||
deleteCluster | ||
createCluster | ||
|
||
echo "* Starting apply" | ||
../k0sctl apply --config "${K0SCTL_CONFIG}" --debug | ||
echo "* Apply OK" | ||
|
||
echo "* Get the ip of the last controller" | ||
controllerip=$(bootloose show manager2 -o json | grep '"ip"' | head -1 | cut -d'"' -f4) | ||
|
||
echo "* Wipe controller 3" | ||
docker rm -fv "$(bootloose show manager2 -o json | grep '"container"' | head -1 | cut -d'"' -f4)" | ||
|
||
echo "* Verify its gone" | ||
bootloose show manager2 | grep "Not created" | ||
|
||
echo "* Recreate controller2" | ||
createCluster | ||
|
||
echo "* Verify its back and IP is the same" | ||
bootloose show manager2 | grep "Running" | ||
newip=$(bootloose show manager2 -o json | grep '"ip"' | head -1 | cut -d'"' -f4) | ||
if [ "$controllerip" != "$newip" ]; then | ||
echo "IP mismatch: $controllerip != $newip - ip should get reused" | ||
exit 1 | ||
fi | ||
|
||
echo "* Re-apply should fail because of known hosts" | ||
if ../k0sctl apply --config "${K0SCTL_CONFIG}" --debug; then | ||
echo "Re-apply should have failed because of known hosts" | ||
exit 1 | ||
fi | ||
|
||
echo "* Clear known hosts" | ||
truncate -s 0 ~/.ssh/known_hosts | ||
|
||
echo "* Re-apply should fail because of replaced controller" | ||
if ../k0sctl apply --config "${K0SCTL_CONFIG}" --debug; then | ||
echo "Re-apply should have failed because of replaced controller" | ||
exit 1 | ||
fi | ||
|
||
echo "* Perform etcd member removal" | ||
bootloose ssh root@manager0 -- k0s etcd leave --peer-address "$controllerip" | ||
|
||
echo "* Re-apply should succeed" | ||
../k0sctl apply --config "${K0SCTL_CONFIG}" --debug | ||
|
||
echo "* Done" |