Browse Source

Remove templating for etcd members

Use a etcd-initer init container to generate etcd args, it determines
etcd name by comparing its ip and etcd cluster ips. This way will
make etcd configuration independent to the ansible templating so
that could be easier on adding master nodes.
pull/2037/head
Wei Tie 7 years ago
parent
commit
dad95c873b
4 changed files with 26 additions and 28 deletions
  1. 12
      roles/network_plugin/contiv/defaults/main.yml
  2. 6
      roles/network_plugin/contiv/tasks/main.yml
  3. 8
      roles/network_plugin/contiv/templates/contiv-etcd.env.j2
  4. 28
      roles/network_plugin/contiv/templates/contiv-etcd.yml.j2

12
roles/network_plugin/contiv/defaults/main.yml

@ -1,29 +1,19 @@
---
contiv_config_dir: "{{ kube_config_dir }}/contiv"
contiv_etcd_conf_dir: "/etc/contiv/etcd/"
contiv_etcd_conf_dir: "/etc/contiv/etcd"
contiv_etcd_data_dir: "/var/lib/etcd/contiv-data"
contiv_netmaster_port: 9999
contiv_cni_version: 0.1.0
contiv_etcd_image_repo: "{{ etcd_image_repo }}"
contiv_etcd_image_tag: "{{ etcd_image_tag }}"
contiv_etcd_listen_ip: "{{ ip | default(ansible_default_ipv4['address']) }}"
contiv_etcd_listen_port: 6666
contiv_etcd_peer_port: 6667
contiv_etcd_ad_urls: http://{{ contiv_etcd_listen_ip }}:{{ contiv_etcd_listen_port }}
contiv_etcd_peer_urls: http://{{ contiv_etcd_listen_ip }}:{{ contiv_etcd_peer_port }}
contiv_etcd_listen_urls:
- http://{{ contiv_etcd_listen_ip }}:{{ contiv_etcd_listen_port }}
- http://127.0.0.1:{{ contiv_etcd_listen_port }}
contiv_etcd_endpoints: |-
{% for host in groups['kube-master'] -%}
contiv_etcd{{ loop.index }}=http://{{ hostvars[host]['ip'] | default(hostvars[host].ansible_default_ipv4['address']) }}:{{ contiv_etcd_peer_port }}{% if not loop.last %},{% endif %}
{%- endfor %}
contiv_etcd_name: |-
{% for host in groups['kube-master'] %}
{% if host == inventory_hostname -%}contiv_etcd{{ loop.index }}{%- endif %}
{% endfor %}
# Parameters for Contiv api-proxy
contiv_enable_api_proxy: true

6
roles/network_plugin/contiv/tasks/main.yml

@ -17,12 +17,6 @@
- "{{ contiv_etcd_conf_dir }}"
- "{{ contiv_etcd_data_dir }}"
- name: Contiv | Create contiv etcd config env
template:
src: contiv-etcd.env.j2
dest: "{{ contiv_etcd_conf_dir }}/contiv-etcd.env"
when: inventory_hostname in groups['kube-master']
- set_fact:
contiv_config_dir: "{{ contiv_config_dir }}"
contiv_enable_api_proxy: "{{ contiv_enable_api_proxy }}"

8
roles/network_plugin/contiv/templates/contiv-etcd.env.j2

@ -1,8 +0,0 @@
# contiv etcd config
export ETCD_DATA_DIR=/var/lib/etcd/contiv-data
export ETCD_ADVERTISE_CLIENT_URLS={{ contiv_etcd_ad_urls }}
export ETCD_INITIAL_ADVERTISE_PEER_URLS={{ contiv_etcd_peer_urls }}
export ETCD_LISTEN_PEER_URLS={{ contiv_etcd_peer_urls }}
export ETCD_LISTEN_CLIENT_URLS={{ contiv_etcd_listen_urls | join(",") }}
export ETCD_NAME={{ contiv_etcd_name }}
export ETCD_INITIAL_CLUSTER={{ contiv_etcd_endpoints }}

28
roles/network_plugin/contiv/templates/contiv-etcd.yml.j2

@ -24,12 +24,34 @@ spec:
tolerations:
- key: node-role.kubernetes.io/master
effect: NoSchedule
initContainers:
- name: contiv-etcd-init
image: ferest/etcd-initer:latest
imagePullPolicy: Always
env:
- name: ETCD_INIT_ARGSFILE
value: '{{ contiv_etcd_conf_dir }}/contiv-etcd-args'
- name: ETCD_INIT_LISTEN_PORT
value: '{{ contiv_etcd_listen_port }}'
- name: ETCD_INIT_PEER_PORT
value: '{{ contiv_etcd_peer_port }}'
- name: ETCD_INIT_CLUSTER
value: '{{ contiv_etcd_endpoints }}'
- name: ETCD_INIT_DATA_DIR
value: '{{ contiv_etcd_data_dir }}'
volumeMounts:
- name: contiv-etcd-conf-dir
mountPath: {{ contiv_etcd_conf_dir }}
containers:
- name: contiv-etcd
image: {{ contiv_etcd_image_repo }}:{{ contiv_etcd_image_tag }}
command: ["sh","-c"]
args:
- '. {{ contiv_etcd_conf_dir }}/contiv-etcd.env && /usr/local/bin/etcd'
command:
- sh
- -c
- "/usr/local/bin/etcd $(cat $ETCD_INIT_ARGSFILE)"
env:
- name: ETCD_INIT_ARGSFILE
value: {{ contiv_etcd_conf_dir }}/contiv-etcd-args
volumeMounts:
- name: contiv-etcd-conf-dir
mountPath: {{ contiv_etcd_conf_dir }}

Loading…
Cancel
Save