c12s-kubespray/roles/kubernetes/node/tasks/pre_upgrade.yml

48 lines
1.6 KiB
YAML
Raw Normal View History

---
2020-08-05 14:56:28 +00:00
- name: "Pre-upgrade | check if kubelet container exists"
shell: >-
2020-08-05 14:56:28 +00:00
set -o pipefail &&
2020-02-07 10:19:43 +00:00
{% if container_manager in ['crio', 'docker'] %}
{{ docker_bin_dir }}/docker ps -af name=kubelet | grep kubelet
{% elif container_manager == 'containerd' %}
{{ bin_dir }}/crictl ps --all --name kubelet | grep kubelet
{% endif %}
2020-08-05 14:56:28 +00:00
args:
executable: /bin/bash
failed_when: false
changed_when: false
register: kubelet_container_check
- name: "Pre-upgrade | copy /var/lib/cni from kubelet"
command: >-
2020-02-07 10:19:43 +00:00
{% if container_manager in ['crio', 'docker'] %}
docker cp kubelet:/var/lib/cni /var/lib/cni
{% elif container_manager == 'containerd' %}
ctr run --rm --mount type=bind,src=/var/lib/cni,dst=/cnilibdir,options=rbind:rw kubelet kubelet-tmp sh -c 'cp /var/lib/cni/* /cnilibdir/'
{% endif %}
args:
creates: "/var/lib/cni"
failed_when: false
when: kubelet_container_check.rc == 0
- name: "Pre-upgrade | ensure kubelet container service is stopped if using host deployment"
service:
name: kubelet
state: stopped
when: kubelet_container_check.rc == 0
- name: "Pre-upgrade | ensure kubelet container is removed if using host deployment"
shell: >-
2020-02-07 10:19:43 +00:00
{% if container_manager in ['crio', 'docker'] %}
{{ docker_bin_dir }}/docker rm -fv kubelet
{% elif container_manager == 'containerd' %}
{{ bin_dir }}/crictl stop kubelet && {{ bin_dir }}/crictl rm kubelet
{% endif %}
failed_when: false
2017-10-25 20:19:40 +00:00
changed_when: false
register: remove_kubelet_container
retries: 4
until: remove_kubelet_container.rc == 0
delay: 5
when: kubelet_container_check.rc == 0