VOL-1727: K8S Liveness and Readiness Probes Added
Change-Id: I18748ebd35286d54d0bb9f0b083f3c69b97abdb5
diff --git a/python/ofagent/connection_mgr.py b/python/ofagent/connection_mgr.py
index 7e17613..a141946 100755
--- a/python/ofagent/connection_mgr.py
+++ b/python/ofagent/connection_mgr.py
@@ -37,6 +37,11 @@
# _ = third_party
class ConnectionManager(object):
+ running = False
+ channel = None
+ subscription = None
+ grpc_client = None
+
def __init__(self, consul_endpoint,
vcore_endpoint, vcore_grpc_timeout, vcore_binding_key,
vcore_transaction_key, controller_endpoints, instance_id,
@@ -78,6 +83,7 @@
log.debug('starting')
self.running = True
+ ConnectionManager.running = True
# Get a subscription to vcore
reactor.callInThread(self.get_vcore_subscription)
@@ -89,6 +95,16 @@
return self
+ @classmethod
+ def liveness_probe(cls):
+ # Pod restarts when liveness condition fails
+ return ConnectionManager.running
+
+ @classmethod
+ def readiness_probe(cls):
+ # Pod is isolated when readiness condition fails
+ return bool(ConnectionManager.channel and ConnectionManager.subscription and ConnectionManager.grpc_client)
+
def stop(self):
log.debug('stopping')
# clean up all controller connections
@@ -126,11 +142,14 @@
if self.channel is not None:
del self.channel
- self.is_alive = False
self.channel = None
self.subscription = None
self.grpc_client = None
+ ConnectionManager.channel = None
+ ConnectionManager.subscription = None
+ ConnectionManager.grpc_client = None
+
log.debug('stop-reset-grpc-attributes')
def _assign_grpc_attributes(self):
@@ -144,7 +163,9 @@
# Establish a connection to the vcore GRPC server
self.channel = grpc.insecure_channel('{}:{}'.format(host, port))
- self.is_alive = True
+
+ # For Readiness probe
+ ConnectionManager.channel = self.channel
log.debug('stop-assign-grpc-attributes')
@@ -167,6 +188,9 @@
subscription = yield self.grpc_client.subscribe(
OfAgentSubscriber(ofagent_id=container_name))
+ #For Readiness probes
+ ConnectionManager.subscription = subscription
+ ConnectionManager.grpc_client = self.grpc_client
# If the subscriber id matches the current instance
# ... then the subscription has succeeded
if subscription is not None and subscription.ofagent_id == container_name: