Skip to content

Commit 7dbaa1d

Browse files
authored
Merge pull request #5083 from muraee/rosa-fix-diff-detection
🐛 ROSA: Fix ROSAMchinePool spec.Taints diff detection
2 parents 46b87c8 + 5941030 commit 7dbaa1d

File tree

2 files changed

+37
-17
lines changed

2 files changed

+37
-17
lines changed

exp/controllers/rosamachinepool_controller.go

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ func (r *ROSAMachinePoolReconciler) reconcileDelete(
312312
if err := ocmClient.DeleteNodePool(machinePoolScope.ControlPlane.Status.ID, nodePool.ID()); err != nil {
313313
return err
314314
}
315-
machinePoolScope.Info("Successfully deleted NodePool %s", nodePool.ID())
315+
machinePoolScope.Info("Successfully deleted NodePool")
316316
}
317317

318318
controllerutil.RemoveFinalizer(machinePoolScope.RosaMachinePool, expinfrav1.RosaMachinePoolFinalizer)
@@ -360,21 +360,14 @@ func (r *ROSAMachinePoolReconciler) updateNodePool(machinePoolScope *scope.RosaM
360360
machinePool := machinePoolScope.RosaMachinePool.DeepCopy()
361361
// default all fields before comparing, so that nil/unset fields don't cause an unnecessary update call.
362362
machinePool.Default()
363-
364363
desiredSpec := machinePool.Spec
365-
currentSpec := nodePoolToRosaMachinePoolSpec(nodePool)
366364

367-
ignoredFields := []string{
368-
"ProviderIDList", // providerIDList is set by the controller.
369-
"Version", // Version changes are reconciled separately.
370-
"AdditionalTags", // AdditionalTags day2 changes not supported.
371-
}
372-
if cmp.Equal(desiredSpec, currentSpec,
373-
cmpopts.EquateEmpty(), // ensures empty non-nil slices and nil slices are considered equal.
374-
cmpopts.IgnoreFields(currentSpec, ignoredFields...)) {
365+
specDiff := computeSpecDiff(desiredSpec, nodePool)
366+
if specDiff == "" {
375367
// no changes detected.
376368
return nodePool, nil
377369
}
370+
machinePoolScope.Info("MachinePool spec diff detected", "diff", specDiff)
378371

379372
// zero-out fields that shouldn't be part of the update call.
380373
desiredSpec.Version = ""
@@ -400,6 +393,21 @@ func (r *ROSAMachinePoolReconciler) updateNodePool(machinePoolScope *scope.RosaM
400393
return updatedNodePool, nil
401394
}
402395

396+
func computeSpecDiff(desiredSpec expinfrav1.RosaMachinePoolSpec, nodePool *cmv1.NodePool) string {
397+
currentSpec := nodePoolToRosaMachinePoolSpec(nodePool)
398+
399+
ignoredFields := []string{
400+
"ProviderIDList", // providerIDList is set by the controller.
401+
"Version", // Version changes are reconciled separately.
402+
"AdditionalTags", // AdditionalTags day2 changes not supported.
403+
"AdditionalSecurityGroups", // AdditionalSecurityGroups day2 changes not supported.
404+
}
405+
406+
return cmp.Diff(desiredSpec, currentSpec,
407+
cmpopts.EquateEmpty(), // ensures empty non-nil slices and nil slices are considered equal.
408+
cmpopts.IgnoreFields(currentSpec, ignoredFields...))
409+
}
410+
403411
func validateMachinePoolSpec(machinePoolScope *scope.RosaMachinePoolScope) (*string, error) {
404412
if machinePoolScope.RosaMachinePool.Spec.Version == "" {
405413
return nil, nil
@@ -517,7 +525,7 @@ func nodePoolToRosaMachinePoolSpec(nodePool *cmv1.NodePool) expinfrav1.RosaMachi
517525
}
518526
}
519527
if nodePool.Taints() != nil {
520-
rosaTaints := make([]expinfrav1.RosaTaint, len(nodePool.Taints()))
528+
rosaTaints := make([]expinfrav1.RosaTaint, 0, len(nodePool.Taints()))
521529
for _, taint := range nodePool.Taints() {
522530
rosaTaints = append(rosaTaints, expinfrav1.RosaTaint{
523531
Key: taint.Key(),

exp/controllers/rosamachinepool_controller_test.go

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import (
44
"testing"
55
"time"
66

7-
"github.com/google/go-cmp/cmp/cmpopts"
87
. "github.com/onsi/gomega"
8+
corev1 "k8s.io/api/core/v1"
99
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1010
"k8s.io/apimachinery/pkg/util/intstr"
1111
"k8s.io/utils/ptr"
@@ -33,18 +33,30 @@ func TestNodePoolToRosaMachinePoolSpec(t *testing.T) {
3333
MaxUnavailable: ptr.To(intstr.FromInt32(5)),
3434
},
3535
},
36+
AdditionalSecurityGroups: []string{
37+
"id-1",
38+
"id-2",
39+
},
40+
Labels: map[string]string{
41+
"label1": "value1",
42+
"label2": "value2",
43+
},
44+
Taints: []expinfrav1.RosaTaint{
45+
{
46+
Key: "myKey",
47+
Value: "myValue",
48+
Effect: corev1.TaintEffectNoExecute,
49+
},
50+
},
3651
}
3752

3853
machinePoolSpec := expclusterv1.MachinePoolSpec{
3954
Replicas: ptr.To[int32](2),
4055
}
4156

4257
nodePoolBuilder := nodePoolBuilder(rosaMachinePoolSpec, machinePoolSpec)
43-
4458
nodePoolSpec, err := nodePoolBuilder.Build()
4559
g.Expect(err).ToNot(HaveOccurred())
4660

47-
expectedSpec := nodePoolToRosaMachinePoolSpec(nodePoolSpec)
48-
49-
g.Expect(rosaMachinePoolSpec).To(BeComparableTo(expectedSpec, cmpopts.EquateEmpty()))
61+
g.Expect(computeSpecDiff(rosaMachinePoolSpec, nodePoolSpec)).To(BeEmpty())
5062
}

0 commit comments

Comments
 (0)