Skip to content

Commit

Permalink
Add a smoke-test for non-root login user
Browse files Browse the repository at this point in the history
Signed-off-by: Kimmo Lehto <[email protected]>
  • Loading branch information
kke committed May 10, 2024
1 parent d8af765 commit 0f6d5f9
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 2 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/smoke.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,35 @@ jobs:
LINUX_IMAGE: ${{ matrix.image }}
run: make smoke-basic

smoke-basic-rootless:
strategy:
matrix:
image:
- quay.io/k0sproject/bootloose-debian12
- quay.io/k0sproject/bootloose-ubuntu20.04
name: Basic 1+1 smoke (regular user login)
needs: build
runs-on: ubuntu-20.04

steps:

- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
check-latest: true

- {"name":"Compiled binary cache","uses":"actions/download-artifact@v4","with":{"name":"k0sctl","path":"."}}
- {"name":"K0sctl cache","uses":"actions/cache@v3","with":{"path":"/var/cache/k0sctl/k0s\n~/.cache/k0sctl/k0s\n","key":"k0sctl-cache"}}
- {"name":"Kubectl cache","uses":"actions/cache@v3","with":{"path":"smoke-test/kubectl\n","key":"kubectl-${{ hashFiles('smoke-test/smoke.common.sh') }}","restore-keys":"kubectl-"}}
- {"name":"Make binaries executable","run":"chmod +x k0sctl || true\nchmod +x smoke-test/kubectl || true"}

- name: Run smoke tests
env:
LINUX_IMAGE: ${{ matrix.image }}
run: make smoke-basic-rootless

smoke-basic-idlike:
name: Basic 1+1 smoke (ID_LIKE fallback)
needs: build
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ build-all: $(addprefix bin/,$(bins)) bin/checksums.md
clean:
rm -rf bin/ k0sctl

smoketests := smoke-basic smoke-files smoke-upgrade smoke-reset smoke-os-override smoke-init smoke-backup-restore smoke-dynamic smoke-basic-openssh smoke-dryrun smoke-downloadurl
smoketests := smoke-basic smoke-basic-rootless smoke-files smoke-upgrade smoke-reset smoke-os-override smoke-init smoke-backup-restore smoke-dynamic smoke-basic-openssh smoke-dryrun smoke-downloadurl
.PHONY: $(smoketests)
$(smoketests): k0sctl
$(MAKE) -C smoke-test $@
Expand Down
3 changes: 3 additions & 0 deletions smoke-test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ id_rsa_k0s:
smoke-basic: $(bootloose) id_rsa_k0s k0sctl
./smoke-basic.sh

smoke-basic-rootless: $(bootloose) id_rsa_k0s k0sctl
./smoke-basic-rootless.sh

smoke-basic-openssh: $(bootloose) id_rsa_k0s k0sctl
./smoke-basic-openssh.sh

Expand Down
4 changes: 3 additions & 1 deletion smoke-test/k0sctl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ spec:
address: "127.0.0.1"
port: 9022
keyPath: ./id_rsa_k0s
user: ${SSH_USER}
hooks:
apply:
before:
Expand All @@ -22,9 +23,10 @@ spec:
address: "127.0.0.1"
port: 9023
keyPath: ./id_rsa_k0s
user: ${SSH_USER}
k0s:
version: "${K0S_VERSION}"
config:
spec:
telemetry:
enabled: false
enabled: false
53 changes: 53 additions & 0 deletions smoke-test/smoke-basic-rootless.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/env sh

K0SCTL_CONFIG=${K0SCTL_CONFIG:-"k0sctl.yaml"}
SSH_USER=${SSH_USER:-"k0sctl-user"}

set -e


. ./smoke.common.sh
trap cleanup EXIT

deleteCluster
createCluster

for host in manager0 worker0; do
echo "* Creating ${SSH_USER} on ${host}"
bootloose ssh "root@${host}" -- groupadd --system k0sctl-admin
bootloose ssh "root@${host}" -- useradd -m -G k0sctl-admin -p '*' "${SSH_USER}"
bootloose ssh "root@${host}" -- echo "'%k0sctl-admin ALL=(ALL)NOPASSWD:ALL'" '>/etc/sudoers.d/k0sctl-admin'
bootloose ssh "root@${host}" -- chmod 0440 /etc/sudoers.d/k0sctl-admin
bootloose ssh "root@${host}" -- mkdir -p "/home/${SSH_USER}/.ssh"
bootloose ssh "root@${host}" -- cp '/root/.ssh/*' "/home/${SSH_USER}/.ssh/"
bootloose ssh "root@${host}" -- chown -R "${SSH_USER}:${SSH_USER}" "/home/${SSH_USER}/.ssh"
done

echo "* Starting apply"
../k0sctl apply --config "${K0SCTL_CONFIG}" --kubeconfig-out applykubeconfig --debug
echo "* Apply OK"

echo "* Verify hooks were executed on the host"
bootloose ssh root@manager0 -- grep -q hello apply.hook

echo "* Verify 'k0sctl kubeconfig' output includes 'data' block"
../k0sctl kubeconfig --config k0sctl.yaml | grep -v -- "-data"

echo "* Run kubectl on controller"
bootloose ssh root@manager0 -- k0s kubectl get nodes

echo "* Downloading kubectl for local test"
downloadKubectl

echo "* Using the kubectl from apply"
./kubectl --kubeconfig applykubeconfig get nodes

echo "* Using k0sctl kubecofig locally"
../k0sctl kubeconfig --config k0sctl.yaml > kubeconfig

echo "* Output:"
grep -v -- -data kubeconfig

echo "* Running kubectl"
./kubectl --kubeconfig kubeconfig get nodes
echo "* Done"

0 comments on commit 0f6d5f9

Please sign in to comment.