Skip to content

Commit

Permalink
Merge pull request #4217 from ingvagabund/move-etcd-upgrade-code-into…
Browse files Browse the repository at this point in the history
…-role

Move etcd upgrade code into role
  • Loading branch information
ingvagabund authored May 21, 2017
2 parents 22dfad7 + 4fcbe72 commit 4cd57c9
Show file tree
Hide file tree
Showing 22 changed files with 270 additions and 198 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
- name: Backup existing etcd CA certificate directories
hosts: oo_etcd_to_config
roles:
- etcd_common
- role: etcd_common
r_etcd_common_etcd_runtime: "{{ openshift.common.etcd_runtime }}"
tasks:
- name: Determine if CA certificate directory exists
stat:
Expand Down Expand Up @@ -52,7 +53,8 @@
vars:
etcd_ca_host: "{{ groups.oo_etcd_to_config.0 }}"
roles:
- etcd_common
- role: etcd_common
r_etcd_common_etcd_runtime: "{{ openshift.common.etcd_runtime }}"
tasks:
- name: Create a tarball of the etcd ca certs
command: >
Expand Down Expand Up @@ -98,7 +100,8 @@
- name: Retrieve etcd CA certificate
hosts: oo_first_etcd
roles:
- etcd_common
- role: etcd_common
r_etcd_common_etcd_runtime: "{{ openshift.common.etcd_runtime }}"
tasks:
- name: Retrieve etcd CA certificate
fetch:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
hosts: oo_first_etcd
any_errors_fatal: true
roles:
- etcd_common
- role: etcd_common
r_etcd_common_etcd_runtime: "{{ openshift.common.etcd_runtime }}"
post_tasks:
- name: Determine if generated etcd certificates exist
stat:
Expand All @@ -27,7 +28,8 @@
hosts: oo_etcd_to_config
any_errors_fatal: true
roles:
- etcd_common
- role: etcd_common
r_etcd_common_etcd_runtime: "{{ openshift.common.etcd_runtime }}"
post_tasks:
- name: Backup etcd certificates
command: >
Expand All @@ -50,6 +52,7 @@
etcd_peers: "{{ groups.oo_etcd_to_config | default([], true) }}"
etcd_certificates_etcd_hosts: "{{ groups.oo_etcd_to_config | default([], true) }}"
openshift_ca_host: "{{ groups.oo_first_master.0 }}"
r_etcd_common_etcd_runtime: "{{ openshift.common.etcd_runtime }}"

- name: Redeploy etcd client certificates for masters
hosts: oo_masters_to_config
Expand All @@ -63,4 +66,5 @@
etcd_cert_prefix: "master.etcd-"
openshift_ca_host: "{{ groups.oo_first_master.0 }}"
openshift_master_count: "{{ openshift.master.master_count | default(groups.oo_masters | length) }}"
r_etcd_common_etcd_runtime: "{{ openshift.common.etcd_runtime }}"
when: groups.oo_etcd_to_config is defined and groups.oo_etcd_to_config
86 changes: 8 additions & 78 deletions playbooks/common/openshift-cluster/upgrades/etcd/backup.yml
Original file line number Diff line number Diff line change
@@ -1,84 +1,14 @@
---
- name: Backup etcd
hosts: oo_etcd_hosts_to_backup
vars:
embedded_etcd: "{{ groups.oo_etcd_to_config | default([]) | length == 0 }}"
etcdctl_command: "{{ 'etcdctl' if not openshift.common.is_containerized or embedded_etcd else 'docker exec etcd_container etcdctl' if not openshift.common.is_etcd_system_container else 'runc exec etcd etcdctl' }}"
timestamp: "{{ lookup('pipe', 'date +%Y%m%d%H%M%S') }}"
roles:
- openshift_facts
tasks:
# Ensure we persist the etcd role for this host in openshift_facts
- openshift_facts:
role: etcd
local_facts: {}
when: "'etcd' not in openshift"
- set_fact:
etcd_backup_dir: "{{ openshift.etcd.etcd_data_dir }}/openshift-backup-{{ backup_tag | default('') }}{{ timestamp }}"

# TODO: replace shell module with command and update later checks
- name: Check available disk space for etcd backup
shell: df --output=avail -k {{ openshift.etcd.etcd_data_dir }} | tail -n 1
register: avail_disk
# AUDIT:changed_when: `false` because we are only inspecting
# state, not manipulating anything
changed_when: false

# TODO: replace shell module with command and update later checks
- name: Check current etcd disk usage
shell: du --exclude='*openshift-backup*' -k {{ openshift.etcd.etcd_data_dir }} | tail -n 1 | cut -f1
register: etcd_disk_usage
when: embedded_etcd | bool
# AUDIT:changed_when: `false` because we are only inspecting
# state, not manipulating anything
changed_when: false

- name: Abort if insufficient disk space for etcd backup
fail:
msg: >
{{ etcd_disk_usage.stdout }} Kb disk space required for etcd backup,
{{ avail_disk.stdout }} Kb available.
when: (embedded_etcd | bool) and (etcd_disk_usage.stdout|int > avail_disk.stdout|int)

