pve_tests/run.sh

89 lines
1.9 KiB
Bash
Executable File

#!/usr/bin/sh
set -xeuo pipefail
function print_help() {
cat <<EOF
usage:
$0 <branch> <k8s_version> <task_number>
EOF
}
if [ "$#" -lt 3 ]; then
print_help
exit 1
fi
K8S_VERSIONS="1.26 1.27 1.28 1.29 1.30"
for k8s_version in $K8S_VERSIONS; do
branch="${1:-"sisyphus"}"
#k8s_version="${2:-"1.28"}"
task_number="${3:-}"
ssh_options="-o IdentitiesOnly=yes -o StrictHostKeyChecking=no"
# Create VMs
python3 ./main.py
# let cloud-init update the system or apt won't be able to get the lock
# remove later
sleep 80
# Send run/hosts to every vm
cat tmp/hosts | awk '{print $1}' | xargs -I {} rsync -e "ssh $ssh_options" tmp/hosts root@{}:/etc/hosts
# Restart network on every vm
cat tmp/hosts | awk '{print $1}' | xargs -I {} ssh $ssh_options root@{} "systemctl restart network"
ansible-playbook ansible/playbook.yaml -i tmp/generated_inventory.yaml \
-e task_number="$task_number" -e k8s_version="$k8s_version" -e branch="$branch"
head -n 1 tmp/hosts | awk '{print $1}' | xargs -I {} rsync root@{}:/etc/kubernetes/admin.conf ~/.kube/config
kubectl apply -f - <<'EOF'
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
spec:
selector:
matchLabels:
app: nginx
replicas: 2 # tells deployment to run 2 pods matching the template
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: obirvalger/my
ports:
- containerPort: 80
EOF
kubectl apply -f - <<'EOF'
apiVersion: v1
kind: Service
metadata:
name: nginx
labels:
app: nginx
spec:
type: NodePort
ports:
- port: 80
targetPort: 80
nodePort: 30007
selector:
app: nginx
EOF
sleep 120
head -n 1 tmp/hosts | awk '{print $1}' | xargs -I {} curl {}:30007
kubectl exec $(kubectl get po | awk 'END{print $1}') -- nslookup nginx
# Remove ip addresses from known_hosts
cat tmp/hosts | awk '{print $1}' | xargs -I {} ssh-keygen -R {}
done