From f343dbb05a0c1a901ff0dc6156a2f2fc51a492d4 Mon Sep 17 00:00:00 2001 From: "James E. Blair" Date: Fri, 13 Dec 2019 14:43:57 -0800 Subject: [PATCH] GCE: add use-internal-ip option This adds an option to the GCE driver to tell nodepool to use the private ip address even when an external one is provided. Also add a missing schema entry for rate-limit. Change-Id: Ib15bdc76fe500dc0fe6bb98f870514e9e157c1a5 --- doc/source/configuration.rst | 6 ++++++ nodepool/driver/gce/config.py | 6 ++++++ nodepool/driver/simple.py | 5 ++++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/doc/source/configuration.rst b/doc/source/configuration.rst index 554f4bdac..6e27568ea 100644 --- a/doc/source/configuration.rst +++ b/doc/source/configuration.rst @@ -2007,6 +2007,12 @@ section of the configuration. booted. This might be needed if nodepool-launcher and the nodes it launches are on different networks. The default value is True. + .. attr:: use-internal-ip + :default: False + + Whether to access the instance with the internal or external IP + address. + .. attr:: labels :type: list diff --git a/nodepool/driver/gce/config.py b/nodepool/driver/gce/config.py index a2d4dc793..e2e25d2fb 100644 --- a/nodepool/driver/gce/config.py +++ b/nodepool/driver/gce/config.py @@ -80,6 +80,7 @@ class ProviderPool(ConfigPool): def __init__(self): self.name = None self.host_key_checking = True + self.use_internal_ip = False self.labels = None # The ProviderConfig object that owns this pool. self.provider = None @@ -94,6 +95,8 @@ class ProviderPool(ConfigPool): self.host_key_checking = bool( pool_config.get('host-key-checking', True)) + self.use_internal_ip = bool( + pool_config.get('use-internal-ip', False)) for label in pool_config.get('labels', []): pl = ProviderLabel() @@ -124,6 +127,7 @@ class ProviderPool(ConfigPool): return (super().__eq__(other) and other.name == self.name and other.host_key_checking == self.host_key_checking + and other.use_internal_ip == self.use_internal_ip and other.labels == self.labels) return False @@ -218,6 +222,7 @@ class GCEProviderConfig(ProviderConfig): pool.update({ v.Required('name'): str, v.Required('labels'): [pool_label], + 'use-internal-ip': bool, }) provider_cloud_images = { @@ -239,6 +244,7 @@ class GCEProviderConfig(ProviderConfig): 'cloud-images': [provider_cloud_images], 'boot-timeout': int, 'launch-retries': int, + 'rate-limit': int, }) return v.Schema(provider) diff --git a/nodepool/driver/simple.py b/nodepool/driver/simple.py index aea9a6a25..71d3b268d 100644 --- a/nodepool/driver/simple.py +++ b/nodepool/driver/simple.py @@ -106,7 +106,10 @@ class SimpleTaskManagerLauncher(NodeLauncher): self.log.debug("Created instance %s", repr(instance)) - server_ip = instance.interface_ip + if self.pool.use_internal_ip: + server_ip = instance.private_ipv4 + else: + server_ip = instance.interface_ip self.node.connection_port = self.label.cloud_image.connection_port self.node.connection_type = self.label.cloud_image.connection_type