Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CPDEV-110491] - Add new Kubernetes version v1.32 #711

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ ca-key.pem
kubernetes.csr
kubernetes.pem
kubernetes-key.pem
/cluster.yaml
/cluster*.yaml
/additional.yaml
/procedure.yaml
venv/
Expand Down
70 changes: 61 additions & 9 deletions kubemarine/kubernetes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@
import math
import os
import time
import re
import json
from contextlib import contextmanager
from typing import List, Dict, Iterator, Any, Optional
from typing import List, Dict, Iterator, Any, Optional, Union

import yaml
from jinja2 import Template
Expand Down Expand Up @@ -397,6 +399,8 @@ def join_control_plane(cluster: KubernetesCluster, node: NodeGroup, join_dict: d
node.sudo("mkdir -p /etc/kubernetes")
node.put(io.StringIO(config), '/etc/kubernetes/join-config.yaml', sudo=True)



# put control-plane patches
components.create_kubeadm_patches_for_node(cluster, node)

Expand Down Expand Up @@ -505,6 +509,7 @@ def init_first_control_plane(group: NodeGroup) -> None:
first_control_plane.sudo("mkdir -p /etc/kubernetes")
first_control_plane.put(io.StringIO(config), '/etc/kubernetes/init-config.yaml', sudo=True)

# migrate_kubeadm_config(first_control_plane, "/etc/kubernetes/init-config.yaml")
# put control-plane patches
components.create_kubeadm_patches_for_node(cluster, first_control_plane)

Expand All @@ -513,7 +518,6 @@ def init_first_control_plane(group: NodeGroup) -> None:

# put audit-policy.yaml
prepare_audit_policy(first_control_plane)

log.debug("Initializing first control_plane...")
result = first_control_plane.sudo(
"kubeadm init"
Expand All @@ -531,13 +535,34 @@ def init_first_control_plane(group: NodeGroup) -> None:
# Remove default resolvConf from kubelet-config ConfigMap for debian OS family
first_control_plane.call(components.patch_kubelet_configmap)

# Preparing join_dict to init other nodes
control_plane_lines = list(result.values())[0].stdout. \
split("You can now join any number of the control-plane")[1].splitlines()[2:5]
worker_lines = list(result.values())[0].stdout. \
split("Then you can join any number of worker")[1].splitlines()[2:4]
control_plane_join_command = " ".join([x.replace("\\", "").strip() for x in control_plane_lines])
worker_join_command = " ".join([x.replace("\\", "").strip() for x in worker_lines])
stdout_output = list(result.values())[0].stdout

# regex patterns for variations in msg for kubeadm init command
control_plane_pattern = (
r"You can now join any number of (?:the )?control-plane node[s]?.*?"
r"(\n\s+kubeadm join[^\n]+(?:\n\s+--[^\n]+)*)"
)
worker_pattern = r"Then you can join any number of worker nodes.*?(\n\s+kubeadm join[^\n]+(?:\n\s+--[^\n]+)*)"

control_plane_match = re.search(control_plane_pattern, stdout_output, re.DOTALL)
if control_plane_match:
control_plane_lines = control_plane_match.group(1).splitlines()
control_plane_lines = [line.strip() for line in control_plane_lines if line.strip()]
if not control_plane_lines:
raise ValueError("Extracted control-plane join command block is empty")
control_plane_join_command = " ".join(control_plane_lines).replace("\\", "").strip()
else:
raise ValueError("Failed to extract control-plane join command from kubeadm output")

worker_match = re.search(worker_pattern, stdout_output, re.DOTALL)
if worker_match:
worker_lines = worker_match.group(1).splitlines()
worker_lines = [line.strip() for line in worker_lines if line.strip()]
if not worker_lines:
raise ValueError("Extracted worker join command block is empty")
worker_join_command = " ".join(worker_lines).replace("\\", "").strip()
else:
raise ValueError("Failed to extract worker join command from kubeadm output")

# TODO: Get rid of this code and use get_join_dict() method
args = control_plane_join_command.split("--")
Expand Down Expand Up @@ -1139,6 +1164,8 @@ def images_prepull(group: DeferredGroup, collector: CollectorCallback) -> Token:

group.put(io.StringIO(config), '/etc/kubernetes/prepull-config.yaml', sudo=True)

# migrate_kubeadm_config(group, "/etc/kubernetes/prepull-config.yaml")

return group.sudo("kubeadm config images pull --config=/etc/kubernetes/prepull-config.yaml",
pty=True, callback=collector)

Expand Down Expand Up @@ -1268,3 +1295,28 @@ def prepare_audit_policy(group: NodeGroup) -> None:
utils.dump_file(cluster, policy_config_file, 'audit-policy.yaml')
# upload rules on cluster
group.put(io.StringIO(policy_config_file), audit_file_name, sudo=True, backup=True)

# def migrate_kubeadm_config(group: Union[NodeGroup, DeferredGroup], config_file: str) -> None:
# """
# Check if migration is needed based on Kubernetes minor version and perform the migration.

# :param group: Node group where the migration is performed.
# :param config_file: The path to the configuration file.
# """
# cluster: KubernetesCluster = group.cluster
# log = cluster.log

# # Retrieve Kubernetes version from inventory and parse the minor version
# k8s_version = cluster.inventory['services']['kubeadm']['kubernetesVersion']
# log.debug(f"Cluster Kubernetes version: {k8s_version}")
# minor_version = int(k8s_version.lstrip('v').split('.')[1])

# # If minor version > 31, proceed with migration
# if minor_version > 31:
# config = config_file
# # Perform migration
# group.sudo(f"kubeadm config migrate --old-config {config} --new-config {config}-migrated", hide=True)
# log.debug(f"Kubeadm config migration successful: {config}-migrated")
# group.sudo(f"cp {config}-migrated {config}")
# else:
# log.debug(f"No migration needed for Kubernetes version: {k8s_version}")
14 changes: 12 additions & 2 deletions kubemarine/kubernetes/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,18 @@ def _upload_config(cluster: KubernetesCluster, control_plane: AbstractGroup[RunR
utils.dump_file(cluster, config, f"{name}_{control_plane.get_node_name()}.yaml")

control_plane.put(io.StringIO(config), remote_path, sudo=True)

# log = cluster.log
# k8s_version = cluster.inventory['services']['kubeadm']['kubernetesVersion']
# log.debug(f"Cluster Kubernetes version: {k8s_version}")
# minor_version = int(k8s_version.lstrip('v').split('.')[1])
# # If minor version > 31, proceed with migration
# if minor_version > 31:
# control_plane.sudo(f"kubeadm config migrate --old-config {remote_path} --new-config {remote_path}-migrated")
# log.debug(f"Kubeadm config migration successful: {remote_path}-migrated")
# control_plane.sudo(f"cp {remote_path}-migrated {remote_path}")
# else:
# log.debug(f"No migration needed for Kubernetes version: {k8s_version}")


def _update_configmap(cluster: KubernetesCluster, control_plane: NodeGroup, configmap: str,
Expand Down Expand Up @@ -895,7 +907,6 @@ def compare_kubelet_config(cluster: KubernetesCluster, *, with_inventory: bool)
def compare_configmap(cluster: KubernetesCluster, configmap: str) -> Optional[str]:
control_plane = cluster.nodes['control-plane'].get_first_member()
kubeadm_config = KubeadmConfig(cluster)

if configmap == 'kubelet-config':
# Do not check kubelet-config ConfigMap, because some properties may be deleted from KubeletConfiguration
# if set to default, for example readOnlyPort: 0, protectKernelDefaults: false
Expand Down Expand Up @@ -961,7 +972,6 @@ def compare_configmap(cluster: KubernetesCluster, configmap: str) -> Optional[st
fromfile=f'{configmap} ConfigMap',
tofile=f"{configmap} ConfigMap merged 'services.{section}' section")


def _detect_changes(logger: log.EnhancedLogger, old: str, new: str, fromfile: str, tofile: str) -> bool:
diff = utils.get_yaml_diff(old, new, fromfile, tofile)
if diff is not None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ kube-apiserver:
version: v1.30.3
v1.31.1:
version: v1.31.1
v1.32.0:
version: v1.32.0
kube-controller-manager:
v1.27.1:
version: v1.27.1
Expand Down Expand Up @@ -70,6 +72,8 @@ kube-controller-manager:
version: v1.30.3
v1.31.1:
version: v1.31.1
v1.32.0:
version: v1.32.0
kube-scheduler:
v1.27.1:
version: v1.27.1
Expand Down Expand Up @@ -105,6 +109,8 @@ kube-scheduler:
version: v1.30.3
v1.31.1:
version: v1.31.1
v1.32.0:
version: v1.32.0
kube-proxy:
v1.27.1:
version: v1.27.1
Expand Down Expand Up @@ -140,6 +146,8 @@ kube-proxy:
version: v1.30.3
v1.31.1:
version: v1.31.1
v1.32.0:
version: v1.32.0
pause:
v1.27.1:
version: '3.9'
Expand Down Expand Up @@ -175,6 +183,8 @@ pause:
version: '3.9'
v1.31.1:
version: '3.10'
v1.32.0:
version: '3.10'
etcd:
v1.27.1:
version: 3.5.7-0
Expand Down Expand Up @@ -210,6 +220,8 @@ etcd:
version: 3.5.12-0
v1.31.1:
version: 3.5.15-0
v1.32.0:
version: 3.5.16-0
coredns/coredns:
v1.27.1:
version: v1.10.1
Expand Down Expand Up @@ -245,3 +257,5 @@ coredns/coredns:
version: v1.11.1
v1.31.1:
version: v1.11.3
v1.32.0:
version: v1.11.3
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ containerd:
version_debian: 1.7.*
v1.31.1:
version_debian: 1.7.*
v1.32.0:
version_debian: 1.7.*
containerdio:
v1.27.1:
version_rhel: 1.6*
Expand Down Expand Up @@ -108,6 +110,10 @@ containerdio:
version_rhel: 1.6*
version_rhel8: 1.6*
version_rhel9: 1.6*
v1.32.0:
version_rhel: 1.6*
version_rhel8: 1.6*
version_rhel9: 1.6*
haproxy:
version_rhel: 1.8*
version_rhel8: 1.8*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ calico:
version: v3.29.1
v1.31.1:
version: v3.29.1
v1.32.0:
version: v3.29.1
nginx-ingress-controller:
v1.27.1:
version: v1.8.4
Expand Down Expand Up @@ -91,6 +93,9 @@ nginx-ingress-controller:
v1.31.1:
version: v1.11.1
webhook-version: v1.4.1
v1.32.0:
version: v1.11.1
webhook-version: v1.4.1
kubernetes-dashboard:
v1.27.1:
version: v2.7.0
Expand Down Expand Up @@ -143,6 +148,9 @@ kubernetes-dashboard:
v1.31.1:
version: v2.7.0
metrics-scraper-version: v1.0.8
v1.32.0:
version: v2.7.0
metrics-scraper-version: v1.0.8
local-path-provisioner:
v1.27.1:
version: v0.0.25
Expand Down Expand Up @@ -195,3 +203,6 @@ local-path-provisioner:
v1.31.1:
version: v0.0.27
busybox-version: 1.34.1
v1.32.0:
version: v0.0.27
busybox-version: 1.34.1
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ kubeadm:
sha1: f840e75f5dc1001ebdd7e286c0e87e1090df011b
v1.31.1:
sha1: 0a682af6436ce4e7188f93ddeebff5c2f3be1592
v1.32.0:
sha1: 981cdd31d4072fe65fb251c1158090f511d34610
kubelet:
v1.27.1:
sha1: 43cb7231a889c01cfd88bd3f27441134e3d1cbff
Expand Down Expand Up @@ -71,6 +73,8 @@ kubelet:
sha1: fbae53efc43ec715a45b05415294ab991ea087a2
v1.31.1:
sha1: fc7d0a9859c97ec2a2a4ac9ec1814b131e8d875f
v1.32.0:
sha1: e81e622c57721ddb31b92e09e2f2f0fc9f58562b
kubectl:
v1.27.1:
sha1: 0c3f1e262a6c37719ba4d66885df6715f58b60e5
Expand Down Expand Up @@ -106,6 +110,8 @@ kubectl:
sha1: 097d6b02fabb284418a9c95ea81fa86fc3c85bb7
v1.31.1:
sha1: a0fd9dc942f533e2bdeaa4b2691fc408e334f922
v1.32.0:
sha1: 0bc860f7bc83b991ee3b099e21504a60c515cfd7
calicoctl:
# calicoctl version is duplicated from kubemarine/resources/configurations/compatibility/kubernetes_versions.yaml
# It also corresponds to the plugin version in kubemarine/resources/configurations/compatibility/internal/plugins.yaml
Expand Down Expand Up @@ -160,6 +166,9 @@ calicoctl:
v1.31.1:
version: v3.29.1
sha1: 00be749d257eee5035d3ba408aca15fcaf8be7c2
v1.32.0:
version: v3.29.1
sha1: 00be749d257eee5035d3ba408aca15fcaf8be7c2
crictl:
# crictl version is duplicated from kubemarine/resources/configurations/compatibility/kubernetes_versions.yaml
# for backward compatibility with clusters in a private environment.
Expand Down Expand Up @@ -214,3 +223,6 @@ crictl:
v1.31.1:
version: v1.30.0
sha1: c81e76d5d4bf64d6b513485490722d2fc0a9a83b
v1.32.0:
version: v1.32.0
sha1: c503051cf6e809a691f776ddf544abfc2a15e790
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ kubernetes_versions:
supported: true
v1.31:
supported: true
v1.32:
supported: true
compatibility_map:
# This section should be changed manually.
v1.27.1:
Expand Down Expand Up @@ -114,6 +116,12 @@ compatibility_map:
kubernetes-dashboard: v2.7.0
local-path-provisioner: v0.0.27
crictl: v1.30.0
v1.32.0:
calico: v3.29.1
nginx-ingress-controller: v1.11.1
kubernetes-dashboard: v2.7.0
local-path-provisioner: v0.0.27
crictl: v1.32.0
# After any change, please run scripts/thirdparties/sync.py

# The following optional keys are supported in addition to the 5 required software keys:
Expand Down
Loading