Ensure EMCO is ready before using
[icn.git] / deploy / addons / addons.sh
1 #!/usr/bin/env bash
2 set -eux -o pipefail
3
4 SCRIPTDIR="$(readlink -f $(dirname ${BASH_SOURCE[0]}))"
5 LIBDIR="$(dirname $(dirname ${SCRIPTDIR}))/env/lib"
6
7 source $LIBDIR/logging.sh
8 source $LIBDIR/common.sh
9
10 BUILDDIR=${SCRIPTDIR/deploy/build}
11 mkdir -p ${BUILDDIR}
12
13 function is_emco_ready {
14     local -r cluster_name=${CLUSTER_NAME:-icn}
15     local -r cluster_kubeconfig="${BUILDDIR}/${cluster_name}.conf"
16     kubectl --kubeconfig=${cluster_kubeconfig} -n emco wait pod --all --for=condition=Ready --timeout=0s >/dev/null 2>&1
17 }
18
19 function register_emco_controllers {
20     wait_for is_emco_ready
21     local -r cluster_name=${CLUSTER_NAME:-icn}
22     local -r host=$(kubectl -n metal3 get cluster/${cluster_name} -o jsonpath='{.spec.controlPlaneEndpoint.host}')
23     cat <<EOF >${BUILDDIR}/${cluster_name}-config.yaml
24 orchestrator:
25   host: ${host}
26   port: 30415
27 EOF
28     cat <<EOF >${BUILDDIR}/${cluster_name}-controllers.yaml
29 ---
30 version: emco/v2
31 resourceContext:
32   anchor: controllers
33 metadata:
34   name: rsync
35 spec:
36   host: ${host}
37   port: 30441
38 ---
39 version: emco/v2
40 resourceContext:
41   anchor: controllers
42 metadata:
43   name: gac
44 spec:
45   host: ${host}
46   port: 30493
47   type: "action"
48   priority: 1
49 ---
50 version: emco/v2
51 resourceContext:
52   anchor: controllers
53 metadata:
54   name: ovnaction
55 spec:
56   host: ${host}
57   port: 30473
58   type: "action"
59   priority: 1
60 ---
61 version: emco/v2
62 resourceContext:
63   anchor: controllers
64 metadata:
65   name: dtc
66 spec:
67   host: ${host}
68   port: 30483
69   type: "action"
70   priority: 1
71 EOF
72     emcoctl --config ${BUILDDIR}/${cluster_name}-config.yaml apply -f ${BUILDDIR}/${cluster_name}-controllers.yaml
73 }
74
75 function unregister_emco_controllers {
76     local -r cluster_name=${CLUSTER_NAME:-icn}
77     emcoctl --config ${BUILDDIR}/${cluster_name}-config.yaml delete -f ${BUILDDIR}/${cluster_name}-controllers.yaml
78 }
79
80 function test_addons {
81     # Create a temporary kubeconfig file for the tests
82     local -r cluster_name=${CLUSTER_NAME:-icn}
83     local -r cluster_kubeconfig="${BUILDDIR}/${cluster_name}.conf"
84     clusterctl -n metal3 get kubeconfig ${cluster_name} >${cluster_kubeconfig}
85
86     clone_kud_repository
87     pushd ${KUDPATH}/kud/tests
88     failed_kud_tests=""
89     container_runtime=$(KUBECONFIG=${cluster_kubeconfig} kubectl get nodes -o jsonpath='{.items[].status.nodeInfo.containerRuntimeVersion}')
90     # TODO Temporarily remove kubevirt from kud_tests below.  The
91     # kubevirt self-test needs AllowTcpForwarding yes in
92     # /etc/ssh/sshd_config which is currently disabled by the OS
93     # security hardening.
94     if [[ "${container_runtime}" == "containerd://1.2.13" ]]; then
95         # With containerd 1.2.13, the qat test container image fails to unpack.
96         kud_tests="topology-manager-sriov multus ovn4nfv nfd sriov-network cmk"
97     else
98         kud_tests="topology-manager-sriov multus ovn4nfv nfd sriov-network qat cmk"
99     fi
100     for test in ${kud_tests}; do
101         KUBECONFIG=${cluster_kubeconfig} bash ${test}.sh || failed_kud_tests="${failed_kud_tests} ${test}"
102     done
103     # The plugin_fw_v2 test needs the EMCO controllers in place
104     register_emco_controllers
105     DEMO_FOLDER=${KUDPATH}/kud/demo KUBECONFIG=${cluster_kubeconfig} bash plugin_fw_v2.sh --external || failed_kud_tests="${failed_kud_tests} plugin_fw_v2"
106     unregister_emco_controllers
107     popd
108     if [[ ! -z "$failed_kud_tests" ]]; then
109         echo "Test cases failed:${failed_kud_tests}"
110         exit 1
111     fi
112     echo "All test cases passed"
113
114     rm ${cluster_kubeconfig}
115 }
116
117 case $1 in
118     "test") test_addons ;;
119     *) cat <<EOF
120 Usage: $(basename $0) COMMAND
121
122 The "test" command looks for the CLUSTER_NAME variable in the
123 environment (default: "icn").  This should be the name of the
124 Cluster resource to execute the tests in.
125
126 Commands:
127   test  - Test the addons
128 EOF
129        ;;
130 esac