Skip to content

Commit 26533e0

Browse files
acuminoshafeeqesary1992
authored
[GEP-31] Controller changes to Support Auto InPlaceUpdate strategy (#973)
* Replicas calculation for new machine set in case of InPlace Co-Authored-By: Shafeeque E S <[email protected]> Co-Authored-By: Ashish Ranjan Yadav <[email protected]> * Add utility function Co-Authored-By: Shafeeque E S <[email protected]> Co-Authored-By: Ashish Ranjan Yadav <[email protected]> * [MCD] Use AutoInPlace rolling strategy Co-Authored-By: Shafeeque E S <[email protected]> Co-Authored-By: Ashish Ranjan Yadav <[email protected]> * [MCD] Label all old nodes and machine as candidate for update Co-Authored-By: Shafeeque E S <[email protected]> Co-Authored-By: Ashish Ranjan Yadav <[email protected]> * [MCD] Add scale up logic Co-Authored-By: Shafeeque E S <[email protected]> Co-Authored-By: Ashish Ranjan Yadav <[email protected]> * [MCD] Add scale down logic Co-Authored-By: Shafeeque E S <[email protected]> Co-Authored-By: Ashish Ranjan Yadav <[email protected]> * [MCD] Sync MachineSets after updates and on new reconciliation Co-Authored-By: Shafeeque E S <[email protected]> Co-Authored-By: Ashish Ranjan Yadav <[email protected]> * [MCD] Handle max surge case Co-authored-by: Shafeeque E S <[email protected]> Co-authored-by: Ashish Ranjan Yadav <[email protected]> * [MCD] Label all the old machine sets to disable the scale up Co-Authored-By: Shafeeque E S <[email protected]> Co-Authored-By: Ashish Ranjan Yadav <[email protected]> * Enhance testing lib for more use cases Co-Authored-By: Shafeeque E S <[email protected]> Co-Authored-By: Ashish Ranjan Yadav <[email protected]> * Add test for in-place updates Co-Authored-By: Shafeeque E S <[email protected]> Co-Authored-By: Ashish Ranjan Yadav <[email protected]> * [MCS] Ignore in-place updated machine in new machine set Co-authored-by: Shafeeque E S <[email protected]> Co-authored-by: Ashish Ranjan Yadav <[email protected]> * [MCS] Label all oldISs to not upscale for the transferred machine When transferring ownership old machine set should not create new machine for the machine transferred to new machine set Co-authored-by: Shafeeque E S <[email protected]> Co-authored-by: Ashish Ranjan Yadav <[email protected]> * [Machine Safety] Calculate maxSurge based on update strategy Co-authored-by: Shafeeque E S <[email protected]> Co-authored-by: Ashish Ranjan Yadav <[email protected]> * [MC] Update node condition based on the in-place update state Co-Authored-By: Shafeeque E S <[email protected]> Co-Authored-By: Ashish Ranjan Yadav <[email protected]> * [MC] Drain Nodes which has been selected for update Co-Authored-By: Shafeeque E S <[email protected]> Co-Authored-By: Ashish Ranjan Yadav <[email protected]> * [MC] Adapt machine health reconciliation Co-Authored-By: Shafeeque E S <[email protected]> Co-Authored-By: Ashish Ranjan Yadav <[email protected]> * [MC] Trigger machine reconciliation on addition of in-place update node label Co-authored-by: Shafeeque E S <[email protected]> Co-authored-by: Ashish Ranjan Yadav <[email protected]> * Nit * Fix case where there are zero machines in oldMachineSets * Address Review * Address Review * Address Review * Address PR review feedback * Adapt constant name change * Address Review * Address Review * Continue in case of node label is not present on the machine --------- Co-authored-by: Shafeeque E S <[email protected]> Co-authored-by: Ashish Ranjan Yadav <[email protected]>
1 parent 57dad3e commit 26533e0

23 files changed

+4219
-130
lines changed

pkg/controller/controller_suite_test.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -270,14 +270,19 @@ func newMachines(
270270

271271
currentTime := metav1.Now()
272272

273+
namePrefix := ""
274+
if owner != nil && owner.Name != "" {
275+
namePrefix = owner.Name + "-"
276+
}
277+
273278
for i := range machines {
274279
m := &v1alpha1.Machine{
275280
TypeMeta: metav1.TypeMeta{
276281
APIVersion: "machine.sapcloud.io",
277282
Kind: "Machine",
278283
},
279284
ObjectMeta: metav1.ObjectMeta{
280-
Name: fmt.Sprintf("machine-%d", i),
285+
Name: fmt.Sprintf("%smachine-%d", namePrefix, i),
281286
Namespace: testNamespace,
282287
Labels: labels,
283288
Annotations: annotations,
@@ -302,18 +307,19 @@ func newMachines(
302307

303308
func newNode(
304309
_ int,
310+
labels map[string]string,
305311
nodeSpec *corev1.NodeSpec,
306312
nodeStatus *corev1.NodeStatus,
307313
) *corev1.Node {
308-
return newNodes(1, nodeSpec, nodeStatus)[0]
314+
return newNodes(1, labels, nodeSpec, nodeStatus)[0]
309315
}
310316

311317
func newNodes(
312318
nodeCount int,
319+
labels map[string]string,
313320
nodeSpec *corev1.NodeSpec,
314321
_ *corev1.NodeStatus,
315322
) []*corev1.Node {
316-
317323
nodes := make([]*corev1.Node, nodeCount)
318324
for i := range nodes {
319325
node := &corev1.Node{
@@ -322,7 +328,8 @@ func newNodes(
322328
Kind: "Node",
323329
},
324330
ObjectMeta: metav1.ObjectMeta{
325-
Name: fmt.Sprintf("node-%d", i),
331+
Name: fmt.Sprintf("node-%d", i),
332+
Labels: labels,
326333
},
327334
Spec: *nodeSpec.DeepCopy(),
328335
}
@@ -447,7 +454,7 @@ func createController(
447454
machineDeploymentQueue: workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), "machinedeployment"),
448455
machineSafetyOvershootingQueue: workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), "machinesafetyovershooting"),
449456
expectations: NewUIDTrackingContExpectations(NewContExpectations()),
450-
recorder: record.NewBroadcaster().NewRecorder(nil, corev1.EventSource{Component: ""}),
457+
recorder: record.NewBroadcaster().NewRecorder(internalExternalScheme, corev1.EventSource{Component: ""}),
451458
}
452459

453460
// controller.internalExternalScheme = runtime.NewScheme()

pkg/controller/controller_utils_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ var _ = Describe("#controllerUtils", func() {
286286
setup: setup{
287287
node: newNode(
288288
1,
289+
nil,
289290
&corev1.NodeSpec{},
290291
nil,
291292
),
@@ -311,6 +312,7 @@ var _ = Describe("#controllerUtils", func() {
311312
setup: setup{
312313
node: newNode(
313314
1,
315+
nil,
314316
&corev1.NodeSpec{},
315317
nil,
316318
),
@@ -333,6 +335,7 @@ var _ = Describe("#controllerUtils", func() {
333335
setup: setup{
334336
node: newNode(
335337
1,
338+
nil,
336339
&corev1.NodeSpec{},
337340
nil,
338341
),
@@ -357,6 +360,7 @@ var _ = Describe("#controllerUtils", func() {
357360
setup: setup{
358361
node: newNode(
359362
1,
363+
nil,
360364
&corev1.NodeSpec{},
361365
nil,
362366
),
@@ -381,6 +385,7 @@ var _ = Describe("#controllerUtils", func() {
381385
setup: setup{
382386
node: newNode(
383387
1,
388+
nil,
384389
&corev1.NodeSpec{},
385390
nil,
386391
),
@@ -461,6 +466,7 @@ var _ = Describe("#controllerUtils", func() {
461466
setup: setup{
462467
node: newNode(
463468
1,
469+
nil,
464470
&corev1.NodeSpec{},
465471
nil,
466472
),
@@ -486,6 +492,7 @@ var _ = Describe("#controllerUtils", func() {
486492
setup: setup{
487493
node: newNode(
488494
1,
495+
nil,
489496
&corev1.NodeSpec{},
490497
nil,
491498
),
@@ -506,6 +513,7 @@ var _ = Describe("#controllerUtils", func() {
506513
setup: setup{
507514
node: newNode(
508515
1,
516+
nil,
509517
&corev1.NodeSpec{},
510518
nil,
511519
),
@@ -531,6 +539,7 @@ var _ = Describe("#controllerUtils", func() {
531539
setup: setup{
532540
node: newNode(
533541
1,
542+
nil,
534543
&corev1.NodeSpec{},
535544
nil,
536545
),

pkg/controller/deployment.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,26 +25,25 @@ package controller
2525
import (
2626
"context"
2727
"fmt"
28-
"github.com/gardener/machine-controller-manager/pkg/util/annotations"
29-
"github.com/gardener/machine-controller-manager/pkg/util/provider/machineutils"
30-
apierrors "k8s.io/apimachinery/pkg/api/errors"
3128
"reflect"
3229
"sync"
3330
"time"
3431

35-
"k8s.io/klog/v2"
36-
3732
v1 "k8s.io/api/core/v1"
33+
apierrors "k8s.io/apimachinery/pkg/api/errors"
3834
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3935
"k8s.io/apimachinery/pkg/labels"
4036
"k8s.io/apimachinery/pkg/types"
4137
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
4238
"k8s.io/apimachinery/pkg/util/sets"
4339
"k8s.io/client-go/tools/cache"
40+
"k8s.io/klog/v2"
4441

4542
"github.com/gardener/machine-controller-manager/pkg/apis/machine"
4643
"github.com/gardener/machine-controller-manager/pkg/apis/machine/v1alpha1"
4744
"github.com/gardener/machine-controller-manager/pkg/apis/machine/validation"
45+
"github.com/gardener/machine-controller-manager/pkg/util/annotations"
46+
"github.com/gardener/machine-controller-manager/pkg/util/provider/machineutils"
4847
)
4948

5049
// controllerKind contains the schema.GroupVersionKind for this controller type.
@@ -546,6 +545,12 @@ func (dc *controller) reconcileClusterMachineDeployment(key string) error {
546545
return dc.rolloutRecreate(ctx, d, machineSets, machineMap)
547546
case v1alpha1.RollingUpdateMachineDeploymentStrategyType:
548547
return dc.rolloutRolling(ctx, d, machineSets, machineMap)
548+
case v1alpha1.InPlaceUpdateMachineDeploymentStrategyType:
549+
if d.Spec.Strategy.InPlaceUpdate.OrchestrationType == v1alpha1.OrchestrationTypeAuto {
550+
return dc.rolloutAutoInPlace(ctx, d, machineSets, machineMap)
551+
}
552+
553+
// TODO(ary1992): Implement Manual InPlace strategy
549554
}
550555
return fmt.Errorf("unexpected deployment strategy type: %s", d.Spec.Strategy.Type)
551556
}

0 commit comments

Comments
 (0)