forked from kata-containers/tests
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebhook-check.sh
executable file
·77 lines (67 loc) · 1.97 KB
/
webhook-check.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/bin/bash
#
# Copyright (c) 2021 Red Hat
#
# SPDX-License-Identifier: Apache-2.0
#
# Run this script to check the webhook is deployed and working
set -o errexit
set -o nounset
set -o pipefail
webhook_dir=$(dirname $0)
source "${webhook_dir}/../lib/common.bash"
source "${webhook_dir}/common.bash"
readonly hello_pod="hello-kata-webhook"
# The Pod RuntimeClassName for Kata Containers.
RUNTIME_CLASS="${RUNTIME_CLASS:-"kata"}"
cleanup() {
{
kubectl get -n ${WEBHOOK_NS} pod/${hello_pod} && \
kubectl delete -n ${WEBHOOK_NS} pod/${hello_pod}
} &>/dev/null
}
trap cleanup EXIT
# Check the deployment exists and is available.
#
check_deployed() {
local timeout="60s"
kubectl get -n ${WEBHOOK_NS} deployment/${WEBHOOK_SVC} &>/dev/null || \
die "The ${WEBHOOK_SVC} deployment does not exist"
kubectl wait -n ${WEBHOOK_NS} deployment/${WEBHOOK_SVC} \
--for condition=Available --timeout ${timeout} &>/dev/null || \
die "The ${WEBHOOK_SVC} deployment is unavailable after ${timeout} waiting"
}
# Check the webhook is working as expected.
#
check_working() {
kubectl get -n ${WEBHOOK_NS} pod/${hello_pod} &>/dev/null && \
die "${hello_pod} pod exists, cannot reliably check the webhook"
cat <<-EOF | kubectl apply -f -
kind: Pod
apiVersion: v1
metadata:
name: ${hello_pod}
namespace: ${WEBHOOK_NS}
spec:
restartPolicy: Never
containers:
- name: ${hello_pod}
image: quay.io/prometheus/busybox:latest
command: ["echo", "Hello Webhook"]
imagePullPolicy: IfNotPresent
EOF
local class_name=$(kubectl get -n ${WEBHOOK_NS} \
-o jsonpath='{.spec.runtimeClassName}' pod/${hello_pod})
if [ "${class_name}" != "${RUNTIME_CLASS}" ]; then
warn "RuntimeClassName expected ${RUNTIME_CLASS}, got ${class_name}"
die "kata-webhook is not working"
fi
}
main() {
info "Going to check the kata-webhook installation"
[ -n "${KUBECONFIG:-}" ] || die "KUBECONFIG should be exported"
check_deployed
check_working
info "kata-webhook is up and working"
}
main $@