Provide connection info for plugin testcase
[multicloud/k8s.git] / kud / tests / nfd.sh
1 #!/bin/bash
2 # SPDX-license-identifier: Apache-2.0
3 ##############################################################################
4 # Copyright (c) 2018
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9 ##############################################################################
10
11 set -o errexit
12 set -o nounset
13 set -o pipefail
14
15 source _common_test.sh
16
17 rm -f $HOME/*.yaml
18
19 pod_name=nfd-pod
20
21 install_deps
22 cat << POD > $HOME/$pod_name.yaml
23 apiVersion:
24  v1
25 kind: Pod
26 metadata:
27   name: $pod_name
28   labels:
29     env: test
30 spec:
31   containers:
32   - name: nginx
33     image: nginx
34 nodeSelector:
35   node.alpha.kubernetes-incubator.io/nfd-network-SRIOV: true
36 POD
37
38 if $(kubectl version &>/dev/null); then
39     labels=$(kubectl get nodes -o json | jq .items[].metadata.labels)
40
41     echo $labels
42     if [[ $labels != *"node.alpha.kubernetes-incubator.io"* ]]; then
43         exit 1
44     fi
45
46     kubectl delete pod $pod_name --ignore-not-found=true --now
47     while kubectl get pod $pod_name &>/dev/null; do
48         sleep 5
49     done
50     kubectl create -f $HOME/$pod_name.yaml --validate=false
51
52     for pod in $pod_name; do
53         status_phase=""
54         while [[ $status_phase != "Running" ]]; do
55             new_phase=$(kubectl get pods $pod | awk 'NR==2{print $3}')
56             if [[ $new_phase != $status_phase ]]; then
57                 echo "$(date +%H:%M:%S) - $pod : $new_phase"
58                 status_phase=$new_phase
59             fi
60             if [[ $new_phase == "Err"* ]]; then
61                 exit 1
62             fi
63         done
64     done
65 fi