2016-07-08 09:59:21 +00:00
---
- name : "Pre-upgrade | check for kube-apiserver unit file"
stat :
path : /etc/systemd/system/kube-apiserver.service
register : kube_apiserver_service_file
2016-12-08 13:36:00 +00:00
tags : [ facts, kube-apiserver]
2016-07-08 09:59:21 +00:00
- name : "Pre-upgrade | check for kube-apiserver init script"
stat :
path : /etc/init.d/kube-apiserver
register : kube_apiserver_init_script
2016-12-08 13:36:00 +00:00
tags : [ facts, kube-apiserver]
2016-07-08 09:59:21 +00:00
- name : "Pre-upgrade | stop kube-apiserver if service defined"
service :
name : kube-apiserver
state : stopped
when : (kube_apiserver_service_file.stat.exists|default(False) or kube_apiserver_init_script.stat.exists|default(False))
2016-12-08 13:36:00 +00:00
tags : kube-apiserver
2016-11-10 09:49:47 +00:00
- name : "Pre-upgrade | remove kube-apiserver service definition"
file :
path : "{{ item }}"
state : absent
when : (kube_apiserver_service_file.stat.exists|default(False) or kube_apiserver_init_script.stat.exists|default(False))
with_items :
- /etc/systemd/system/kube-apiserver.service
- /etc/init.d/kube-apiserver
2016-12-08 13:36:00 +00:00
tags : kube-apiserver
2016-12-13 09:03:35 +00:00
- name : "Pre-upgrade | See if kube-apiserver manifest exists"
stat :
path : /etc/kubernetes/manifests/kube-apiserver.manifest
register : kube_apiserver_manifest
2017-03-06 10:22:13 +00:00
- name : "Pre-upgrade | etcd3 upgrade | see if old config exists"
command : "{{ bin_dir }}/etcdctl --peers={{ etcd_access_addresses }} ls /registry/minions"
environment :
ETCDCTL_API : 2
register : old_data_exists
2017-03-23 09:11:30 +00:00
delegate_to : "{{groups['etcd'][0]}}"
2017-03-06 10:22:13 +00:00
when : kube_apiserver_storage_backend == "etcd3"
failed_when : false
2017-08-20 10:54:28 +00:00
- name : "Pre-upgrade | etcd3 upgrade | use etcd2 unless forced to etcd3"
2017-03-30 13:08:13 +00:00
set_fact :
kube_apiserver_storage_backend : "etcd2"
when : old_data_exists.rc == 0 and not force_etcd3|bool
2017-03-06 10:22:13 +00:00
- name : "Pre-upgrade | etcd3 upgrade | see if data was already migrated"
command : "{{ bin_dir }}/etcdctl --endpoints={{ etcd_access_addresses }} get --limit=1 --prefix=true /registry/minions"
environment :
ETCDCTL_API : 3
register : data_migrated
delegate_to : "{{groups['etcd'][0]}}"
when : kube_apiserver_storage_backend == "etcd3"
failed_when : false
- name : "Pre-upgrade | etcd3 upgrade | set needs_etcd_migration"
set_fact :
2017-03-30 13:08:13 +00:00
needs_etcd_migration : "{{ force_etcd3|default(false) and kube_apiserver_storage_backend == 'etcd3' and data_migrated.stdout_lines|length == 0 and old_data_exists.rc == 0 }}"
2017-03-06 10:22:13 +00:00
2017-03-27 11:44:21 +00:00
- name : "Pre-upgrade | Delete master manifests on all kube-masters"
file :
path : "/etc/kubernetes/manifests/{{item[1]}}.manifest"
state : absent
2017-03-24 15:29:28 +00:00
delegate_to : "{{item[0]}}"
with_nested :
- "{{groups['kube-master']}}"
- [ "kube-apiserver" , "kube-controller-manager" , "kube-scheduler" ]
2016-12-13 09:03:35 +00:00
register : kube_apiserver_manifest_replaced
2017-03-06 10:22:13 +00:00
when : (secret_changed|default(false) or etcd_secret_changed|default(false) or needs_etcd_migration|bool) and kube_apiserver_manifest.stat.exists
2016-12-13 09:03:35 +00:00
2017-03-27 11:44:21 +00:00
- name : "Pre-upgrade | Delete master containers forcefully on all kube-masters"
shell : "docker ps -f name=k8s-{{item}}* -q | xargs --no-run-if-empty docker rm -f"
delegate_to : "{{item[0]}}"
with_nested :
- "{{groups['kube-master']}}"
- [ "kube-apiserver" , "kube-controller-manager" , "kube-scheduler" ]
register : kube_apiserver_manifest_replaced
when : (secret_changed|default(false) or etcd_secret_changed|default(false) or needs_etcd_migration|bool) and kube_apiserver_manifest.stat.exists
2017-07-27 17:46:21 +00:00
run_once : true
2016-12-13 09:03:35 +00:00
2017-03-06 10:22:13 +00:00
- name : "Pre-upgrade | etcd3 upgrade | stop etcd"
service :
name : etcd
state : stopped
delegate_to : "{{item}}"
with_items : "{{groups['etcd']}}"
when : needs_etcd_migration|bool
2017-07-27 17:46:21 +00:00
run_once : true
2017-03-06 10:22:13 +00:00
- name : "Pre-upgrade | etcd3 upgrade | migrate data"
command : "{{ bin_dir }}/etcdctl migrate --data-dir=\"{{ etcd_data_dir }}\" --wal-dir=\"{{ etcd_data_dir }}/member/wal\""
environment :
ETCDCTL_API : 3
delegate_to : "{{item}}"
with_items : "{{groups['etcd']}}"
register : etcd_migrated
when : needs_etcd_migration|bool
2017-07-27 17:46:21 +00:00
run_once : true
2017-03-06 10:22:13 +00:00
- name : "Pre-upgrade | etcd3 upgrade | start etcd"
service :
name : etcd
state : started
delegate_to : "{{item}}"
with_items : "{{groups['etcd']}}"
when : needs_etcd_migration|bool
2017-07-27 17:46:21 +00:00
run_once : true