Skip to content

Commit 5c0ae0e

Browse files
Merge pull request #866 from alexander-demicev/inplaceskeleton
Add support for in-place update contracts
2 parents a15defd + df0b746 commit 5c0ae0e

28 files changed

Lines changed: 3640 additions & 79 deletions

File tree

.golangci.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,15 @@ linters:
103103
- linters:
104104
- gosec
105105
text: G114
106+
- linters:
107+
- gosec
108+
text: G115
109+
- linters:
110+
- gomoddirectives
111+
text: "replacement are not allowed"
112+
- linters:
113+
- staticcheck
114+
text: SA1019
106115
- linters:
107116
- revive
108117
path: pkg/rke2

controlplane/config/manager/manager.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ spec:
2525
- "--diagnostics-address=${CAPRKE2_DIAGNOSTICS_ADDRESS:=:8443}"
2626
- "--insecure-diagnostics=${CAPRKE2_INSECURE_DIAGNOSTICS:=false}"
2727
- "--v=${CAPRKE2_DEBUG_LEVEL:=0}"
28+
- "--feature-gates=InPlaceUpdates=${EXP_IN_PLACE_UPDATES:=false}"
2829
- "--concurrency=${CONCURRENCY_NUMBER:=10}"
2930
image: controller:latest
3031
name: manager

controlplane/config/rbac/role.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,11 @@ rules:
104104
- list
105105
- patch
106106
- watch
107+
- apiGroups:
108+
- runtime.cluster.x-k8s.io
109+
resources:
110+
- extensionconfigs
111+
verbs:
112+
- get
113+
- list
114+
- watch
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
Copyright 2025 SUSE.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package controllers
18+
19+
import (
20+
"context"
21+
"fmt"
22+
23+
"k8s.io/klog/v2"
24+
ctrl "sigs.k8s.io/controller-runtime"
25+
26+
clusterv1 "sigs.k8s.io/cluster-api/api/core/v1beta2"
27+
28+
"github.com/rancher/cluster-api-provider-rke2/pkg/rke2"
29+
)
30+
31+
func (r *RKE2ControlPlaneReconciler) tryInPlaceUpdate(
32+
ctx context.Context,
33+
controlPlane *rke2.ControlPlane,
34+
machineToInPlaceUpdate *clusterv1.Machine,
35+
machineUpToDateResult rke2.UpToDateResult,
36+
) (fallbackToScaleDown bool, _ ctrl.Result, _ error) {
37+
// 1. Preflight checks for all machines.
38+
if resultForAllMachines := r.preflightChecks(ctx, controlPlane); !resultForAllMachines.IsZero() {
39+
if result := r.preflightChecks(ctx, controlPlane, machineToInPlaceUpdate); result.IsZero() {
40+
return true, ctrl.Result{}, nil
41+
}
42+
43+
return false, resultForAllMachines, nil
44+
}
45+
46+
// 2. CanUpdateMachine check.
47+
canUpdate, err := r.canUpdateMachine(ctx, machineToInPlaceUpdate, machineUpToDateResult)
48+
if err != nil {
49+
return false, ctrl.Result{}, fmt.Errorf("failed to determine if Machine %s can be updated in-place: %w", klog.KObj(machineToInPlaceUpdate), err)
50+
}
51+
52+
if !canUpdate {
53+
return true, ctrl.Result{}, nil
54+
}
55+
56+
return false, ctrl.Result{}, r.triggerInPlaceUpdate(ctx, machineToInPlaceUpdate, machineUpToDateResult)
57+
}

0 commit comments

Comments
 (0)