# For non containerized and non embedded we should have the correct version of
# etcd installed already. So don't do anything.
#
# For containerized installs we now exec into etcd_container
#
# For embedded non containerized we need to ensure we have the latest version
# etcd on the host.
- name: Install latest etcd for embedded
package:
name: etcd
state: latest
when:
- embedded_etcd | bool
- not openshift.common.is_atomic | bool

- name: Generate etcd backup
command: >
{{ etcdctl_command }} backup --data-dir={{ openshift.etcd.etcd_data_dir }}
--backup-dir={{ etcd_backup_dir }}
# According to the docs change you can simply copy snap/db
# https://github.com/openshift/openshift-docs/commit/b38042de02d9780842dce95cfa0ef45d53b58bc6
- name: Check for v3 data store
stat:
path: "{{ openshift.etcd.etcd_data_dir }}/member/snap/db"
register: v3_db

- name: Copy etcd v3 data store
command: >
cp -a {{ openshift.etcd.etcd_data_dir }}/member/snap/db
{{ etcd_backup_dir }}/member/snap/
when: v3_db.stat.exists

- set_fact:
etcd_backup_complete: True

- name: Display location of etcd backup
debug:
msg: "Etcd backup created in {{ etcd_backup_dir }}"
- role: openshift_facts
- role: etcd_upgrade
r_etcd_upgrade_action: backup
r_etcd_backup_tag: etcd_backup_tag
r_etcd_common_etcd_runtime: "{{ openshift.common.etcd_runtime }}"
r_etcd_upgrade_embedded_etcd: "{{ groups.oo_etcd_to_config | default([]) | length == 0 }}"
r_etcd_backup_sufix_name: "{{ lookup('pipe', 'date +%Y%m%d%H%M%S') }}"

- name: Gate on etcd backup
hosts: localhost
Expand All @@ -88,7 +18,7 @@
- set_fact:
etcd_backup_completed: "{{ hostvars
| oo_select_keys(groups.oo_etcd_hosts_to_backup)
| oo_collect('inventory_hostname', {'etcd_backup_complete': true}) }}"
| oo_collect('inventory_hostname', {'r_etcd_upgrade_backup_complete': true}) }}"
- set_fact:
etcd_backup_failed: "{{ groups.oo_etcd_hosts_to_backup | difference(etcd_backup_completed) }}"
- fail:
Expand Down
23 changes: 0 additions & 23 deletions playbooks/common/openshift-cluster/upgrades/etcd/fedora_tasks.yml

This file was deleted.

2 changes: 1 addition & 1 deletion playbooks/common/openshift-cluster/upgrades/etcd/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
- name: Backup etcd before upgrading anything
include: backup.yml
vars:
backup_tag: "pre-upgrade-"
etcd_backup_tag: "pre-upgrade-"
when: openshift_etcd_backup | default(true) | bool

- name: Drop etcdctl profiles
Expand Down
20 changes: 0 additions & 20 deletions playbooks/common/openshift-cluster/upgrades/etcd/rhel_tasks.yml

This file was deleted.

87 changes: 30 additions & 57 deletions playbooks/common/openshift-cluster/upgrades/etcd/upgrade.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
# AUDIT:changed_when: `false` because we are only inspecting
# state, not manipulating anything
changed_when: false

- debug:
msg: "Etcd rpm version {{ etcd_rpm_version.stdout }} detected"
when: not openshift.common.is_containerized | bool
when:
- not openshift.common.is_containerized | bool

- block:
- name: Record containerized etcd version (docker)
Expand Down Expand Up @@ -54,84 +54,57 @@

- debug:
msg: "Etcd containerized version {{ etcd_container_version }} detected"

when:
- openshift.common.is_containerized | bool

# I really dislike this copy/pasta but I wasn't able to find a way to get it to loop
# through hosts, then loop through tasks only when appropriate
- name: Upgrade to 2.1
hosts: oo_etcd_hosts_to_upgrade
serial: 1
- include: upgrade_rpm_members.yml
vars:
upgrade_version: '2.1'
tasks:
- include: rhel_tasks.yml
when: etcd_rpm_version.stdout | default('99') | version_compare('2.1','<') and ansible_distribution == 'RedHat' and not openshift.common.is_containerized | bool
etcd_upgrade_version: '2.1'

- name: Upgrade RPM hosts to 2.2
hosts: oo_etcd_hosts_to_upgrade
serial: 1
- include: upgrade_rpm_members.yml
vars:
upgrade_version: '2.2'
tasks:
- include: rhel_tasks.yml
when: etcd_rpm_version.stdout | default('99') | version_compare('2.2','<') and ansible_distribution == 'RedHat' and not openshift.common.is_containerized | bool
etcd_upgrade_version: '2.2'

- name: Upgrade containerized hosts to 2.2.5
hosts: oo_etcd_hosts_to_upgrade
serial: 1
- include: upgrade_image_members.yml
vars:
upgrade_version: 2.2.5
tasks:
- include: containerized_tasks.yml
when: etcd_container_version | default('99') | version_compare('2.2','<') and openshift.common.is_containerized | bool
etcd_upgrade_version: '2.2.5'

