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
351357func (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 {
0 commit comments