Optimize reconfiguration for etcd
Co-Authored-By: caoyuan <cao.yuan@99cloud.net> Change-Id: I1cd494afd3a76e832272e70e9e1e5a41a522a31e Partially-implements: blueprint better-reconfigure
This commit is contained in:
parent
161491edc5
commit
b155ad5d96
@ -1,6 +1,30 @@
|
|||||||
---
|
---
|
||||||
project_name: "etcd"
|
project_name: "etcd"
|
||||||
|
|
||||||
|
etcd_services:
|
||||||
|
etcd:
|
||||||
|
container_name: etcd
|
||||||
|
group: etcd
|
||||||
|
enabled: true
|
||||||
|
environment:
|
||||||
|
ETCD_DATA_DIR: "/var/lib/etcd"
|
||||||
|
ETCD_NAME: "{{ ansible_hostname }}"
|
||||||
|
ETCD_ADVERTISE_CLIENT_URLS: "{{ internal_protocol }}://{{ hostvars[inventory_hostname]['ansible_' + api_interface]['ipv4']['address'] }}:{{ etcd_client_port }}"
|
||||||
|
ETCD_LISTEN_CLIENT_URLS: "{{ internal_protocol }}://{{ hostvars[inventory_hostname]['ansible_' + api_interface]['ipv4']['address'] }}:{{ etcd_client_port }}"
|
||||||
|
ETCD_INITIAL_ADVERTISE_PEER_URLS: "{{ internal_protocol }}://{{ hostvars[inventory_hostname]['ansible_' + api_interface]['ipv4']['address'] }}:{{ etcd_peer_port }}"
|
||||||
|
ETCD_LISTEN_PEER_URLS: "{{ internal_protocol }}://{{ hostvars[inventory_hostname]['ansible_' + api_interface]['ipv4']['address'] }}:{{ etcd_peer_port }}"
|
||||||
|
ETCD_INITIAL_CLUSTER_TOKEN: "{{ etcd_cluster_token }}"
|
||||||
|
ETCD_INITIAL_CLUSTER: "{% for host in groups['etcd'] %}{{ hostvars[host]['ansible_hostname'] }}={{ internal_protocol }}://{{ hostvars[host]['ansible_' + hostvars[host]['api_interface']]['ipv4']['address'] }}:{{ etcd_peer_port }}{% if not loop.last %},{% endif %}{% endfor %}"
|
||||||
|
ETCD_INITIAL_CLUSTER_STATE: "new"
|
||||||
|
ETCD_OUT_FILE: "/var/log/kolla/etcd/etcd.log"
|
||||||
|
KOLLA_CONFIG_STRATEGY: "{{ config_strategy }}"
|
||||||
|
image: "{{ etcd_image_full }}"
|
||||||
|
volumes:
|
||||||
|
- "{{ node_config_directory }}/etcd/:{{ container_config_directory }}/:ro"
|
||||||
|
- "/etc/localtime:/etc/localtime:ro"
|
||||||
|
- "kolla_etcd:/var/lib/etcd/"
|
||||||
|
- "kolla_logs:/var/log/kolla/"
|
||||||
|
|
||||||
|
|
||||||
####################
|
####################
|
||||||
# Docker
|
# Docker
|
||||||
|
19
ansible/roles/etcd/handlers/main.yml
Normal file
19
ansible/roles/etcd/handlers/main.yml
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
---
|
||||||
|
- name: Restart etcd container
|
||||||
|
vars:
|
||||||
|
service_name: "etcd"
|
||||||
|
service: "{{ etcd_services[service_name] }}"
|
||||||
|
config_json: "{{ etcd_config_jsons.results|selectattr('item.key', 'equalto', service_name)|first }}"
|
||||||
|
etcd_container: "{{ check_etcd_containers.results|selectattr('item.key', 'equalto', service_name)|first }}"
|
||||||
|
kolla_docker:
|
||||||
|
action: "recreate_or_restart_container"
|
||||||
|
common_options: "{{ docker_common_options }}"
|
||||||
|
name: "{{ service.container_name }}"
|
||||||
|
image: "{{ service.image }}"
|
||||||
|
volumes: "{{ service.volumes }}"
|
||||||
|
when:
|
||||||
|
- action != "config"
|
||||||
|
- inventory_hostname in groups[service.group]
|
||||||
|
- service.enabled | bool
|
||||||
|
- config_json.changed | bool
|
||||||
|
or etcd_container.changed | bool
|
@ -1,5 +1,7 @@
|
|||||||
---
|
---
|
||||||
- name: Running etcd bootstrap container
|
- name: Running etcd bootstrap container
|
||||||
|
vars:
|
||||||
|
etcd: "{{ etcd_services['etcd'] }}"
|
||||||
kolla_docker:
|
kolla_docker:
|
||||||
action: "start_container"
|
action: "start_container"
|
||||||
common_options: "{{ docker_common_options }}"
|
common_options: "{{ docker_common_options }}"
|
||||||
@ -7,13 +9,11 @@
|
|||||||
environment:
|
environment:
|
||||||
KOLLA_BOOTSTRAP:
|
KOLLA_BOOTSTRAP:
|
||||||
KOLLA_CONFIG_STRATEGY: "{{ config_strategy }}"
|
KOLLA_CONFIG_STRATEGY: "{{ config_strategy }}"
|
||||||
image: "{{ etcd_image_full }}"
|
image: "{{ etcd.image }}"
|
||||||
labels:
|
labels:
|
||||||
BOOTSTRAP:
|
BOOTSTRAP:
|
||||||
name: "bootstrap_etcd"
|
name: "bootstrap_etcd"
|
||||||
restart_policy: "never"
|
restart_policy: "never"
|
||||||
volumes:
|
volumes: "{{ etcd.volumes }}"
|
||||||
- "{{ node_config_directory }}/etcd/:{{ container_config_directory }}/:ro"
|
run_once: True
|
||||||
- "/etc/localtime:/etc/localtime:ro"
|
delegate_to: "{{ groups[etcd.group][0] }}"
|
||||||
- "kolla_etcd:/var/lib/etcd/"
|
|
||||||
- "kolla_logs:/var/log/kolla/"
|
|
||||||
|
@ -1,15 +1,38 @@
|
|||||||
---
|
---
|
||||||
- name: Ensuring config directories exist
|
- name: Ensuring config directories exist
|
||||||
file:
|
file:
|
||||||
path: "{{ node_config_directory }}/{{ item }}"
|
path: "{{ node_config_directory }}/{{ item.key }}"
|
||||||
state: "directory"
|
state: "directory"
|
||||||
recurse: yes
|
recurse: yes
|
||||||
with_items:
|
when:
|
||||||
- "etcd"
|
- inventory_hostname in groups[item.value.group]
|
||||||
|
- item.value.enabled | bool
|
||||||
|
with_dict: "{{ etcd_services }}"
|
||||||
|
|
||||||
- name: Copying over config.json files for services
|
- name: Copying over config.json files for services
|
||||||
template:
|
template:
|
||||||
src: "{{ item }}.json.j2"
|
src: "{{ item.key }}.json.j2"
|
||||||
dest: "{{ node_config_directory }}/{{ item }}/config.json"
|
dest: "{{ node_config_directory }}/{{ item.key }}/config.json"
|
||||||
with_items:
|
register: etcd_config_jsons
|
||||||
- "etcd"
|
when:
|
||||||
|
- inventory_hostname in groups[item.value.group]
|
||||||
|
- item.value.enabled | bool
|
||||||
|
with_dict: "{{ etcd_services }}"
|
||||||
|
notify:
|
||||||
|
- Restart etcd container
|
||||||
|
|
||||||
|
- name: Check etcd containers
|
||||||
|
kolla_docker:
|
||||||
|
action: "compare_container"
|
||||||
|
common_options: "{{ docker_common_options }}"
|
||||||
|
name: "{{ item.value.container_name }}"
|
||||||
|
image: "{{ item.value.image }}"
|
||||||
|
volumes: "{{ item.value.volumes }}"
|
||||||
|
register: check_etcd_containers
|
||||||
|
when:
|
||||||
|
- action != "config"
|
||||||
|
- inventory_hostname in groups[item.value.group]
|
||||||
|
- item.value.enabled | bool
|
||||||
|
with_dict: "{{ etcd_services }}"
|
||||||
|
notify:
|
||||||
|
- Restart etcd container
|
||||||
|
@ -3,4 +3,5 @@
|
|||||||
|
|
||||||
- include: bootstrap.yml
|
- include: bootstrap.yml
|
||||||
|
|
||||||
- include: start.yml
|
- name: Flush handlers
|
||||||
|
meta: flush_handlers
|
||||||
|
@ -3,4 +3,8 @@
|
|||||||
kolla_docker:
|
kolla_docker:
|
||||||
action: "pull_image"
|
action: "pull_image"
|
||||||
common_options: "{{ docker_common_options }}"
|
common_options: "{{ docker_common_options }}"
|
||||||
image: "{{ etcd_image_full }}"
|
image: "{{ item.value.image }}"
|
||||||
|
when:
|
||||||
|
- inventory_hostname in groups[item.value.group]
|
||||||
|
- item.value.enabled | bool
|
||||||
|
with_dict: "{{ etcd_services }}"
|
||||||
|
@ -1,64 +1,2 @@
|
|||||||
---
|
---
|
||||||
- name: Ensuring the containers up
|
- include: deploy.yml
|
||||||
kolla_docker:
|
|
||||||
name: "{{ item.name }}"
|
|
||||||
action: "get_container_state"
|
|
||||||
register: container_state
|
|
||||||
failed_when: container_state.Running == false
|
|
||||||
when: inventory_hostname in groups[item.group]
|
|
||||||
with_items:
|
|
||||||
- { name: etcd, group: etcd }
|
|
||||||
|
|
||||||
- include: config.yml
|
|
||||||
|
|
||||||
- name: Check the configs
|
|
||||||
command: docker exec {{ item.name }} /usr/local/bin/kolla_set_configs --check
|
|
||||||
changed_when: false
|
|
||||||
failed_when: false
|
|
||||||
register: check_results
|
|
||||||
when: inventory_hostname in groups[item.group]
|
|
||||||
with_items:
|
|
||||||
- { name: etcd, group: etcd }
|
|
||||||
|
|
||||||
# NOTE(jeffrey4l): when config_strategy == 'COPY_ALWAYS'
|
|
||||||
# and container env['KOLLA_CONFIG_STRATEGY'] == 'COPY_ONCE',
|
|
||||||
# just remove the container and start again
|
|
||||||
- name: Containers config strategy
|
|
||||||
kolla_docker:
|
|
||||||
name: "{{ item.name }}"
|
|
||||||
action: "get_container_env"
|
|
||||||
register: container_envs
|
|
||||||
when: inventory_hostname in groups[item.group]
|
|
||||||
with_items:
|
|
||||||
- { name: etcd, group: etcd }
|
|
||||||
|
|
||||||
- name: Remove the containers
|
|
||||||
kolla_docker:
|
|
||||||
name: "{{ item[0]['name'] }}"
|
|
||||||
action: "remove_container"
|
|
||||||
register: remove_containers
|
|
||||||
when:
|
|
||||||
- inventory_hostname in groups[item[0]['group']]
|
|
||||||
- config_strategy == "COPY_ONCE" or item[1]['KOLLA_CONFIG_STRATEGY'] == 'COPY_ONCE'
|
|
||||||
- item[2]['rc'] == 1
|
|
||||||
with_together:
|
|
||||||
- [{ name: etcd, group: etcd }]
|
|
||||||
- "{{ container_envs.results }}"
|
|
||||||
- "{{ check_results.results }}"
|
|
||||||
|
|
||||||
- include: start.yml
|
|
||||||
when: remove_containers.changed
|
|
||||||
|
|
||||||
- name: Restart containers
|
|
||||||
kolla_docker:
|
|
||||||
name: "{{ item[0]['name'] }}"
|
|
||||||
action: "restart_container"
|
|
||||||
when:
|
|
||||||
- inventory_hostname in groups[item[0]['group']]
|
|
||||||
- config_strategy == 'COPY_ALWAYS'
|
|
||||||
- item[1]['KOLLA_CONFIG_STRATEGY'] != 'COPY_ONCE'
|
|
||||||
- item[2]['rc'] == 1
|
|
||||||
with_together:
|
|
||||||
- [{ name: etcd, group: etcd }]
|
|
||||||
- "{{ container_envs.results }}"
|
|
||||||
- "{{ check_results.results }}"
|
|
||||||
|
@ -1,24 +0,0 @@
|
|||||||
---
|
|
||||||
- name: Starting etcd container
|
|
||||||
kolla_docker:
|
|
||||||
action: "start_container"
|
|
||||||
common_options: "{{ docker_common_options }}"
|
|
||||||
environment:
|
|
||||||
ETCD_DATA_DIR: "/var/lib/etcd"
|
|
||||||
ETCD_NAME: "{{ ansible_hostname }}"
|
|
||||||
ETCD_ADVERTISE_CLIENT_URLS: "{{ internal_protocol }}://{{ hostvars[inventory_hostname]['ansible_' + api_interface]['ipv4']['address'] }}:{{ etcd_client_port }}"
|
|
||||||
ETCD_LISTEN_CLIENT_URLS: "{{ internal_protocol }}://{{ hostvars[inventory_hostname]['ansible_' + api_interface]['ipv4']['address'] }}:{{ etcd_client_port }}"
|
|
||||||
ETCD_INITIAL_ADVERTISE_PEER_URLS: "{{ internal_protocol }}://{{ hostvars[inventory_hostname]['ansible_' + api_interface]['ipv4']['address'] }}:{{ etcd_peer_port }}"
|
|
||||||
ETCD_LISTEN_PEER_URLS: "{{ internal_protocol }}://{{ hostvars[inventory_hostname]['ansible_' + api_interface]['ipv4']['address'] }}:{{ etcd_peer_port }}"
|
|
||||||
ETCD_INITIAL_CLUSTER_TOKEN: "{{ etcd_cluster_token }}"
|
|
||||||
ETCD_INITIAL_CLUSTER: "{% for host in groups['etcd'] %}{{ hostvars[host]['ansible_hostname'] }}={{ internal_protocol }}://{{ hostvars[host]['ansible_' + hostvars[host]['api_interface']]['ipv4']['address'] }}:{{ etcd_peer_port }}{% if not loop.last %},{% endif %}{% endfor %}"
|
|
||||||
ETCD_INITIAL_CLUSTER_STATE: "new"
|
|
||||||
ETCD_OUT_FILE: "/var/log/kolla/etcd/etcd.log"
|
|
||||||
KOLLA_CONFIG_STRATEGY: "{{ config_strategy }}"
|
|
||||||
image: "{{ etcd_image_full }}"
|
|
||||||
name: "etcd"
|
|
||||||
volumes:
|
|
||||||
- "{{ node_config_directory }}/etcd/:{{ container_config_directory }}/:ro"
|
|
||||||
- "/etc/localtime:/etc/localtime:ro"
|
|
||||||
- "kolla_etcd:/var/lib/etcd/"
|
|
||||||
- "kolla_logs:/var/log/kolla/"
|
|
@ -1,4 +1,5 @@
|
|||||||
---
|
---
|
||||||
- include: config.yml
|
- include: config.yml
|
||||||
|
|
||||||
- include: start.yml
|
- name: Flush handlers
|
||||||
|
meta: flush_handlers
|
||||||
|
Loading…
Reference in New Issue
Block a user