- name: Upgrade RPM hosts to 2.3
hosts: oo_etcd_hosts_to_upgrade
serial: 1
- include: upgrade_rpm_members.yml
vars:
upgrade_version: '2.3'
tasks:
- include: rhel_tasks.yml
when: etcd_rpm_version.stdout | default('99') | version_compare('2.3','<') and ansible_distribution == 'RedHat' and not openshift.common.is_containerized | bool
etcd_upgrade_version: '2.3'

- name: Upgrade containerized hosts to 2.3.7
hosts: oo_etcd_hosts_to_upgrade
serial: 1
- include: upgrade_image_members.yml
vars:
upgrade_version: 2.3.7
tasks:
- include: containerized_tasks.yml
when: etcd_container_version | default('99') | version_compare('2.3','<') and openshift.common.is_containerized | bool
etcd_upgrade_version: '2.3.7'

- name: Upgrade RPM hosts to 3.0
hosts: oo_etcd_hosts_to_upgrade
serial: 1
- include: upgrade_rpm_members.yml
vars:
upgrade_version: '3.0'
tasks:
- include: rhel_tasks.yml
when: etcd_rpm_version.stdout | default('99') | version_compare('3.0','<') and ansible_distribution == 'RedHat' and not openshift.common.is_containerized | bool
etcd_upgrade_version: '3.0'

- name: Upgrade containerized hosts to etcd3 image
hosts: oo_etcd_hosts_to_upgrade
serial: 1
- include: upgrade_image_members.yml
vars:
upgrade_version: 3.0.15
tasks:
- include: containerized_tasks.yml
when: etcd_container_version | default('99') | version_compare('3.0','<') and openshift.common.is_containerized | bool
etcd_upgrade_version: '3.0.15'

- include: upgrade_rpm_members.yml
vars:
etcd_upgrade_version: '3.1'

- include: upgrade_image_members.yml
vars:
etcd_upgrade_version: '3.1.3'

- name: Upgrade fedora to latest
hosts: oo_etcd_hosts_to_upgrade
serial: 1
tasks:
- include: fedora_tasks.yml
when: ansible_distribution == 'Fedora' and not openshift.common.is_containerized | bool
- include_role:
name: etcd_upgrade
when:
- ansible_distribution == 'Fedora'
- not openshift.common.is_containerized | bool

- name: Backup etcd
include: backup.yml
vars:
backup_tag: "post-3.0-"
etcd_backup_tag: "post-3.0-"
when: openshift_etcd_backup | default(true) | bool
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
# INPUT etcd_upgrade_version
# INPUT etcd_container_version
# INPUT openshift.common.is_containerized
- name: Upgrade containerized hosts to {{ etcd_upgrade_version }}
hosts: oo_etcd_hosts_to_upgrade
serial: 1
roles:
- role: etcd_upgrade
r_etcd_upgrade_action: upgrade
r_etcd_upgrade_mechanism: image
r_etcd_upgrade_version: "{{ etcd_upgrade_version }}"
r_etcd_common_etcd_runtime: "{{ openshift.common.etcd_runtime }}"
etcd_peer: "{{ openshift.common.hostname }}"
when:
- etcd_container_version | default('99') | version_compare(etcd_upgrade_version,'<')
- openshift.common.is_containerized | bool
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
# INPUT etcd_upgrade_version
# INPUT etcd_rpm_version
# INPUT openshift.common.is_containerized
- name: Upgrade to {{ etcd_upgrade_version }}
hosts: oo_etcd_hosts_to_upgrade
serial: 1
roles:
- role: etcd_upgrade
r_etcd_upgrade_action: upgrade
r_etcd_upgrade_mechanism: rpm
r_etcd_upgrade_version: "{{ etcd_upgrade_version }}"
r_etcd_common_etcd_runtime: "host"
etcd_peer: "{{ openshift.common.hostname }}"
when:
- etcd_rpm_version.stdout | default('99') | version_compare(etcd_upgrade_version, '<')
- ansible_distribution == 'RedHat'
- not openshift.common.is_containerized | bool
1 change: 1 addition & 0 deletions playbooks/common/openshift-etcd/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
etcd_peers: "{{ groups.oo_etcd_to_config | default([], true) }}"
etcd_ca_host: "{{ groups.oo_etcd_to_config.0 }}"
etcd_certificates_etcd_hosts: "{{ groups.oo_etcd_to_config | default([], true) }}"
r_etcd_common_etcd_runtime: "{{ openshift.common.etcd_runtime }}"
- role: nickhammond.logrotate
6 changes: 0 additions & 6 deletions roles/etcd/defaults/main.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
---
etcd_service: "{{ 'etcd' if openshift.common.is_etcd_system_container | bool or not etcd_is_containerized | bool else 'etcd_container' }}"
etcd_client_port: 2379
etcd_peer_port: 2380
etcd_url_scheme: http
etcd_peer_url_scheme: http

etcd_initial_cluster_state: new
etcd_initial_cluster_token: etcd-cluster-1

Expand Down
Loading

0 comments on commit 4cd57c9

Please sign in to comment.