Skip to content

Commit

Permalink
Always backup both certs and kubeconfig
Browse files Browse the repository at this point in the history
There are no reasons not to backup during upgrade

Signed-off-by: Etienne Champetier <[email protected]>
  • Loading branch information
champtar authored and k8s-ci-robot committed Mar 5, 2021
1 parent 8800b5c commit 53e5ef6
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 21 deletions.
28 changes: 28 additions & 0 deletions roles/kubernetes/control-plane/tasks/kubeadm-backup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
- name: Backup old certs and keys
copy:
src: "{{ kube_cert_dir }}/{{ item }}"
dest: "{{ kube_cert_dir }}/{{ item }}.old"
mode: preserve
remote_src: yes
with_items:
- apiserver.crt
- apiserver.key
- apiserver-kubelet-client.crt
- apiserver-kubelet-client.key
- front-proxy-client.crt
- front-proxy-client.key
ignore_errors: yes

- name: Backup old confs
copy:
src: "{{ kube_config_dir }}/{{ item }}"
dest: "{{ kube_config_dir }}/{{ item }}.old"
mode: preserve
remote_src: yes
with_items:
- admin.conf
- controller-manager.conf
- kubelet.conf
- scheduler.conf
ignore_errors: yes
15 changes: 0 additions & 15 deletions roles/kubernetes/control-plane/tasks/kubeadm-certificate.yml

This file was deleted.

11 changes: 5 additions & 6 deletions roles/kubernetes/control-plane/tasks/kubeadm-setup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
get_mime: no
register: kubeadm_already_run

- name: kubeadm | Backup kubeadm certs / kubeconfig
import_tasks: kubeadm-backup.yml
when:
- kubeadm_already_run.stat.exists

- name: kubeadm | aggregate all SANs
set_fact:
apiserver_sans: "{{ (sans_base + groups['kube-master'] + sans_lb + sans_lb_ip + sans_supp + sans_access_ip + sans_ip + sans_address + sans_override + sans_hostname + sans_fqdn) | unique }}"
Expand Down Expand Up @@ -68,12 +73,6 @@
- name: kubeadm | set kubeadm version
import_tasks: kubeadm-version.yml

- name: kubeadm | Certificate management with kubeadm
import_tasks: kubeadm-certificate.yml
when:
- not upgrade_cluster_setup
- kubeadm_already_run.stat.exists

- name: kubeadm | Check if apiserver.crt contains all needed SANs
command: openssl x509 -noout -in "{{ kube_cert_dir }}/apiserver.crt" -check{{ item|ipaddr|ternary('ip','host') }} "{{ item }}"
with_items: "{{ apiserver_sans }}"
Expand Down

0 comments on commit 53e5ef6

Please sign in to comment.