2024-08-08 22:41:12 +03:00
#!/bin/sh
2023-10-13 16:48:05 +03:00
2024-05-26 08:37:52 +03:00
set -xeuo pipefail
2024-04-29 04:14:52 +03:00
2024-05-26 08:37:52 +03:00
function print_help( ) {
cat <<EOF
usage:
2024-09-05 21:13:37 +03:00
$0 <branch> <k8s_version> <flannel_tag> <flannel_cni_tag> <registry> [ <task_number>]
2024-05-26 08:37:52 +03:00
EOF
}
2024-09-05 21:13:37 +03:00
if [ " $# " -lt 5 ] ; 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 "
2024-09-05 21:13:37 +03:00
flannel_tag = " $3 "
flannel_cni_tag = " $4 "
registry = " $5 "
task_number = " ${ 6 :- } "
2024-08-08 22:41:12 +03:00
ssh_options = "-o IdentitiesOnly=yes -o StrictHostKeyChecking=no"
2024-04-29 04:14:52 +03:00
2024-08-08 22:41:12 +03:00
# Create VMs
2024-09-05 21:13:37 +03:00
python3 ./main.py " $branch "
2023-10-13 16:48:05 +03:00
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"
2024-09-05 21:13:37 +03:00
if [ -f '001-insecure-registries.conf' ] ; then
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
fi
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 \
2024-09-05 21:13:37 +03:00
-e branch = " $branch " \
-e k8s_version = " $k8s_version " \
-e flannel_tag = " $flannel_tag " \
-e flannel_cni_tag = " $flannel_cni_tag " \
-e registry = " $registry " \
-e task_number = " $task_number "
2023-10-13 16:48:05 +03:00
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
2023-10-13 16:48:05 +03:00
2024-08-08 22:41:12 +03:00
kubectl apply -f - <<EOF
2023-10-13 16:48:05 +03:00
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
2023-10-13 16:48:05 +03:00
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
2023-10-13 16:48:05 +03:00
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-04-29 04:14:52 +03:00
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 { }