-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
67 lines (49 loc) · 2.39 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import os
import sys
import json
from helpers.config.orchestrator.kube.liveapps import get_kube_svc, get_my_ingress_pod_ip, get_kube_app_with_ingress_all, get_kube_proxy_info
parent_dir = os.path.dirname(os.path.realpath(__file__))
sys.path.append(parent_dir)
'''
Check if node is eligible and healthy for
kube-proxy
ingress
list all the svc on the k8s cluster
categorise them to L4-Kube-Proxy and L7-IngressClass
yes: bring up the ClusterIP on FRR up
no: bring down the ClusterIP on FRR down
loop every second !
'''
# fetch the running services and ingress pod IPs
services = get_kube_svc()
app_ingresses = get_kube_app_with_ingress_all()
node_ingress_details = get_my_ingress_pod_ip()
node_kube_proxy_details = get_kube_proxy_info()
# Blindly advertise the ClusterIP of Ingress Service if node is eligible
svc_list = []
for svc in services:
svc_list.append(svc["service_name"])
l7_ingress_services_to_expose = []
for app_ingress in app_ingresses:
l7_ingress_services_to_expose.append(app_ingress["name"])
node_ingresses = []
node_ingresses_namespaces = []
for ingress in node_ingress_details:
node_ingresses.append(ingress["ingress_release_name"])
node_ingresses_namespaces.append(ingress["ingress_release_namespace"])
# Check the health of each service and then expose the ClusterIP if the node is able to handle the traffic
l4_kube_proxy_services_to_expose = []
for svc in services:
if svc["service_name"] not in l7_ingress_services_to_expose:
if svc["service_namespace"] not in node_ingresses_namespaces:
l4_kube_proxy_services_to_expose.append(svc["service_name"])
print("L7 Ingresses to be BGP Advertised:\n{}".format(json.dumps(node_ingresses)))
print("L7 Applications that are automatically getting advertised:\n{}".format(json.dumps(app_ingresses)))
print("if my ingress pod on current node is healthy, advertise the Cluster IP of the ingress svc")
print("L4 Kube-Proxy ClusterIP SVCs to be BGP Advertised:\n{}".format(json.dumps(l4_kube_proxy_services_to_expose)))
print("if my kube-proxy pod on current node is healthy, advertise the Cluster IP of the l4 svc")
#print("{}\n".format(json.dumps(app_ingresses)))
#print("{}\n".format(json.dumps(node_kube_proxy_details)))
#print("{}\n".format(json.dumps(node_ingress_details)))
#print("{}\n".format(json.dumps(l7_ingress_services_to_expose)))
#print("{}\n".format(json.dumps(l4_kube_proxy_services_to_expose)))