![Cole Walker](/assets/img/avatar_default.png)
Updates the locationservice, notificationservice and notificationclient containers to support ipv6 httpGet liveness probes. notificationservice-base and notificationservice-basev2: - Adds health.py which starts a simple http server that runs within the daemon. The k8s httpGet liveness probe can query this endpoint to verify that the service is running - Update the daemonset template and values to provide the required info for initalizing the new endpoint locationservice-base: - Remove unused portions of the locationservice_start.sh config map. The location-query-server.py and location-announce.py were never active and are not required - Add locationservice_start.py in order to start the locationservice pecan WSGI application with either an ipv4 or ipv6 socket - Use existing pecan endpoint to respond to liveness probes notificationclient-base: - Add notificationclient_start.py to start the notificationclient pecan WSGI application with either an ipv4 or ipv6 socket - Use existing pecan endpoint to respond to liveness probes Daemonset: - Add required ip and port environment variables to support liveness probes on each container - Add a conditional section for enabling liveness probes. Disabled by default but can be enabled via helm overrides by setting "liveness: True" Misc: - Re-organized python imports in affected files - Incremented helm chart version to 2.0.1 Test-plan: Pass: Verify application build and install Pass: Verify containers build correctly Pass: Deploy ptp-notification and verify basic sanity (v1 and v2 get, subscribe, delete, list) Pass: Enable httpGet liveness probes for each container and verify operation Pass: Verify application removal Story: 2011090 Task: 49851 Signed-off-by: Cole Walker <cole.walker@windriver.com> Change-Id: I4671c7f8c67c4869a6d5e3b384eae66d8c57a284
80 lines
2.0 KiB
Python
80 lines
2.0 KiB
Python
#
|
|
# Copyright (c) 2024 Wind River Systems, Inc.
|
|
#
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
#
|
|
|
|
import json
|
|
import logging
|
|
import os
|
|
import socket
|
|
import threading
|
|
from http.server import BaseHTTPRequestHandler, HTTPServer
|
|
|
|
from netaddr import IPAddress
|
|
from pecan.deploy import deploy
|
|
from trackingfunctionsdk.common.helpers import log_helper
|
|
|
|
LOG = logging.getLogger(__name__)
|
|
log_helper.config_logger(LOG)
|
|
|
|
HEALTH_API_HOST = os.environ.get(
|
|
"HEALTH_API_HOST", '127.0.0.1')
|
|
HEALTH_SERVICE_API_PORT = int(
|
|
os.environ.get("HEALTH_API_PORT", '8081'))
|
|
|
|
|
|
def get_address_family(ip_string):
|
|
"""
|
|
Get the family for the given ip address string.
|
|
"""
|
|
ip_address = IPAddress(ip_string)
|
|
if ip_address.version == 6:
|
|
return socket.AF_INET6
|
|
else:
|
|
return socket.AF_INET
|
|
|
|
|
|
class HealthRequestHandler(BaseHTTPRequestHandler):
|
|
|
|
def do_GET(self):
|
|
self.send_response(200)
|
|
self.send_header('Content-Type', 'application/json')
|
|
self.end_headers()
|
|
self.wfile.write(self.get_response().encode("utf-8"))
|
|
|
|
def do_POST(self):
|
|
self.do_GET()
|
|
|
|
def get_response(self):
|
|
"""
|
|
Return a simple confirmation if the process is running.
|
|
Can be extended to check broader health aspects of notification service as needed
|
|
"""
|
|
return json.dumps(
|
|
{'health': True}
|
|
)
|
|
|
|
|
|
class HealthServer:
|
|
def __init__(self):
|
|
HTTPServer.address_family = get_address_family(HEALTH_API_HOST)
|
|
self.health_server = HTTPServer(
|
|
(HEALTH_API_HOST, HEALTH_SERVICE_API_PORT), HealthRequestHandler)
|
|
self.thread = threading.Thread(target=self.health_server.serve_forever)
|
|
self.thread.daemon = True
|
|
|
|
def run(self):
|
|
self.thread.start()
|
|
return
|
|
|
|
|
|
if __name__ == "__main__":
|
|
my_health = HealthServer()
|
|
my_health.run()
|
|
print(
|
|
f"Health server running on {HEALTH_API_HOST}:{str(HEALTH_SERVICE_API_PORT)}")
|
|
while True:
|
|
# run indefinitely
|
|
pass
|