From c1954ff918154d5805d959c34baff360219c6710 Mon Sep 17 00:00:00 2001
From: Cristian Calin <6627509+cristicalin@users.noreply.github.com>
Date: Tue, 21 Dec 2021 11:38:46 +0200
Subject: [PATCH] Support deploying kubernetes 1.23 (#8323)

* Ensure entries for 1.23 are added for supported_versions vars

* cri-o: add support for kubernetes 1.23 but still use cri-o 1.22

* kubescheduler-config: diferentiate config versions based on kube_version
---
 roles/container-engine/cri-o/defaults/main.yml           | 1 +
 roles/container-engine/cri-o/vars/fedora.yml             | 3 ++-
 roles/download/defaults/main.yml                         | 2 ++
 roles/kubernetes/control-plane/tasks/main.yml            | 2 +-
 ...nfig.v1beta1.yaml.j2 => kubescheduler-config.yaml.j2} | 9 ++++++++-
 5 files changed, 14 insertions(+), 3 deletions(-)
 rename roles/kubernetes/control-plane/templates/{kubescheduler-config.v1beta1.yaml.j2 => kubescheduler-config.yaml.j2} (70%)

diff --git a/roles/container-engine/cri-o/defaults/main.yml b/roles/container-engine/cri-o/defaults/main.yml
index 7e7a63660..7fc81a592 100644
--- a/roles/container-engine/cri-o/defaults/main.yml
+++ b/roles/container-engine/cri-o/defaults/main.yml
@@ -45,6 +45,7 @@ crio_stream_port: "10010"
 crio_required_version: "{{ kube_version | regex_replace('^v(?P<major>\\d+).(?P<minor>\\d+).(?P<patch>\\d+)$', '\\g<major>.\\g<minor>') }}"
 
 crio_kubernetes_version_matrix:
+  "1.23": "1.22"
   "1.22": "1.22"
   "1.21": "1.21"
   "1.20": "1.20"
diff --git a/roles/container-engine/cri-o/vars/fedora.yml b/roles/container-engine/cri-o/vars/fedora.yml
index 4c517e815..69636f0aa 100644
--- a/roles/container-engine/cri-o/vars/fedora.yml
+++ b/roles/container-engine/cri-o/vars/fedora.yml
@@ -4,7 +4,8 @@ crio_packages:
   - cri-tools
 
 crio_kubernetes_version_matrix:
+  "1.23": "1.22"
   "1.22": "1.22"
   "1.21": "1.21"
   "1.20": "1.20"
-crio_version: "{{ crio_kubernetes_version_matrix[crio_required_version] | default('1.20') }}"
+crio_version: "{{ crio_kubernetes_version_matrix[crio_required_version] | default('1.22') }}"
diff --git a/roles/download/defaults/main.yml b/roles/download/defaults/main.yml
index c4084cecf..5cd1dddc6 100644
--- a/roles/download/defaults/main.yml
+++ b/roles/download/defaults/main.yml
@@ -94,6 +94,7 @@ krew_version: "v0.4.2"
 # Get kubernetes major version (i.e. 1.17.4 => 1.17)
 kube_major_version: "{{ kube_version | regex_replace('^v([0-9])+\\.([0-9]+)\\.[0-9]+', 'v\\1.\\2') }}"
 crictl_supported_versions:
+  v1.23: "v1.22.0"
   v1.22: "v1.22.0"
   v1.21: "v1.21.0"
   v1.20: "v1.20.0"
@@ -745,6 +746,7 @@ csi_livenessprobe_image_repo: "{{ kube_image_repo }}/sig-storage/livenessprobe"
 csi_livenessprobe_image_tag: "v2.5.0"
 
 snapshot_controller_supported_versions:
+  v1.23: "v4.2.1"
   v1.22: "v4.2.1"
   v1.21: "v4.2.1"
   v1.20: "v4.0.0"
diff --git a/roles/kubernetes/control-plane/tasks/main.yml b/roles/kubernetes/control-plane/tasks/main.yml
index 3f2f3b403..7271f1ca8 100644
--- a/roles/kubernetes/control-plane/tasks/main.yml
+++ b/roles/kubernetes/control-plane/tasks/main.yml
@@ -22,7 +22,7 @@
 
 - name: Create kube-scheduler config
   template:
-    src: kubescheduler-config.v1beta1.yaml.j2
+    src: kubescheduler-config.yaml.j2
     dest: "{{ kube_config_dir }}/kubescheduler-config.yaml"
     mode: 0644
 
diff --git a/roles/kubernetes/control-plane/templates/kubescheduler-config.v1beta1.yaml.j2 b/roles/kubernetes/control-plane/templates/kubescheduler-config.yaml.j2
similarity index 70%
rename from roles/kubernetes/control-plane/templates/kubescheduler-config.v1beta1.yaml.j2
rename to roles/kubernetes/control-plane/templates/kubescheduler-config.yaml.j2
index 87782fc16..4ee61da90 100644
--- a/roles/kubernetes/control-plane/templates/kubescheduler-config.v1beta1.yaml.j2
+++ b/roles/kubernetes/control-plane/templates/kubescheduler-config.yaml.j2
@@ -1,4 +1,11 @@
-apiVersion: kubescheduler.config.k8s.io/v1beta1
+{% if kube_version is version('v1.22.0', '<') %}
+{% set kubescheduler_config_api_version = "v1beta1" %}
+{% elif kube_version is version('v1.23.0', '<') %}
+{% set kubescheduler_config_api_version = "v1beta2" %}
+{% else %}
+{% set kubescheduler_config_api_version = "v1beta3" %}
+{% endif %}
+apiVersion: kubescheduler.config.k8s.io/{{ kubescheduler_config_api_version|d('v1') }}
 kind: KubeSchedulerConfiguration
 clientConnection:
   kubeconfig: "{{ kube_config_dir }}/scheduler.conf"
-- 
GitLab