Skip to content

Commit

Permalink
* separate get and set cluster version tasks
Browse files Browse the repository at this point in the history
* introduce initial_cluster_version used to evaluate need of
  an upgrade

Signed-off-by: cicharka <[email protected]>
  • Loading branch information
cicharka committed Jan 3, 2022
1 parent 6211265 commit 15537d7
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 46 deletions.
3 changes: 1 addition & 2 deletions ansible/playbooks/roles/upgrade/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,4 @@ opendistro_for_elasticsearch:
upgrade_state_file_path: /etc/elasticsearch/epicli-upgrade-started.state

kubernetes:
upgrade_master_state_file_path: /var/lib/epiphany/upgrade/state/kubernetes-master-{{ ver }}.uncompleted
upgrade_node_state_file_path: /var/lib/epiphany/upgrade/state/kubernetes-node-{{ ver }}.uncompleted
upgrade_state_file_path: /var/lib/epiphany/upgrade/state/kubernetes-{{ ver }}.uncompleted
62 changes: 35 additions & 27 deletions ansible/playbooks/roles/upgrade/tasks/kubernetes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,35 +18,45 @@
import_tasks: kubernetes/utils/wait-for-kube-apiserver.yml

- name: k8s | Include get-cluster-version.yml
import_tasks: kubernetes/get-cluster-version.yml # sets cluster_version
import_tasks: kubernetes/get-cluster-version.yml

- name: k8s | Set cluster version facts
set_fact:
initial_cluster_version: "{{ _cluster_version }}"
cluster_version: "{{ _cluster_version }}"
vars:
_cluster_version: "{{ (kubectl_cluster_version.stdout | from_yaml).serverVersion.gitVersion }}"

- name: k8s | Include get-kubelet-version.yml
import_tasks: kubernetes/get-kubelet-version.yml # sets kubelet_version
import_tasks: kubernetes/get-kubelet-version.yml
delegate_to: "{{ groups.kubernetes_master[0] }}"

- name: Check upgrade state file for master
stat:
path: "{{ kubernetes.upgrade_master_state_file_path }}"
register: upgrade_master_state_file_status
- name: k8s | Set kubelet version as fact
set_fact:
initial_kubelet_version: "{{ kubelet_version.stdout }}"

- name: Check upgrade state file for node
- name: Check if upgrade state file exists
stat:
path: "{{ kubernetes.upgrade_node_state_file_path }}"
register: upgrade_node_state_file_status
path: "{{ kubernetes.upgrade_state_file_path }}"
get_attributes: false
get_checksum: false
get_mime: false
register: k8s_upgrade_state_file_status

- name: Upgrade masters then nodes
vars:
version: "{{ ver }}"
cni_version: "{{ cni_ver }}"
block:
- name: Upgrade masters
when: >
upgrade_master_state_file_status.stat.exists or
cluster_version is version('v' + version, '<')
when:
- inventory_hostname in groups.kubernetes_master
- k8s_upgrade_state_file_status.stat.exists
or initial_cluster_version is version('v' + version, '<')
block:
- name: Create k8s upgrade state file for masters
- name: Create K8s upgrade state file on master node
copy:
dest: "{{ kubernetes.upgrade_master_state_file_path }}"
dest: "{{ kubernetes.upgrade_state_file_path }}"
content: Upgrade started
mode: u=rw,g=r,o=

Expand All @@ -60,34 +70,32 @@
when:
- inventory_hostname in groups.kubernetes_master[1:]

- name: Remove k8s upgrade state file for masters
- name: Remove K8s upgrade state file on master node
file:
path: "{{ kubernetes.upgrade_master_state_file_path }}"
path: "{{ kubernetes.upgrade_state_file_path }}"
state: absent

- name: Upgrade nodes
when: >
upgrade_node_state_file_status.stat.exists or
kubelet_version is version('v' + version, '<')
when:
- groups.kubernetes_node is defined
- inventory_hostname in groups.kubernetes_node
- k8s_upgrade_state_file_status.stat.exists
or initial_kubelet_version is version('v' + version, '<')
block:
- name: Create k8s upgrade state file for nodes
- name: Create K8s upgrade state file on node
copy:
dest: "{{ kubernetes.upgrade_node_state_file_path }}"
dest: "{{ kubernetes.upgrade_state_file_path }}"
content: Upgrade started
mode: u=rw,g=r,o=

- name: k8s | Upgrade node to v{{ version }}
include_tasks: kubernetes/upgrade-node.yml
when:
- groups.kubernetes_node is defined
- inventory_hostname in groups.kubernetes_node

- name: Remove k8s upgrade state file for nodes
- name: Remove K8s upgrade state file on node
file:
path: "{{ kubernetes.upgrade_node_state_file_path }}"
path: "{{ kubernetes.upgrade_state_file_path }}"
state: absent


- name: k8s/master | Switch apiserver address to HAProxy
command: |-
kubectl config set-cluster {{ kubectl_context_cluster.stdout }} --server=https://localhost:3446
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,3 @@
retries: 60
delay: 5
changed_when: false

- name: Set cluster version as fact
set_fact:
cluster_version: >-
{{ (kubectl_cluster_version.stdout | from_yaml).serverVersion.gitVersion }}
cluster_version_major: >-
{{ (kubectl_cluster_version.stdout | from_yaml).serverVersion.major }}
cluster_version_minor: >-
{{ (kubectl_cluster_version.stdout | from_yaml).serverVersion.minor }}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,3 @@
kubectl get node {{ inventory_hostname }} -o jsonpath='{.status.nodeInfo.kubeletVersion}'
register: kubelet_version
changed_when: false

- name: Set kubelet version as fact
set_fact:
kubelet_version: "{{ kubelet_version.stdout }}"
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
- name: k8s/kubelet-cm | Include get-cluster-version.yml
include_tasks: get-cluster-version.yml # sets cluster_version
- name: k8s/kubelet-cm | Include set-cluster-version.yml
include_tasks: set-cluster-version.yml # sets cluster_version

- name: k8s/kubelet-cm | Get kubelet config from ConfigMap
command: |-
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
- name: k8s | Include get-cluster-version.yml
include_tasks: kubernetes/get-cluster-version.yml

- name: Set cluster version as fact
set_fact:
cluster_version: >-
{{ (kubectl_cluster_version.stdout | from_yaml).serverVersion.gitVersion }}
cluster_version_major: >-
{{ (kubectl_cluster_version.stdout | from_yaml).serverVersion.major }}
cluster_version_minor: >-
{{ (kubectl_cluster_version.stdout | from_yaml).serverVersion.minor }}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
- name: k8s/verify | Include wait-for-kube-apiserver.yml
include_tasks: utils/wait-for-kube-apiserver.yml

- name: k8s/verify | Include get-cluster-version.yml
include_tasks: get-cluster-version.yml # sets cluster_version
- name: k8s/verify | Include set-cluster-version.yml
include_tasks: set-cluster-version.yml

- name: k8s/verify | Verify cluster version
assert:
Expand Down

0 comments on commit 15537d7

Please sign in to comment.