kata-containers/tests/integration/kubernetes/k8s-exec.bats
Fabiano Fidêncio 11e0099fb5 tests: Move k8s tests to this repo
The first part of simplifying things to have all our tests using GitHub
actions is moving the k8s tests to this repo, as those will be the first
vict^W targets to be migrated to GitHub actions.

Those tests have been slightly adapted, mainly related to what they load
/ import, so they are more self-contained and do not require us bringing
a lot of scripts from the tests repo here.

A few scripts were also dropped along the way, as we no longer plan to
deploy kubernetes as part of every single run, but rather assume there
will always be k8s running whenever we land to run those tests.

It's important to mention that a few tests were not added here:

* k8s-block-volume:
* k8s-file-volume:
* k8s-volume:
* k8s-ro-volume:
  These tests depend on some sort of volume being created on the
  kubernetes node where the test will run, and this won't fly as the
  tests will run from a GitHub runner, targetting a different machine
  where kubernetes will be running.
  * https://github.com/kata-containers/kata-containers/issues/6566

* k8s-hugepages: This test depends a whole lot on the host where it
  lands and right now we cannot assume anything about that anymore, as
  the tests will run from a GitHub runner, targetting a different
  machine where kubernetes will be running.
  * https://github.com/kata-containers/kata-containers/issues/6567

* k8s-expose-ip: This is simply hanging when running on AKS and has to
  be debugged in order to figure out the root cause of that, and then
  adapted to also work on AKS.
  * https://github.com/kata-containers/kata-containers/issues/6578

Till those issues are solved, we'll keep running a jenkins job with
hose tests to avoid any possible regression.

Last but not least, I've decided to **not** keep the history when
bringing those tests here, otherwise we'd end up polluting a lot the
history of this repo, without any clear benefit on doing so.

Signed-off-by: Fabiano Fidêncio <fabiano.fidencio@intel.com>
2023-03-31 21:55:41 +02:00

66 lines
1.6 KiB
Bash

#!/usr/bin/env bats
#
# Copyright (c) 2020 Ant Financial
#
# SPDX-License-Identifier: Apache-2.0
#
load "${BATS_TEST_DIRNAME}/../../common.bash"
load "${BATS_TEST_DIRNAME}/tests_common.sh"
setup() {
get_pod_config_dir
pod_name="busybox"
first_container_name="first-test-container"
second_container_name="second-test-container"
}
@test "Kubectl exec" {
# Create the pod
kubectl create -f "${pod_config_dir}/busybox-pod.yaml"
# Get pod specification
kubectl wait --for=condition=Ready --timeout=$timeout pod "$pod_name"
# Run commands in Pod
## Cases for -it options
# TODO: enable -i option after updated to new CRI-O
# see: https://github.com/kata-containers/tests/issues/2770
# kubectl exec -i "$pod_name" -- ls -tl /
# kubectl exec -it "$pod_name" -- ls -tl /
kubectl exec "$pod_name" -- date
## Case for stdin
kubectl exec -i "$pod_name" -- sh <<-EOF
echo abc > /tmp/abc.txt
grep abc /tmp/abc.txt
exit
EOF
## Case for return value
### Command return non-zero code
run bash -c "kubectl exec -i $pod_name -- sh <<-EOF
exit 123
EOF"
echo "run status: $status" 1>&2
echo "run output: $output" 1>&2
[ "$status" -eq 123 ]
## Cases for target container
### First container
container_name=$(kubectl exec $pod_name -c $first_container_name -- env | grep CONTAINER_NAME)
[ "$container_name" == "CONTAINER_NAME=$first_container_name" ]
### Second container
container_name=$(kubectl exec $pod_name -c $second_container_name -- env | grep CONTAINER_NAME)
[ "$container_name" == "CONTAINER_NAME=$second_container_name" ]
}
teardown() {
# Debugging information
kubectl describe "pod/$pod_name"
kubectl delete pod "$pod_name"
}