pve_tests/run.sh

92 lines
2.1 KiB
Bash
Raw Normal View History

2024-08-08 22:41:12 +03:00
#!/bin/sh
2024-05-26 08:37:52 +03:00
set -xeuo pipefail
2024-05-26 08:37:52 +03:00
function print_help() {
cat <<EOF
usage:
2024-08-08 22:41:12 +03:00
$0 <branch> <k8s_version> [<task_number>]
2024-05-26 08:37:52 +03:00
EOF
}
2024-08-08 22:41:12 +03:00
if [ "$#" -lt 2 ]; then
2024-05-26 08:37:52 +03:00
print_help
exit 1
fi
2024-08-08 22:41:12 +03:00
function at_err() {
if [ -s tmp/hosts ]; then
cat tmp/hosts | awk '{print $1}' | xargs -I {} ssh-keygen -R {}
fi
}
2024-05-26 08:37:52 +03:00
2024-08-08 22:41:12 +03:00
trap at_err ERR
2024-05-26 08:37:52 +03:00
2024-08-08 22:41:12 +03:00
branch="$1"
k8s_version="$2"
task_number="${3:-}"
ssh_options="-o IdentitiesOnly=yes -o StrictHostKeyChecking=no"
2024-08-08 22:41:12 +03:00
# Create VMs
python3 ./main.py
2024-08-08 22:41:12 +03:00
# 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"
# Add insecure registry entry
cat tmp/hosts | awk '{print $1}' | xargs -I {} ssh $ssh_options root@{} "mkdir -p /etc/containers/registries.conf.d"
cat tmp/hosts | awk '{print $1}' | xargs -I {} scp $ssh_options 001-insecure-registries.conf root@{}:/etc/containers/registries.conf.d/001-insecure-registries.conf
2023-10-24 21:16:48 +03:00
2024-08-08 22:41:12 +03:00
ansible-playbook ansible/playbook.yaml -i tmp/generated_inventory.yaml \
-e branch="$branch" -e k8s_version="$k8s_version" -e task_number="$task_number"
2024-08-08 22:41:12 +03:00
head -n 1 tmp/hosts | awk '{print $1}' | xargs -I {} rsync --mkpath root@{}:/etc/kubernetes/admin.conf ~/.kube/config
2024-08-08 22:41:12 +03:00
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
2024-08-08 22:41:12 +03:00
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
2024-08-08 22:41:12 +03:00
sleep 120
2024-08-08 22:41:12 +03:00
head -n 1 tmp/hosts | awk '{print $1}' | xargs -I {} curl {}:30007
kubectl exec $(kubectl get po | awk 'END{print $1}') -- nslookup nginx
2024-08-08 22:41:12 +03:00
# Remove ip addresses from known_hosts
cat tmp/hosts | awk '{print $1}' | xargs -I {} ssh-keygen -R {}