Merge "Add source to Events"
This commit is contained in:
commit
6128e8fa7e
@ -18,7 +18,6 @@ from http import client as httplib
|
||||
import multiprocessing
|
||||
import os
|
||||
import queue
|
||||
import socket
|
||||
import sys
|
||||
import threading
|
||||
import time
|
||||
@ -262,23 +261,13 @@ class CNIDaemonWatcherService(cotyledon.Service):
|
||||
self.registry = registry
|
||||
self.healthy = healthy
|
||||
|
||||
def _get_nodename(self):
|
||||
# NOTE(dulek): At first try to get it using environment variable,
|
||||
# otherwise assume hostname is the nodename.
|
||||
try:
|
||||
nodename = os.environ['KUBERNETES_NODE_NAME']
|
||||
except KeyError:
|
||||
# NOTE(dulek): By default K8s nodeName is lowercased hostname.
|
||||
nodename = socket.gethostname().lower()
|
||||
return nodename
|
||||
|
||||
def run(self):
|
||||
self.pipeline = h_cni.CNIPipeline()
|
||||
self.pipeline.register(h_cni.CallbackHandler(self.on_done,
|
||||
self.on_deleted))
|
||||
self.watcher = k_watcher.Watcher(self.pipeline)
|
||||
query_label = urllib.parse.quote_plus(f'{k_const.KURYRPORT_LABEL}='
|
||||
f'{self._get_nodename()}')
|
||||
f'{utils.get_nodename()}')
|
||||
|
||||
self.watcher.add(f'{k_const.K8S_API_CRD_KURYRPORTS}'
|
||||
f'?labelSelector={query_label}')
|
||||
|
@ -101,13 +101,14 @@ class K8sCNIRegistryPlugin(base_cni.CNIPlugin):
|
||||
try:
|
||||
self.k8s.add_event(pod, 'CNIWaitingForVIFs',
|
||||
f'Waiting for Neutron ports of {kp_name} to '
|
||||
f'become ACTIVE after binding.')
|
||||
f'become ACTIVE after binding.',
|
||||
component='kuryr-daemon')
|
||||
vifs = wait_for_active(kp_name)
|
||||
except retrying.RetryError:
|
||||
self.k8s.add_event(pod, 'CNITimedOutWaitingForVIFs',
|
||||
f'Timed out waiting for Neutron ports of '
|
||||
f'{kp_name} to become ACTIVE after binding.',
|
||||
'Warning')
|
||||
'Warning', 'kuryr-daemon')
|
||||
raise exceptions.CNINeutronPortActivationTimeout(
|
||||
kp_name, self.registry[kp_name]['vifs'])
|
||||
|
||||
@ -189,7 +190,8 @@ class K8sCNIRegistryPlugin(base_cni.CNIPlugin):
|
||||
self.k8s.add_event(pod, 'CNITimeoutKuryrPortRegistry',
|
||||
f'Timed out waiting for Neutron ports to be '
|
||||
f'created for {kp_name}. Check '
|
||||
f'kuryr-controller logs.', 'Warning')
|
||||
f'kuryr-controller logs.', 'Warning',
|
||||
'kuryr-daemon')
|
||||
raise exceptions.CNIKuryrPortTimeout(kp_name)
|
||||
|
||||
for ifname, vif in vifs.items():
|
||||
|
@ -449,7 +449,8 @@ class K8sClient(object):
|
||||
time.sleep(t)
|
||||
attempt += 1
|
||||
|
||||
def add_event(self, resource, reason, message, type_='Normal'):
|
||||
def add_event(self, resource, reason, message, type_='Normal',
|
||||
component='kuryr-controller'):
|
||||
"""Create an Event object for the provided resource."""
|
||||
if not self.are_events_enabled:
|
||||
return {}
|
||||
@ -478,7 +479,9 @@ class K8sClient(object):
|
||||
'reason': reason,
|
||||
'message': message,
|
||||
'type': type_,
|
||||
'involvedObject': involved_object}
|
||||
'involvedObject': involved_object,
|
||||
'source': {'component': component,
|
||||
'host': utils.get_nodename()}}
|
||||
|
||||
try:
|
||||
return self.post(f'{constants.K8S_API_BASE}/namespaces/'
|
||||
|
@ -11,6 +11,7 @@
|
||||
# under the License.
|
||||
|
||||
import ipaddress
|
||||
import os
|
||||
import random
|
||||
import re
|
||||
import socket
|
||||
@ -664,6 +665,17 @@ def is_host_network(pod):
|
||||
return pod['spec'].get('hostNetwork', False)
|
||||
|
||||
|
||||
def get_nodename():
|
||||
# NOTE(dulek): At first try to get it using environment variable,
|
||||
# otherwise assume hostname is the nodename.
|
||||
try:
|
||||
nodename = os.environ['KUBERNETES_NODE_NAME']
|
||||
except KeyError:
|
||||
# NOTE(dulek): By default K8s nodeName is lowercased hostname.
|
||||
nodename = socket.gethostname().lower()
|
||||
return nodename
|
||||
|
||||
|
||||
def get_referenced_object(obj, kind):
|
||||
"""Get referenced object.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user