-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add CAPI patch to support in-place upgrade in KCP
- Loading branch information
1 parent
309a66c
commit e3615a4
Showing
1 changed file
with
102 additions
and
0 deletions.
There are no files selected for viewing
102 changes: 102 additions & 0 deletions
102
...ts/kubernetes-sigs/cluster-api/patches/0037-Add-support-for-in-place-upgrade-in-KCP.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
From 4efd2b227eb3f4bc34101f7c948078f191c49d2a Mon Sep 17 00:00:00 2001 | ||
From: Abhinav Pandey <[email protected]> | ||
Date: Wed, 17 Jan 2024 00:50:28 -0800 | ||
Subject: [PATCH] Add support for in-place upgrade in KCP | ||
|
||
--- | ||
.../kubeadm/api/v1beta1/kubeadm_control_plane_types.go | 8 ++++++++ | ||
.../kubeadm/api/v1beta1/kubeadm_control_plane_webhook.go | 6 +++++- | ||
controlplane/kubeadm/internal/controllers/upgrade.go | 8 +++++++- | ||
3 files changed, 20 insertions(+), 2 deletions(-) | ||
|
||
diff --git a/controlplane/kubeadm/api/v1beta1/kubeadm_control_plane_types.go b/controlplane/kubeadm/api/v1beta1/kubeadm_control_plane_types.go | ||
index 5272b0e5a..933d87f8a 100644 | ||
--- a/controlplane/kubeadm/api/v1beta1/kubeadm_control_plane_types.go | ||
+++ b/controlplane/kubeadm/api/v1beta1/kubeadm_control_plane_types.go | ||
@@ -35,6 +35,9 @@ const ( | ||
// RollingUpdateStrategyType replaces the old control planes by new one using rolling update | ||
// i.e. gradually scale up or down the old control planes and scale up or down the new one. | ||
RollingUpdateStrategyType RolloutStrategyType = "RollingUpdate" | ||
+ | ||
+ // InPlaceUpgradeStrategyType updates the node in place by delegating the upgrade to an external entity. | ||
+ InPlaceUpgradeStrategyType RolloutStrategyType = "InPlace" | ||
) | ||
|
||
const ( | ||
@@ -65,6 +68,11 @@ const ( | ||
// failures in updating remediation retry (the counter restarts from zero). | ||
RemediationForAnnotation = "controlplane.cluster.x-k8s.io/remediation-for" | ||
|
||
+ // InPlaceUpgradeAnnotation is used to denote that the KCP object needs to be in-place upgraded by an external entity. | ||
+ // This annotation will be added to the KCP object when `rolloutStrategy.type` is set to `InPlace`. | ||
+ // The external upgrader entity should watch for the annoatation and trigger an upgrade when it's added. | ||
+ InPlaceUpgradeAnnotation = "controlplane.clusters.x-k8s.io/in-place-upgrade-needed" | ||
+ | ||
// DefaultMinHealthyPeriod defines the default minimum period before we consider a remediation on a | ||
// machine unrelated from the previous remediation. | ||
DefaultMinHealthyPeriod = 1 * time.Hour | ||
diff --git a/controlplane/kubeadm/api/v1beta1/kubeadm_control_plane_webhook.go b/controlplane/kubeadm/api/v1beta1/kubeadm_control_plane_webhook.go | ||
index 83bf26356..f7d0f6635 100644 | ||
--- a/controlplane/kubeadm/api/v1beta1/kubeadm_control_plane_webhook.go | ||
+++ b/controlplane/kubeadm/api/v1beta1/kubeadm_control_plane_webhook.go | ||
@@ -381,12 +381,16 @@ func validateRolloutStrategy(rolloutStrategy *RolloutStrategy, replicas *int32, | ||
return allErrs | ||
} | ||
|
||
+ if rolloutStrategy.Type == InPlaceUpgradeStrategyType { | ||
+ return allErrs | ||
+ } | ||
+ | ||
if rolloutStrategy.Type != RollingUpdateStrategyType { | ||
allErrs = append( | ||
allErrs, | ||
field.Required( | ||
pathPrefix.Child("type"), | ||
- "only RollingUpdateStrategyType is supported", | ||
+ "only RollingUpdateStrategyType and InPlaceUpgradeStrategyType are supported", | ||
), | ||
) | ||
} | ||
diff --git a/controlplane/kubeadm/internal/controllers/upgrade.go b/controlplane/kubeadm/internal/controllers/upgrade.go | ||
index 200a27174..181e4dd1c 100644 | ||
--- a/controlplane/kubeadm/internal/controllers/upgrade.go | ||
+++ b/controlplane/kubeadm/internal/controllers/upgrade.go | ||
@@ -18,6 +18,7 @@ package controllers | ||
|
||
import ( | ||
"context" | ||
+ "time" | ||
|
||
"github.com/blang/semver" | ||
"github.com/pkg/errors" | ||
@@ -26,6 +27,7 @@ import ( | ||
controlplanev1 "sigs.k8s.io/cluster-api/controlplane/kubeadm/api/v1beta1" | ||
"sigs.k8s.io/cluster-api/controlplane/kubeadm/internal" | ||
"sigs.k8s.io/cluster-api/util" | ||
+ "sigs.k8s.io/cluster-api/util/annotations" | ||
"sigs.k8s.io/cluster-api/util/collections" | ||
"sigs.k8s.io/cluster-api/util/version" | ||
) | ||
@@ -37,7 +39,7 @@ func (r *KubeadmControlPlaneReconciler) upgradeControlPlane( | ||
) (ctrl.Result, error) { | ||
logger := ctrl.LoggerFrom(ctx) | ||
|
||
- if controlPlane.KCP.Spec.RolloutStrategy == nil || controlPlane.KCP.Spec.RolloutStrategy.RollingUpdate == nil { | ||
+ if controlPlane.KCP.Spec.RolloutStrategy == nil { | ||
return ctrl.Result{}, errors.New("rolloutStrategy is not set") | ||
} | ||
|
||
@@ -133,6 +135,10 @@ func (r *KubeadmControlPlaneReconciler) upgradeControlPlane( | ||
return r.scaleUpControlPlane(ctx, controlPlane) | ||
} | ||
return r.scaleDownControlPlane(ctx, controlPlane, machinesRequireUpgrade) | ||
+ case controlplanev1.InPlaceUpgradeStrategyType: | ||
+ annotations.AddAnnotations(controlPlane.KCP, map[string]string{controlplanev1.InPlaceUpgradeAnnotation: ""}) | ||
+ logger.Info("RolloutStrategy.Type set to `InPlace`, adding the annotation an requeuing the request in 30 seconds") | ||
+ return ctrl.Result{RequeueAfter: time.Second * 30}, nil | ||
default: | ||
logger.Info("RolloutStrategy type is not set to RollingUpdateStrategyType, unable to determine the strategy for rolling out machines") | ||
return ctrl.Result{}, nil | ||
-- | ||
2.42.0 | ||
|