Skip to content

Commit

Permalink
fix enabling of dns when running HA. (#1403)
Browse files Browse the repository at this point in the history
  • Loading branch information
balchua authored and ktsakalozos committed Jul 22, 2020
1 parent a26bbb5 commit a90763a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
25 changes: 25 additions & 0 deletions scripts/cluster/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import string
import random
import yaml
import socket


def try_set_file_permissions(file):
Expand Down Expand Up @@ -146,3 +147,27 @@ def get_cluster_agent_port():
if len(port_parse) > 1:
cluster_agent_port = port_parse[1].rstrip()
return cluster_agent_port


def get_internal_ip_from_get_node(node_info):
"""
Retrieves the InternalIp returned by kubectl get no -o json
"""
for status_addresses in node_info['status']['addresses']:
if status_addresses["type"] == "InternalIP":
return status_addresses["address"]


def is_same_server(hostname, ip):
"""
Check if the hostname is the same as the current node's hostname
"""
try:
hname, _, _ = socket.gethostbyaddr(ip)
if hname == hostname:
return True
except:
# Ignore any unresolvable IP by host, surely this is not from the same node.
pass

return False
15 changes: 9 additions & 6 deletions scripts/cluster/distributed_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
import json
import socket

from common.utils import is_node_running_dqlite
from common.utils import (
is_node_running_dqlite,
get_internal_ip_from_get_node,
is_same_server,
)

urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
CLUSTER_API = "cluster/api/v1.0"
Expand Down Expand Up @@ -39,13 +43,12 @@ def do_op(remote_op):
)
info = json.loads(nodes_info.decode())
for node_info in info["items"]:
node = node_info['metadata']['name']
# TODO: What if the user has set a hostname override in the kubelet args?
if node == hostname:
node_ip = get_internal_ip_from_get_node(node_info)
if is_same_server(hostname, node_ip):
continue
print("Configuring node {}".format(node))
print("Configuring node {}".format(node_ip))
# TODO: make port configurable
node_ep = "{}:{}".format(node, '25000')
node_ep = "{}:{}".format(node_ip, '25000')
remote_op["callback"] = token.rstrip()
# TODO: handle ssl verification
res = requests.post(
Expand Down

0 comments on commit a90763a

Please sign in to comment.