Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support InternalIP address for K8S nodes with no IP address of type ExternalDNS #316

Merged
merged 1 commit into from
Nov 16, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ def _pass_conflicts():


class KubernetesContainerManager(ContainerManager):
def __init__(self, kubernetes_api_ip, redis_ip=None, redis_port=6379):
def __init__(self,
kubernetes_api_ip,
redis_ip=None,
redis_port=6379,
useInternalIP=False):
"""
Parameters
----------
Expand All @@ -44,6 +48,9 @@ def __init__(self, kubernetes_api_ip, redis_ip=None, redis_port=6379):
redis_port : int, optional
The Redis port. If ``redis_ip`` is set to None, Clipper will start Redis on this port.
If ``redis_ip`` is provided, Clipper will connect to Redis on this port.
useInternalIP : bool, optional
Use Internal IP of the K8S nodes . If ``useInternalIP`` is set to False, Clipper will throw an exception, if none of the nodes have ExternalDNS .
If ``useInternalIP`` is set to true, Clipper will use the Internal IP of the K8S node if no ExternalDNS exists for any of the nodes.

Note
----
Expand All @@ -56,6 +63,7 @@ def __init__(self, kubernetes_api_ip, redis_ip=None, redis_port=6379):
self.kubernetes_api_ip = kubernetes_api_ip
self.redis_ip = redis_ip
self.redis_port = redis_port
self.useInternalIP = useInternalIP

config.load_kube_config()
configuration.assert_hostname = False
Expand Down Expand Up @@ -118,6 +126,12 @@ def connect(self):
for addr in node.status.addresses:
if addr.type == "ExternalDNS":
external_node_hosts.append(addr.address)
if len(external_node_hosts) == 0 and (self.useInternalIP):
msg = "No external node addresses found.Using Internal IP address"
logger.warn(msg)
for addr in node.status.addresses:
if addr.type == "InternalIP":
external_node_hosts.append(addr.address)
if len(external_node_hosts) == 0:
msg = "Error connecting to Kubernetes cluster. No external node addresses found"
logger.error(msg)
Expand Down