1+ # SPDX-FileCopyrightText: Copyright The Lima Authors
2+ # SPDX-License-Identifier: Apache-2.0
3+
4+ # This test verifies that a Kubernetes cluster can be started and that the single node is ready.
5+
6+ load " ../helpers/load"
7+
8+ : " ${TEMPLATE:= k8s} "
9+
10+ # Instance names are "${NAME}-0", "${NAME}-1", ...
11+ NAME=" k8s"
12+
13+ get_num_nodes () {
14+ local nodes=0
15+ for tag in " ${BATS_TEST_TAGS[@]} " ; do
16+ if [[ $tag =~ ^nodes:([0-9]+)$ ]]; then
17+ nodes=" ${BASH_REMATCH[1]} "
18+ fi
19+ done
20+ if [[ $nodes -eq 0 ]]; then
21+ echo >&2 " nodes:N tag is required"
22+ exit 1
23+ fi
24+ echo " $nodes "
25+ }
26+
27+ local_setup () {
28+ local nodes=$( get_num_nodes)
29+ for (( i= 0 ; i< nodes; i++ )) ; do
30+ limactl delete --force " ${NAME} -$i " || :
31+ limactl start --tty=false --name " ${NAME} -$i " " template:${TEMPLATE} " 3>& - 4>& -
32+ # NOTE: No support for multi-node clusters yet.
33+ done
34+ for node in $( k get node -o name) ; do
35+ k wait --timeout=5m --for=condition=ready " ${node} "
36+ done
37+ }
38+
39+ local_teardown () {
40+ local nodes=$( get_num_nodes)
41+ for (( i= 0 ; i< nodes; i++ )) ; do
42+ limactl delete --force " ${NAME} -$i " || :
43+ done
44+ }
45+
46+ k () {
47+ # The host home directory is not mounted in the case of k8s.
48+ limactl shell --workdir=/ " ${NAME} -0" -- kubectl " $@ "
49+ }
50+
51+ # bats test_tags=nodes:1
52+ @test ' Single-node' {
53+ k create deployment nginx --image=" ${TEST_CONTAINER_IMAGES["nginx"]} "
54+ k rollout status deployment nginx --timeout 60s
55+ k create service nodeport nginx --node-port=31080 --tcp=80:80
56+ run curl --fail --silent --show-error --retry 30 --retry-all-errors http://localhost:31080
57+ assert_success
58+ assert_output --partial " Welcome to nginx"
59+ # TODO: support UDP
60+ k delete service nginx
61+ k delete deployment nginx
62+ }
63+
64+ # TODO: add a test for multi-node
0 commit comments