2 # SPDX-license-identifier: Apache-2.0
3 ##############################################################################
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 ##############################################################################
15 source _common_test.sh
22 function create_pod_yaml_with_affinity {
24 cat << POD > $HOME/$pod_name-affinity.yaml
32 requiredDuringSchedulingIgnoredDuringExecution:
35 - key: "feature.node.kubernetes.io/kernel-version.major"
40 - key: "feature.node.kubernetes.io/kernel-version.major"
45 - key: "feature.node.kubernetes.io/kernel-version.major"
52 - key: "feature.node.kubernetes.io/kernel-version.major"
57 - key: "feature.node.kubernetes.io/kernel-version.major"
60 - key: "feature.node.kubernetes.io/label_does_not_exist"
61 operator: DoesNotExist
63 - name: with-node-affinity
64 image: gcr.io/google_containers/pause:2.0
68 function create_pod_yaml_with_nodeSelector {
70 cat << POD > $HOME/$pod_name-nodeSelector.yaml
77 feature.node.kubernetes.io/kernel-version.major: '4'
79 - name: with-node-affinity
80 image: gcr.io/google_containers/pause:2.0
85 if $(kubectl version &>/dev/null); then
86 labels=$(kubectl get nodes -o json | jq .items[].metadata.labels)
89 if [[ $labels != *"kubernetes.io"* ]]; then
93 create_pod_yaml_with_affinity
94 create_pod_yaml_with_nodeSelector
96 for podType in ${POD_TYPE:-nodeSelector affinity}; do
98 kubectl delete pod $pod_name --ignore-not-found=true --now
99 while kubectl get pod $pod_name &>/dev/null; do
103 kubectl create -f $HOME/$pod_name-$podType.yaml --validate=false
105 for pod in $pod_name; do
107 while [[ $status_phase != "Running" ]]; do
108 new_phase=$(kubectl get pods $pod | awk 'NR==2{print $3}')
109 if [[ $new_phase != $status_phase ]]; then
110 echo "$(date +%H:%M:%S) - $pod-$podType : $new_phase"
111 status_phase=$new_phase
114 if [[ $new_phase == "Running" ]]; then
115 echo " Test is complete.."
117 if [[ $new_phase == "Err"* ]]; then
122 kubectl delete pod $pod_name
123 while kubectl get pod $pod_name &>/dev/null; do