minor edit on Linux tests and init work on k8s API

This commit is contained in:
bunkerity 2021-07-26 17:15:24 +02:00
parent 50c279617b
commit 22612f1757
No known key found for this signature in database
GPG Key ID: 3D80806F12602A7C
4 changed files with 84 additions and 22 deletions

View File

@ -13,10 +13,10 @@ jobs:
- name: Checkout source code - name: Checkout source code
uses: actions/checkout@v2 uses: actions/checkout@v2
- name: Debian test - name: Debian test
run: ./tests/linux.sh debian:buster-slim run: ./tests/linux-run.sh debian:buster-slim test-debian
- name: Ubuntu test - name: Ubuntu test
run: ./tests/linux.sh ubuntu:focal run: ./tests/linux-run.sh ubuntu:focal test-ubuntu
- name: CentOS test - name: CentOS test
run: ./tests/linux.sh centos:7 run: ./tests/linux-run.sh centos:7 test-centos
- name: Fedora test - name: Fedora test
run: ./tests/linux.sh fedora:34 run: ./tests/linux-run.sh fedora:34 test-fedora

View File

@ -0,0 +1,54 @@
from kubernetes import client, config, watch
import asyncio
class IngressController :
def __init__(self) :
config.load_kube_config()
self.__api = client.CoreV1Api()
self.__extensions_api = client.ExtensionsV1beta1Api()
def get_ingresses(self) :
return self.__extensions_api.list_ingress_for_all_namespaces(watch=False)
def get_services(self) :
return self.__api.list_service_for_all_namespaces(watch=False)
async def watch_ingress(self) :
print("ok ingress", flush=True)
w = watch.Watch()
for event in w.stream(self.__extensions_api.list_ingress_for_all_namespaces) :
print("*** NEW INGRESS EVENT ***", flush=True)
for k, v in event.items() :
print(k + " :", flush=True)
print(v, flush=True)
await asyncio.sleep(0)
async def watch_service(self) :
print("ok service", flush=True)
w = watch.Watch()
for event in w.stream(self.__api.list_service_for_all_namespaces) :
print("*** NEW SERVICE EVENT ***", flush=True)
for k, v in event.items() :
print(k + " :", flush=True)
print(v, flush=True)
await asyncio.sleep(0)
ic = IngressController()
print("*** INGRESSES ***")
print(ic.get_ingresses())
print("*** SERVICES ***")
print(ic.get_services())
print("*** LISTENING FOR EVENTS ***")
ioloop = asyncio.get_event_loop()
print("ok1")
ioloop.create_task(ic.watch_ingress())
print("ok2")
ioloop.create_task(ic.watch_service())
print("ok3")
ioloop.run_forever()

View File

@ -1,3 +1,4 @@
docker docker
requests requests
jinja2 jinja2
kubernetes

View File

@ -5,68 +5,73 @@ function cleanup() {
} }
image="$1" image="$1"
name="$2"
do_cleanup="yes"
if [ "$3" == "no" ] ; then
do_cleanup="no"
fi
echo "[*] Run $image" echo "[*] Run $image"
id="$(docker run --rm -d -it -p 80:80 "$image")" id="$(docker run --rm -d -it -p 80:80 -p 443:443 --name "$name" "$image")"
if [ $? -ne 0 ] ; then if [ $? -ne 0 ] ; then
echo "[!] docker run failed" echo "[!] docker run failed"
cleanup "$id" cleanup "$name"
exit 1 exit 1
fi fi
echo "[*] Copy install.sh" echo "[*] Copy install.sh"
docker cp helpers/install.sh "$id:/tmp" docker cp helpers/install.sh "$name:/tmp"
if [ $? -ne 0 ] ; then if [ $? -ne 0 ] ; then
echo "[!] docker cp failed" echo "[!] docker cp failed"
cleanup "$id" cleanup "$name"
exit 2 exit 2
fi fi
echo "[*] Copy bunkerized-nginx" echo "[*] Copy bunkerized-nginx"
docker cp . "$id:/tmp/bunkerized-nginx-test" docker cp . "$name:/tmp/bunkerized-nginx-test"
if [ $? -ne 0 ] ; then if [ $? -ne 0 ] ; then
echo "[!] docker cp failed" echo "[!] docker cp failed"
cleanup "$id" cleanup "$name"
exit 3 exit 3
fi fi
echo "[*] Exec install.sh" echo "[*] Exec install.sh"
docker exec "$id" /bin/bash -c 'chmod +x /tmp/install.sh && /tmp/install.sh' docker exec "$name" /bin/bash -c 'chmod +x /tmp/install.sh && /tmp/install.sh'
if [ $? -ne 0 ] ; then if [ $? -ne 0 ] ; then
echo "[!] docker exec failed" echo "[!] docker exec failed"
cleanup "$id" cleanup "$name"
exit 4 exit 4
fi fi
echo "[*] Exec nginx -V" echo "[*] Exec nginx -V"
docker exec "$id" nginx -V docker exec "$name" nginx -V
if [ $? -ne 0 ] ; then if [ $? -ne 0 ] ; then
echo "[!] docker exec failed" echo "[!] docker exec failed"
cleanup "$id" cleanup "$name"
exit 5 exit 5
fi fi
echo "[*] Copy variables.env" echo "[*] Copy variables.env"
docker cp "tests/variables.env" "$id:/opt/bunkerized-nginx" docker cp "tests/variables.env" "$name:/opt/bunkerized-nginx"
if [ $? -ne 0 ] ; then if [ $? -ne 0 ] ; then
echo "[!] docker cp failed" echo "[!] docker cp failed"
cleanup "$id" cleanup "$name"
exit 6 exit 6
fi fi
echo "[*] Copy index.html" echo "[*] Copy index.html"
docker cp "tests/index.html" "$id:/opt/bunkerized-nginx/www" docker cp "tests/index.html" "$name:/opt/bunkerized-nginx/www"
if [ $? -ne 0 ] ; then if [ $? -ne 0 ] ; then
echo "[!] docker cp failed" echo "[!] docker cp failed"
cleanup "$id" cleanup "$name"
exit 7 exit 7
fi fi
echo "[*] Exec bunkerized-nginx" echo "[*] Exec bunkerized-nginx"
docker exec "$id" bunkerized-nginx docker exec "$name" bunkerized-nginx
if [ $? -ne 0 ] ; then if [ $? -ne 0 ] ; then
echo "[!] docker exec failed" echo "[!] docker exec failed"
cleanup "$id" cleanup "$name"
exit 8 exit 8
fi fi
@ -74,8 +79,10 @@ echo "[*] Exec curl"
res="$(curl -s -H "User-Agent: LegitOne" http://localhost/)" res="$(curl -s -H "User-Agent: LegitOne" http://localhost/)"
if [ $? -ne 0 ] || [ "$res" != "ok" ] ; then if [ $? -ne 0 ] || [ "$res" != "ok" ] ; then
echo "[!] curl failed" echo "[!] curl failed"
cleanup "$id" cleanup "$name"
exit 9 exit 9
fi fi
cleanup "$id" if [ "$do_cleanup" == "yes" ] ; then
cleanup "$name"
fi