net=host + resolv.conf workaround.

We're using service discovery with our net=host pods but resolv.conf
doesn't point at kube-dns when net=host. This provides a workaround.
You can do this by creating a configmap called resolv-conf with a
resolv.conf from a non net=host pod, and you set:

enable_resolve_conf_net_host_workaround="yes"

Change-Id: Ic2ac1725f42ba66b89cd5869f3ec3a751aa66df8
This commit is contained in:
Kevin Fox 2016-09-13 20:51:04 -07:00
parent 5a44ff5721
commit 51c8b7df96
6 changed files with 58 additions and 0 deletions

View File

@ -90,6 +90,14 @@ class ResourceTemplate(ResourceBase):
" The vars dict is created by merging configuration files "
" from several sources before applying the dict to itself.")
),
parser.add_argument(
"-o",
"--output",
metavar="output",
default="yaml",
help=("Format output into one of [%s]" % (
"|".join(['yaml', 'json'])))
),
parser.add_argument(
'--print-jinja-keys-regex',
metavar='<print-jinja-keys-regex>',
@ -150,6 +158,9 @@ class ResourceTemplate(ResourceBase):
if skip_and_return:
return res
if args.output == 'json':
res = json.dumps(yaml.load(res), indent=4)
print(res)

View File

@ -94,6 +94,11 @@ spec:
readOnly: true
- mountPath: /var/log/kolla/
name: kolla-logs
{%- if enable_resolve_conf_net_host_workaround == "yes" %}
- mountPath: /etc/resolv.conf
name: resolv-conf
subPath: resolv.conf
{%- endif %}
env:
- name: KOLLA_CONFIG_STRATEGY
value: {{ config_strategy }}
@ -128,3 +133,8 @@ spec:
path: /var/lib/neutron/kolla/metadata_proxy
- name: kolla-logs
emptyDir: {}
{%- if enable_resolve_conf_net_host_workaround == "yes" %}
- name: resolv-conf
configMap:
name: resolv-conf
{%- endif %}

View File

@ -110,6 +110,11 @@ spec:
readOnly: true
- mountPath: /var/log/kolla/
name: kolla-logs
{%- if enable_resolve_conf_net_host_workaround == "yes" %}
- mountPath: /etc/resolv.conf
name: resolv-conf
subPath: resolv.conf
{%- endif %}
env:
- name: KOLLA_CONFIG_STRATEGY
value: {{ config_strategy }}
@ -144,3 +149,8 @@ spec:
path: /var/lib/neutron/kolla/metadata_proxy
- name: kolla-logs
emptyDir: {}
{%- if enable_resolve_conf_net_host_workaround == "yes" %}
- name: resolv-conf
configMap:
name: resolv-conf
{%- endif %}

View File

@ -45,6 +45,11 @@ spec:
readOnly: true
- mountPath: /var/log/kolla/
name: kolla-logs
{%- if enable_resolve_conf_net_host_workaround == "yes" %}
- mountPath: /etc/resolv.conf
name: resolv-conf
subPath: resolv.conf
{%- endif %}
env:
- name: KOLLA_CONFIG_STRATEGY
value: {{ config_strategy }}
@ -75,3 +80,8 @@ spec:
path: /var/lib/neutron/kolla/metadata_proxy
- name: kolla-logs
emptyDir: {}
{%- if enable_resolve_conf_net_host_workaround == "yes" %}
- name: resolv-conf
configMap:
name: resolv-conf
{%- endif %}

View File

@ -99,6 +99,11 @@ spec:
readOnly: true
- mountPath: /var/log/kolla/
name: kolla-logs
{%- if enable_resolve_conf_net_host_workaround == "yes" %}
- mountPath: /etc/resolv.conf
name: resolv-conf
subPath: resolv.conf
{%- endif %}
# NOTE: (sbezverk) Linux bridge will be moved to its own file at the time of development
# keeping it here just for future reference.
@ -164,3 +169,8 @@ spec:
path: /lib/modules
- name: kolla-logs
emptyDir: {}
{%- if enable_resolve_conf_net_host_workaround == "yes" %}
- name: resolv-conf
configMap:
name: resolv-conf
{%- endif %}

7
tools/setup-resolv-conf.sh Executable file
View File

@ -0,0 +1,7 @@
#!/bin/bash
NAMESPACE=$(kolla-kubernetes resource-template create bootstrap neutron-create-db -o json | jq -r '.metadata.namespace')
TOOLBOX=$(kolla-kubernetes resource-template create bootstrap neutron-create-db -o json | jq -r '.spec.template.spec.containers[0].image')
kubectl run -i --rm fetchresolv --restart=Never --namespace=$NAMESPACE --image=$TOOLBOX -- /bin/bash -c 'cat /etc/resolv.conf' | egrep '^search|^nameserver|^options' > /tmp/$$
kubectl create configmap resolv-conf --from-file=resolv.conf=/tmp/$$ --namespace $NAMESPACE
rm -f /tmp/$$