Kubernetes storage upgrade

Creates the support of k8s storage upgrade. Since image pods may
change from a Kubernetes version to the next, the storage deployment
must be upgraded to use the new images.

Test Plan:
 PASS: Run a kubernetes upgrade with the kube-upgrade-storage step
       and observe that the image for volume-snapshot-controller is
       changed

Story: 2010877
Task: 48590

Change-Id: Id044fe5f7c58a5babefa057220927b40813d3e37
Signed-off-by: Luiz Felipe Kina <LuizFelipe.EiskeKina@windriver.com>
Signed-off-by: Gabriel de Araújo Cabral <gabriel.cabral@windriver.com>
This commit is contained in:
Luiz Felipe Kina 2023-07-25 08:10:03 -04:00 committed by Gabriel de Araújo Cabral
parent 372ad0c72f
commit e5b651c677
3 changed files with 118 additions and 0 deletions

View File

@ -85,6 +85,12 @@
download_images_list: "{{ download_images_list|default([]) + networking_images }}"
when: mode == 'upgrade_k8s_networking'
# Only download k8s storage images if k8s storage upgrade
- name: Set download images list to k8s storage images if upgrading k8s storage
set_fact:
download_images_list: "{{ download_images_list|default([]) + storage_images }}"
when: mode == 'upgrade_k8s_storage'
# Only download kubernetes images if kubernetes upgrade
- name: Set download images list to kubernetes images if upgrading kubernetes
set_fact:

View File

@ -0,0 +1,99 @@
---
#
# Copyright (c) 2023 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
# ROLE DESCRIPTION:
# This will upgrade storage images during a kubernetes upgrade
- name: Fail if kubernetes_version is not defined
fail: msg="The mandatory parameter kubernetes_version is not defined."
when: kubernetes_version is not defined
- name: Backup mode variable
set_fact:
previous_mode: "{{ mode }}"
when: mode is defined
- name: Initialize variables
set_fact:
overrides_file: "/tmp/upgrade_overrides.yaml"
mode: "upgrade_k8s_storage"
- name: Set kubernetes long version
set_fact:
kubernetes_long_version: "{{ kubernetes_version if kubernetes_version.startswith('v')
else 'v' + kubernetes_version }}"
when: kubernetes_long_version is not defined
- name: Create the upgrade overrides file
command: "/usr/bin/sysinv-utils create-host-overrides {{ overrides_file }}"
- name: Read the overrides variables
include_vars:
file: "{{ overrides_file }}"
when: inventory_hostname == 'localhost'
- block:
- name: Fetch local copy of overrides
fetch:
src: "{{ overrides_file }}"
dest: /tmp/
register: fetched
- name: Read the overrides variables
include_vars:
file: "{{ fetched.dest }}"
- name: Remove local overrides copy
local_action:
module: file
path: "{{ fetched.dest }}"
state: absent
become: no
when: inventory_hostname != 'localhost'
- name: Upgrade k8s storage images
import_role:
name: common/push-docker-images
- name: Update Snapshot CRDs
command: "kubectl --kubeconfig=/etc/kubernetes/admin.conf apply -f roles/k8s-storage-backends/snapshot\
-controller/files/k8s-{{ kubernetes_long_version }}/crd/"
retries: 5
delay: 3
- name: Create Snapshot-controller config file
template:
src: "roles/k8s-storage-backends/snapshot-controller/templates/k8s-{{ kubernetes_long_version }}/volume\
-snapshot-controller/volume-snapshot-controller-deployment.yaml.j2"
dest: /etc/kubernetes/update_snapshot-controller.yaml
- name: Update Snapshot-Controller
command: 'kubectl --kubeconfig=/etc/kubernetes/admin.conf apply -f
/etc/kubernetes/update_snapshot-controller.yaml'
retries: 5
delay: 3
register: result
until: result.rc == 0
- name: Create rbac-volume-snapshot-controller config file
template:
src: "roles/k8s-storage-backends/snapshot-controller/templates/k8s-{{ kubernetes_long_version }}/volume\
-snapshot-controller/rbac-snapshot-controller.yaml.j2"
dest: /etc/kubernetes/update_rbac-volume-snapshot-controller.yaml
- name: Update Rbac-volume-snapshot-controller
command: 'kubectl --kubeconfig=/etc/kubernetes/admin.conf apply -f
/etc/kubernetes/update_rbac-volume-snapshot-controller.yaml'
retries: 5
delay: 3
register: result
until: result.rc == 0
- name: Restore mode variable
set_fact:
mode: "{{ previous_mode }}"
when: previous_mode is defined

View File

@ -0,0 +1,13 @@
---
#
# Copyright (c) 2023 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
- hosts: all
gather_facts: no
roles:
- common/upgrade-k8s-storage