Merge "Restructuring the repo."
[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 rm -f $HOME/*.yaml
16
17 pod_name=nfd-pod
18
19 cat << POD > $HOME/$pod_name.yaml
20 apiVersion:
21  v1
22 kind: Pod
23 metadata:
24   name: $pod_name
25   labels:
26     env: test
27 spec:
28   containers:
29   - name: nginx
30     image: nginx
31 nodeSelector:
32   node.alpha.kubernetes-incubator.io/nfd-network-SRIOV: true
33 POD
34
35 if $(kubectl version &>/dev/null); then
36     labels=$(kubectl get nodes -o json | jq .items[].metadata.labels)
37
38     echo $labels
39     if [[ $labels != *"node.alpha.kubernetes-incubator.io"* ]]; then
40         exit 1
41     fi
42
43     kubectl delete pod $pod_name --ignore-not-found=true --now
44     while kubectl get pod $pod_name &>/dev/null; do
45         sleep 5
46     done
47     kubectl create -f $HOME/$pod_name.yaml --validate=false
48
49     for pod in $pod_name; do
50         status_phase=""
51         while [[ $status_phase != "Running" ]]; do
52             new_phase=$(kubectl get pods $pod | awk 'NR==2{print $3}')
53             if [[ $new_phase != $status_phase ]]; then
54                 echo "$(date +%H:%M:%S) - $pod : $new_phase"
55                 status_phase=$new_phase
56             fi
57             if [[ $new_phase == "Err"* ]]; then
58                 exit 1
59             fi
60         done
61     done
62 fi