robust handling of API server SANs (#4435)

* robust handling of API server SANs

* use apiserver_loadbalancer_domain_name if it is defined, according to PR 3977
This commit is contained in:
rptaylor 2019-04-08 08:10:35 -07:00 committed by Kubernetes Prow Robot
parent 09bbdadcee
commit f52584a715
5 changed files with 19 additions and 27 deletions

View file

@ -45,29 +45,21 @@
- name: kubeadm | aggregate all SANs - name: kubeadm | aggregate all SANs
set_fact: set_fact:
apiserver_sans: >- apiserver_sans: "{{ (sans_base + groups['kube-master'] + sans_lb + sans_supp + sans_access_ip + sans_ip + sans_address) | unique }}"
kubernetes vars:
kubernetes.default sans_base:
kubernetes.default.svc - "kubernetes"
kubernetes.default.svc.{{ dns_domain }} - "kubernetes.default"
{{ kube_apiserver_ip }} - "kubernetes.default.svc"
localhost - "kubernetes.default.svc.{{ dns_domain }}"
127.0.0.1 - "{{ kube_apiserver_ip }}"
{{ ' '.join(groups['kube-master']) }} - "localhost"
{%- if loadbalancer_apiserver is defined %} - "127.0.0.1"
{{ apiserver_loadbalancer_domain_name }} sans_lb: "{{ [apiserver_loadbalancer_domain_name] if apiserver_loadbalancer_domain_name is defined else [] }}"
{% endif %} sans_supp: "{{ supplementary_addresses_in_ssl_keys if supplementary_addresses_in_ssl_keys is defined else [] }}"
{% for host in groups['kube-master'] -%} sans_access_ip: "{{ groups['kube-master'] | map('extract', hostvars, 'access_ip') | list | select('defined') | list }}"
{%- if hostvars[host]['access_ip'] is defined %} sans_ip: "{{ groups['kube-master'] | map('extract', hostvars, 'ip') | list | select('defined') | list }}"
{{ hostvars[host]['access_ip'] }} sans_address: "{{ groups['kube-master'] | map('extract', hostvars, ['ansible_default_ipv4', 'address']) | list | select('defined') | list }}"
{% endif %}
{{ hostvars[host]['ip'] | default(fallback_ips[host]) }}
{%- endfor %}
{% if supplementary_addresses_in_ssl_keys is defined -%}
{% for addr in supplementary_addresses_in_ssl_keys %}
{{ addr }}
{% endfor %}
{%- endif %}
tags: facts tags: facts
- name: kubeadm | Copy etcd cert dir under k8s cert dir - name: kubeadm | Copy etcd cert dir under k8s cert dir

View file

@ -193,7 +193,7 @@ apiServerExtraVolumes:
{% endif %} {% endif %}
{% endif %} {% endif %}
apiServerCertSANs: apiServerCertSANs:
{% for san in apiserver_sans.split() | unique %} {% for san in apiserver_sans %}
- {{ san }} - {{ san }}
{% endfor %} {% endfor %}
certificatesDir: {{ kube_cert_dir }} certificatesDir: {{ kube_cert_dir }}

View file

@ -211,7 +211,7 @@ schedulerExtraArgs:
{% endfor %} {% endfor %}
{% endif %} {% endif %}
apiServerCertSANs: apiServerCertSANs:
{% for san in apiserver_sans.split() | unique %} {% for san in apiserver_sans %}
- {{ san }} - {{ san }}
{% endfor %} {% endfor %}
certificatesDir: {{ kube_cert_dir }} certificatesDir: {{ kube_cert_dir }}

View file

@ -43,7 +43,7 @@ controlPlaneEndpoint: {{ kubeadm_config_api_fqdn }}:{{ loadbalancer_apiserver.po
controlPlaneEndpoint: {{ ip | default(fallback_ips[inventory_hostname]) }}:{{ kube_apiserver_port }} controlPlaneEndpoint: {{ ip | default(fallback_ips[inventory_hostname]) }}:{{ kube_apiserver_port }}
{% endif %} {% endif %}
apiServerCertSANs: apiServerCertSANs:
{% for san in apiserver_sans.split() | unique %} {% for san in apiserver_sans %}
- {{ san }} - {{ san }}
{% endfor %} {% endfor %}
certificatesDir: {{ kube_cert_dir }} certificatesDir: {{ kube_cert_dir }}

View file

@ -176,7 +176,7 @@ apiServer:
{% endif %} {% endif %}
{% endif %} {% endif %}
certSANs: certSANs:
{% for san in apiserver_sans.split() | unique %} {% for san in apiserver_sans %}
- {{ san }} - {{ san }}
{% endfor %} {% endfor %}
timeoutForControlPlane: 5m0s timeoutForControlPlane: 5m0s