4 SCRIPTDIR="$(readlink -f $(dirname ${BASH_SOURCE[0]}))"
5 LIBDIR="$(dirname $(dirname ${SCRIPTDIR}))/env/lib"
7 source $LIBDIR/logging.sh
8 source $LIBDIR/common.sh
10 BUILDDIR=${SCRIPTDIR/deploy/build}
13 KATA_VERSION="2.1.0-rc0"
14 KATA_WEBHOOK_VERSION="2.1.0-rc0"
16 KATA_DEPLOY_URL="https://raw.githubusercontent.com/kata-containers/kata-containers/${KATA_VERSION}/tools/packaging/kata-deploy"
17 KATA_WEBHOOK_URL="https://raw.githubusercontent.com/kata-containers/tests/${KATA_WEBHOOK_VERSION}/kata-webhook"
18 KATA_WEBHOOK_DIR="/opt/src/kata_webhook"
19 KATA_WEBHOOK_RUNTIMECLASS="kata-clh"
21 # This may be used to update the in-place Kata YAML files from the
23 function build_source {
24 mkdir -p ${SCRIPTDIR}/base
25 curl -sL ${KATA_DEPLOY_URL}/kata-rbac/base/kata-rbac.yaml -o ${SCRIPTDIR}/base/kata-rbac.yaml
26 curl -sL ${KATA_DEPLOY_URL}/kata-deploy/base/kata-deploy.yaml -o ${SCRIPTDIR}/base/kata-deploy.yaml
27 curl -sL ${KATA_DEPLOY_URL}/runtimeclasses/kata-runtimeClasses.yaml -o ${SCRIPTDIR}/base/kata-runtimeClasses.yaml
28 pushd ${SCRIPTDIR}/base && kustomize create --autodetect && popd
31 function deploy_webhook {
32 local -r cluster_name=$1
33 local -r cluster_kubeconfig="${BUILDDIR}/${cluster_name}.conf"
35 # Note that the webhook-registration.yaml.tpl file is fetched here
36 # but webhook-registration.yaml is deployed: this is intentional,
37 # create-certs.sh takes care of converting the .yaml.tpl into the
39 mkdir -p ${BUILDDIR}/webhook/base/deploy
40 curl -sL ${KATA_WEBHOOK_URL}/common.bash -o ${BUILDDIR}/webhook/base/common.bash
41 curl -sL ${KATA_WEBHOOK_URL}/create-certs.sh -o ${BUILDDIR}/webhook/base/create-certs.sh
42 curl -sL ${KATA_WEBHOOK_URL}/deploy/webhook-registration.yaml.tpl -o ${BUILDDIR}/webhook/base/deploy/webhook-registration.yaml.tpl
43 curl -sL ${KATA_WEBHOOK_URL}/deploy/webhook.yaml -o ${BUILDDIR}/webhook/base/deploy/webhook.yaml
45 chmod +x ${BUILDDIR}/webhook/base/create-certs.sh
46 sed 's/value: kata/value: ${KATA_WEBHOOK_RUNTIMECLASS}/g' ${BUILDDIR}/webhook/base/deploy/webhook.yaml | tee ${BUILDDIR}/webhook/base/deploy/webhook-${KATA_WEBHOOK_RUNTIMECLASS}.yaml
47 pushd ${BUILDDIR}/webhook/base && ./create-certs.sh && popd
49 cat <<EOF >${BUILDDIR}/webhook/base/kustomization.yaml
50 apiVersion: kustomize.config.k8s.io/v1beta1
53 - deploy/webhook-certs.yaml
54 - deploy/webhook-registration.yaml
55 - deploy/webhook-${KATA_WEBHOOK_RUNTIMECLASS}.yaml
58 kustomize build ${BUILDDIR}/webhook/base | KUBECONFIG=${cluster_kubeconfig} kubectl apply -f -
61 function clean_webhook {
62 local -r cluster_name=$1
63 local -r cluster_kubeconfig="${BUILDDIR}/${cluster_name}.conf"
65 kustomize build ${BUILDDIR}/webhook/base | KUBECONFIG=${cluster_kubeconfig} kubectl delete -f -
68 function is_kata_deployed {
69 local -r cluster_name=${CLUSTER_NAME:-icn}
70 local -r cluster_kubeconfig="${BUILDDIR}/${cluster_name}.conf"
71 kubectl --kubeconfig=${cluster_kubeconfig} get runtimeclass/kata-qemu
75 # Create a temporary kubeconfig file for the tests
76 local -r cluster_name=${CLUSTER_NAME:-icn}
77 local -r cluster_kubeconfig="${BUILDDIR}/${cluster_name}.conf"
78 clusterctl -n metal3 get kubeconfig ${cluster_name} >${cluster_kubeconfig}
80 # Ensure that Kata has been deployed first
82 wait_for is_kata_deployed
84 deploy_webhook ${cluster_name}
86 pushd ${KUDPATH}/kud/tests
88 KUBECONFIG=${cluster_kubeconfig} bash kata.sh || failed_kud_tests="${failed_kud_tests} kata"
90 clean_webhook ${cluster_name}
91 if [[ ! -z "$failed_kud_tests" ]]; then
92 echo "Test cases failed:${failed_kud_tests}"
95 echo "All test cases passed"
97 rm ${cluster_kubeconfig}
101 "build-source") build_source ;;
104 Usage: $(basename $0) COMMAND
106 The "test" command looks for the CLUSTER_NAME variable in the
107 environment (default: "icn"). This should be the name of the
108 Cluster resource to execute the tests in.
111 build-source - Rebuild the in-tree Kata YAML files