Skip to content

Commit 3dbaaf2

Browse files
muraeek8s-infra-cherrypick-robot
authored and
k8s-infra-cherrypick-robot
committed
fix ROSAMachinePool changes detection logic
1 parent 3b350ef commit 3dbaaf2

File tree

2 files changed

+25
-11
lines changed

2 files changed

+25
-11
lines changed

exp/controllers/rosamachinepool_controller.go

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/aws/aws-sdk-go/service/ec2"
1010
"github.com/blang/semver"
1111
"github.com/google/go-cmp/cmp"
12+
"github.com/google/go-cmp/cmp/cmpopts"
1213
cmv1 "github.com/openshift-online/ocm-sdk-go/clustersmgmt/v1"
1314
"github.com/openshift/rosa/pkg/ocm"
1415
"github.com/pkg/errors"
@@ -220,6 +221,11 @@ func (r *ROSAMachinePoolReconciler) reconcileNormal(ctx context.Context,
220221
}
221222

222223
if found {
224+
if rosaMachinePool.Spec.AvailabilityZone == "" {
225+
// reflect the current AvailabilityZone in the spec if not set.
226+
rosaMachinePool.Spec.AvailabilityZone = nodePool.AvailabilityZone()
227+
}
228+
223229
nodePool, err := r.updateNodePool(machinePoolScope, ocmClient, nodePool)
224230
if err != nil {
225231
return ctrl.Result{}, fmt.Errorf("failed to ensure rosaMachinePool: %w", err)
@@ -349,13 +355,23 @@ func (r *ROSAMachinePoolReconciler) reconcileMachinePoolVersion(machinePoolScope
349355
}
350356

351357
func (r *ROSAMachinePoolReconciler) updateNodePool(machinePoolScope *scope.RosaMachinePoolScope, ocmClient *ocm.Client, nodePool *cmv1.NodePool) (*cmv1.NodePool, error) {
352-
desiredSpec := machinePoolScope.RosaMachinePool.Spec.DeepCopy()
353-
358+
desiredSpec := *machinePoolScope.RosaMachinePool.Spec.DeepCopy()
354359
currentSpec := nodePoolToRosaMachinePoolSpec(nodePool)
355-
currentSpec.ProviderIDList = desiredSpec.ProviderIDList // providerIDList is set by the controller and shouldn't be compared here.
356-
currentSpec.Version = desiredSpec.Version // Version changes are reconciled separately and shouldn't be compared here.
357360

358-
if cmp.Equal(desiredSpec, currentSpec) {
361+
if desiredSpec.NodeDrainGracePeriod == nil {
362+
// currentSpec.NodeDrainGracePeriod is always non-nil.
363+
// if desiredSpec.NodeDrainGracePeriod is nil, set to 0 so we update the nodePool, otherewise the current value will be preserved.
364+
desiredSpec.NodeDrainGracePeriod = &metav1.Duration{}
365+
}
366+
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...)) {
359375
// no changes detected.
360376
return nodePool, nil
361377
}
@@ -365,7 +381,7 @@ func (r *ROSAMachinePoolReconciler) updateNodePool(machinePoolScope *scope.RosaM
365381
desiredSpec.AdditionalSecurityGroups = nil
366382
desiredSpec.AdditionalTags = nil
367383

368-
npBuilder := nodePoolBuilder(*desiredSpec, machinePoolScope.MachinePool.Spec)
384+
npBuilder := nodePoolBuilder(desiredSpec, machinePoolScope.MachinePool.Spec)
369385
nodePoolSpec, err := npBuilder.Build()
370386
if err != nil {
371387
return nil, fmt.Errorf("failed to build nodePool spec: %w", err)
@@ -470,11 +486,13 @@ func nodePoolToRosaMachinePoolSpec(nodePool *cmv1.NodePool) expinfrav1.RosaMachi
470486
AvailabilityZone: nodePool.AvailabilityZone(),
471487
Subnet: nodePool.Subnet(),
472488
Labels: nodePool.Labels(),
473-
AdditionalTags: nodePool.AWSNodePool().Tags(),
474489
AutoRepair: nodePool.AutoRepair(),
475490
InstanceType: nodePool.AWSNodePool().InstanceType(),
476491
TuningConfigs: nodePool.TuningConfigs(),
477492
AdditionalSecurityGroups: nodePool.AWSNodePool().AdditionalSecurityGroupIds(),
493+
// nodePool.AWSNodePool().Tags() returns all tags including "system" tags if "fetchUserTagsOnly" parameter is not specified.
494+
// TODO: enable when AdditionalTags day2 changes is supported.
495+
// AdditionalTags: nodePool.AWSNodePool().Tags(),
478496
}
479497

480498
if nodePool.Autoscaling() != nil {

exp/controllers/rosamachinepool_controller_test.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
99
"k8s.io/utils/ptr"
1010

11-
infrav1 "sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta2"
1211
expinfrav1 "sigs.k8s.io/cluster-api-provider-aws/v2/exp/api/v1beta2"
1312
expclusterv1 "sigs.k8s.io/cluster-api/exp/api/v1beta1"
1413
)
@@ -26,9 +25,6 @@ func TestNodePoolToRosaMachinePoolSpec(t *testing.T) {
2625
NodeDrainGracePeriod: &metav1.Duration{
2726
Duration: time.Minute * 10,
2827
},
29-
AdditionalTags: infrav1.Tags{
30-
"tag1": "value1",
31-
},
3228
}
3329

3430
machinePoolSpec := expclusterv1.MachinePoolSpec{

0 commit comments

Comments
 (0)