Skip to content

Commit 9833a7e

Browse files
Merge pull request openstack-k8s-operators#354 from rabi/ipv6
Make the probe healthcheck script ipv6 compatible
2 parents 5684983 + 8b3fd0d commit 9833a7e

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

templates/cinder/bin/healthcheck.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636

3737
from http import server
3838
import signal
39+
import socket
3940
import sys
4041
import time
4142
import threading
@@ -47,11 +48,12 @@
4748
from cinder import objects
4849

4950

50-
HOSTNAME = ''
5151
SERVER_PORT = 8080
5252
CONF = cfg.CONF
5353
BINARIES = ('volume', 'backup', 'scheduler')
5454

55+
class HTTPServerV6(server.HTTPServer):
56+
address_family = socket.AF_INET6
5557

5658
class HeartbeatServer(server.BaseHTTPRequestHandler):
5759
@classmethod
@@ -164,7 +166,12 @@ def stopper(signal_number=None, frame=None):
164166

165167
HeartbeatServer.initialize_class(binary)
166168

167-
webServer = server.HTTPServer((HOSTNAME, SERVER_PORT), HeartbeatServer)
169+
hostname = socket.gethostname()
170+
ipv6_address = socket.getaddrinfo(hostname, None, socket.AF_INET6)
171+
if ipv6_address:
172+
webServer = HTTPServerV6(("::",SERVER_PORT), HeartbeatServer)
173+
else:
174+
webServer = server.HTTPServer(("0.0.0.0", SERVER_PORT), HeartbeatServer)
168175
stop = get_stopper(webServer)
169176

170177
# Need to run the server on a different thread because its shutdown method
@@ -173,7 +180,7 @@ def stopper(signal_number=None, frame=None):
173180
thread = threading.Thread(target=webServer.serve_forever)
174181
thread.daemon = True
175182
thread.start()
176-
print(f"Cinder Healthcheck Server started http://{HOSTNAME}:{SERVER_PORT}")
183+
print(f"Cinder Healthcheck Server started http://{hostname}:{SERVER_PORT}")
177184
signal.signal(signal.SIGTERM, stop)
178185

179186
try:

0 commit comments

Comments
 (0)