Add optional external_ip to promjoin

Adds an optional external_ip parameter to the prom join script API,
and to the Genesis and KubernetesNode schema.
This is used to populate the host's IP address in its /etc/hosts
file if present, according to normal hosts conventions.
If the value is not passed to prom-join or is absent from a
Genesis or KubernetesNode document, then the hosts file defaults
to the current loopback IP for the hostname (business as usual).

Change-Id: I58dc219923b18aaf9c83453b896ce509664d8766
This commit is contained in:
Matt McEuen 2019-04-04 20:09:49 -05:00
parent f85687607c
commit c18e3a8d9d
9 changed files with 19 additions and 2 deletions

View File

@ -10,6 +10,7 @@ metadata:
data: data:
hostname: n0 hostname: n0
ip: 192.168.77.10 ip: 192.168.77.10
external_ip: 192.168.77.10
apiserver: apiserver:
arguments: arguments:
- --authorization-mode=Node,RBAC - --authorization-mode=Node,RBAC

View File

@ -10,6 +10,7 @@ metadata:
data: data:
hostname: n0 hostname: n0
ip: 192.168.77.10 ip: 192.168.77.10
external_ip: 192.168.77.10
armada: armada:
target_manifest: cluster-bootstrap target_manifest: cluster-bootstrap
labels: labels:

View File

@ -36,7 +36,10 @@ class JoinScriptsResource(BaseResource):
def on_get(self, req, resp): def on_get(self, req, resp):
leave_kubectl = req.get_param_as_bool('leave_kubectl') leave_kubectl = req.get_param_as_bool('leave_kubectl')
design_ref = req.get_param('design_ref', required=True) design_ref = req.get_param('design_ref', required=True)
# The required IP address to be used by Kubernetes itself
ip = req.get_param('ip', required=True) ip = req.get_param('ip', required=True)
# The optional IP address to configure as externally-routable
external_ip = req.get_param('external_ip', default='127.0.0.1')
hostname = req.get_param('hostname', required=True) hostname = req.get_param('hostname', required=True)
# NOTE(sh8121att): Set a default here for backward compatability # NOTE(sh8121att): Set a default here for backward compatability
dns_domain = req.get_param('domain', default='local') dns_domain = req.get_param('domain', default='local')
@ -73,6 +76,7 @@ class JoinScriptsResource(BaseResource):
'hostname': hostname, 'hostname': hostname,
'domain': dns_domain, 'domain': dns_domain,
'ip': ip, 'ip': ip,
'external_ip': external_ip,
'join_ips': join_ips, 'join_ips': join_ips,
'labels': { 'labels': {
'dynamic': dynamic_labels, 'dynamic': dynamic_labels,

View File

@ -91,6 +91,9 @@ data:
ip: ip:
$ref: '#/definitions/ip_address' $ref: '#/definitions/ip_address'
external_ip:
$ref: '#/definitions/ip_address'
labels: labels:
properties: properties:
static: static:

View File

@ -26,6 +26,9 @@ data:
ip: ip:
$ref: '#/definitions/ip_address' $ref: '#/definitions/ip_address'
external_ip:
$ref: '#/definitions/ip_address'
domain: domain:
type: string type: string

View File

@ -1,7 +1,7 @@
# This file is controlled by Promenade. Do not modify. # This file is controlled by Promenade. Do not modify.
# #
127.0.0.1 {{ config.get_first('Genesis:hostname', 'KubernetesNode:hostname') }}.{{ config.get_first('Genesis:domain', 'KubernetesNode:domain', default='local') }} {{ config.get_first('Genesis:hostname', 'KubernetesNode:hostname') }}
127.0.0.1 localhost 127.0.0.1 localhost
{{ config.get_first('Genesis:external_ip', 'KubernetesNode:external_ip', default='127.0.0.1') }} {{ config.get_first('Genesis:hostname', 'KubernetesNode:hostname') }}.{{ config.get_first('Genesis:domain', 'KubernetesNode:domain', default='local') }} {{ config.get_first('Genesis:hostname', 'KubernetesNode:hostname') }}
{%- for entry in config.get_path('KubernetesNetwork:hosts_entries', []) %} {%- for entry in config.get_path('KubernetesNetwork:hosts_entries', []) %}
{{ entry['ip'] }} {{ entry['names'] | join(' ') }} {{ entry['ip'] }} {{ entry['names'] | join(' ') }}
{%- endfor %} {%- endfor %}

View File

@ -24,7 +24,7 @@ promenade_render_curl_url() {
else else
DESIGN_REF="design_ref=${NGINX_URL}/promenade.yaml" DESIGN_REF="design_ref=${NGINX_URL}/promenade.yaml"
fi fi
HOST_PARAMS="hostname=${NAME}&ip=$(config_vm_ip "${NAME}")" HOST_PARAMS="hostname=${NAME}&ip=$(config_vm_ip "${NAME}")&external_ip=$(config_vm_ip "${NAME}")"
echo "${BASE_URL}?${DESIGN_REF}&${HOST_PARAMS}&leave_kubectl=true${LABEL_PARAMS}" echo "${BASE_URL}?${DESIGN_REF}&${HOST_PARAMS}&leave_kubectl=true${LABEL_PARAMS}"
} }

View File

@ -10,6 +10,7 @@ metadata:
data: data:
hostname: ${GENESIS_HOSTNAME} hostname: ${GENESIS_HOSTNAME}
ip: ${GENESIS_IP} ip: ${GENESIS_IP}
external_ip: ${GENESIS_IP}
labels: labels:
dynamic: dynamic:
- calico-etcd=enabled - calico-etcd=enabled

View File

@ -10,6 +10,7 @@ metadata:
data: data:
hostname: ${GENESIS_HOSTNAME} hostname: ${GENESIS_HOSTNAME}
ip: ${GENESIS_IP} ip: ${GENESIS_IP}
external_ip: ${GENESIS_IP}
join_ip: ${MASTER1_IP} join_ip: ${MASTER1_IP}
labels: labels:
dynamic: dynamic:
@ -40,6 +41,7 @@ metadata:
data: data:
hostname: ${MASTER1_HOSTNAME} hostname: ${MASTER1_HOSTNAME}
ip: ${MASTER1_IP} ip: ${MASTER1_IP}
external_ip: ${MASTER1_IP}
join_ip: ${GENESIS_IP} join_ip: ${GENESIS_IP}
labels: labels:
dynamic: dynamic:
@ -70,6 +72,7 @@ metadata:
data: data:
hostname: ${MASTER2_HOSTNAME} hostname: ${MASTER2_HOSTNAME}
ip: ${MASTER2_IP} ip: ${MASTER2_IP}
external_ip: ${MASTER2_IP}
join_ips: join_ips:
- ${GENESIS_IP} - ${GENESIS_IP}
- ${MASTER1_IP} - ${MASTER1_IP}
@ -102,6 +105,7 @@ metadata:
data: data:
hostname: ${WORKER_HOSTNAME} hostname: ${WORKER_HOSTNAME}
ip: ${WORKER_IP} ip: ${WORKER_IP}
external_ip: ${WORKER_IP}
join_ips: join_ips:
- ${GENESIS_IP} - ${GENESIS_IP}
- ${MASTER1_IP} - ${MASTER1_IP}