@@ -24,12 +24,13 @@ def __init__(self, namespace='default', ignore_namespaces=["kube-system"], ingre
24
24
self .namespace = namespace
25
25
self .ignore_namespaces = ignore_namespaces
26
26
self .ingress_class = ingress_class
27
+ self ._logger = logging .getLogger ('flask.app' )
28
+ self ._logger .setLevel (logging .getLevelName ('INFO' ))
29
+
30
+ self ._logger .info ("Initializing Kubernetes Backend; namespace='%s', ignore_namespaces='%s', ingress_class='%s'" % (self .namespace , self .ignore_namespaces , self .ingress_class ))
27
31
28
32
if not self ._api or not self ._ext_api :
29
- self ._logger = logging .getLogger ('flask.app' )
30
- self ._logger .setLevel (logging .getLevelName ('INFO' ))
31
33
self ._logger .info ('Initializing Kubernetes Client.' )
32
-
33
34
config .load_incluster_config ()
34
35
35
36
self ._api = client .CoreV1Api ()
@@ -135,7 +136,7 @@ def _get_services(self):
135
136
def get_relevant_services (self , ingress ):
136
137
services = {}
137
138
for service in self ._get_services ().items :
138
- if service .metadata .name in ingress ["services" ] and service .metadata .namespace not in self .ignore_namespaces :
139
+ if service .metadata .name in ingress ["services" ] and service .metadata .namespace not in self .ignore_namespaces and service . metadata . name != "kubernetes" :
139
140
ports = {}
140
141
for port in service .spec .ports :
141
142
ports [port .protocol ] = { port .port : port .target_port }
@@ -151,9 +152,12 @@ def get_services_from_annotation(self, annotation):
151
152
for service in self ._get_services ().items :
152
153
ports = {}
153
154
for port in service .spec .ports :
154
- if port .port in relevant_ports and service .metadata .namespace not in self .ignore_namespaces :
155
- ports [port .protocol ] = { port .port : port .target_port }
156
- services [service .metadata .name ] = ports
155
+ if port .port in relevant_ports :
156
+ if service .metadata .namespace not in self .ignore_namespaces and service .metadata .name != "kubernetes" :
157
+ ports [port .protocol ] = { port .port : port .target_port }
158
+ services [service .metadata .name ] = ports
159
+ else :
160
+ self ._logger .info ("Ignoring service from namespace; name='%s', namespace='%s'" % (service .metadata .name , service .metadata .namespace ))
157
161
return services
158
162
159
163
def _get_endpoints (self ):
@@ -174,7 +178,7 @@ def get_relevant_endpoints(self, services):
174
178
tcp_endpoints = {}
175
179
udp_endpoints = {}
176
180
for endpoint in self ._get_endpoints ().items :
177
- if endpoint .metadata .name in services .keys () and endpoint . metadata . namespace not in self . ignore_namespaces :
181
+ if endpoint .metadata .name in services .keys ():
178
182
for subset in endpoint .subsets :
179
183
for address in subset .addresses :
180
184
for port in subset .ports :
@@ -192,34 +196,6 @@ def get_relevant_endpoints(self, services):
192
196
endpoints [port .port ] = { name : [address .ip , ]}
193
197
return {"TCP" : tcp_endpoints , "UDP" : udp_endpoints }
194
198
195
- def get_endpoints_from_annotation (self , annotation ):
196
- relevant_ports = []
197
- for rule in annotation :
198
- if "target_ports" in rule :
199
- relevant_ports .extend (rule ["target_ports" ])
200
-
201
- tcp_endpoints = {}
202
- udp_endpoints = {}
203
- for endpoint in self ._get_endpoints ().items :
204
- if endpoint .subsets is not None and endpoint .metadata .namespace not in self .ignore_namespaces :
205
- for subset in endpoint .subsets :
206
- for port in subset .ports :
207
- if port .port in relevant_ports and subset .addresses is not None :
208
- for address in subset .addresses :
209
- name = endpoint .metadata .name
210
- if port .protocol == "TCP" :
211
- endpoints = tcp_endpoints
212
- else :
213
- endpoints = udp_endpoints
214
- if port .port in endpoints :
215
- if name in endpoints [port .port ]:
216
- endpoints [port .port ][name ].append (address .ip )
217
- else :
218
- endpoints [port .port ][name ] = [address .ip , ]
219
- else :
220
- endpoints [port .port ] = { name : [address .ip , ]}
221
- return {"TCP" : tcp_endpoints , "UDP" : udp_endpoints }
222
-
223
199
def _get_secret (self , namespace = None , name = 'tls-secret' ):
224
200
if namespace is None :
225
201
namespace = self .namespace
0 commit comments