Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release-2.5] 🐛 ROSA: fix ROSAMachinePool changes detection logic #5025

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 25 additions & 7 deletions exp/controllers/rosamachinepool_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/aws/aws-sdk-go/service/ec2"
"github.com/blang/semver"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
cmv1 "github.com/openshift-online/ocm-sdk-go/clustersmgmt/v1"
"github.com/openshift/rosa/pkg/ocm"
"github.com/pkg/errors"
Expand Down Expand Up @@ -220,6 +221,11 @@ func (r *ROSAMachinePoolReconciler) reconcileNormal(ctx context.Context,
}

if found {
if rosaMachinePool.Spec.AvailabilityZone == "" {
// reflect the current AvailabilityZone in the spec if not set.
rosaMachinePool.Spec.AvailabilityZone = nodePool.AvailabilityZone()
}

nodePool, err := r.updateNodePool(machinePoolScope, ocmClient, nodePool)
if err != nil {
return ctrl.Result{}, fmt.Errorf("failed to ensure rosaMachinePool: %w", err)
Expand Down Expand Up @@ -349,13 +355,23 @@ func (r *ROSAMachinePoolReconciler) reconcileMachinePoolVersion(machinePoolScope
}

func (r *ROSAMachinePoolReconciler) updateNodePool(machinePoolScope *scope.RosaMachinePoolScope, ocmClient *ocm.Client, nodePool *cmv1.NodePool) (*cmv1.NodePool, error) {
desiredSpec := machinePoolScope.RosaMachinePool.Spec.DeepCopy()

desiredSpec := *machinePoolScope.RosaMachinePool.Spec.DeepCopy()
currentSpec := nodePoolToRosaMachinePoolSpec(nodePool)
currentSpec.ProviderIDList = desiredSpec.ProviderIDList // providerIDList is set by the controller and shouldn't be compared here.
currentSpec.Version = desiredSpec.Version // Version changes are reconciled separately and shouldn't be compared here.

if cmp.Equal(desiredSpec, currentSpec) {
if desiredSpec.NodeDrainGracePeriod == nil {
// currentSpec.NodeDrainGracePeriod is always non-nil.
// if desiredSpec.NodeDrainGracePeriod is nil, set to 0 so we update the nodePool, otherewise the current value will be preserved.
desiredSpec.NodeDrainGracePeriod = &metav1.Duration{}
}

ignoredFields := []string{
"ProviderIDList", // providerIDList is set by the controller.
"Version", // Version changes are reconciled separately.
"AdditionalTags", // AdditionalTags day2 changes not supported.
}
if cmp.Equal(desiredSpec, currentSpec,
cmpopts.EquateEmpty(), // ensures empty non-nil slices and nil slices are considered equal.
cmpopts.IgnoreFields(currentSpec, ignoredFields...)) {
// no changes detected.
return nodePool, nil
}
Expand All @@ -365,7 +381,7 @@ func (r *ROSAMachinePoolReconciler) updateNodePool(machinePoolScope *scope.RosaM
desiredSpec.AdditionalSecurityGroups = nil
desiredSpec.AdditionalTags = nil

npBuilder := nodePoolBuilder(*desiredSpec, machinePoolScope.MachinePool.Spec)
npBuilder := nodePoolBuilder(desiredSpec, machinePoolScope.MachinePool.Spec)
nodePoolSpec, err := npBuilder.Build()
if err != nil {
return nil, fmt.Errorf("failed to build nodePool spec: %w", err)
Expand Down Expand Up @@ -470,11 +486,13 @@ func nodePoolToRosaMachinePoolSpec(nodePool *cmv1.NodePool) expinfrav1.RosaMachi
AvailabilityZone: nodePool.AvailabilityZone(),
Subnet: nodePool.Subnet(),
Labels: nodePool.Labels(),
AdditionalTags: nodePool.AWSNodePool().Tags(),
AutoRepair: nodePool.AutoRepair(),
InstanceType: nodePool.AWSNodePool().InstanceType(),
TuningConfigs: nodePool.TuningConfigs(),
AdditionalSecurityGroups: nodePool.AWSNodePool().AdditionalSecurityGroupIds(),
// nodePool.AWSNodePool().Tags() returns all tags including "system" tags if "fetchUserTagsOnly" parameter is not specified.
// TODO: enable when AdditionalTags day2 changes is supported.
// AdditionalTags: nodePool.AWSNodePool().Tags(),
}

if nodePool.Autoscaling() != nil {
Expand Down
4 changes: 0 additions & 4 deletions exp/controllers/rosamachinepool_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/ptr"

infrav1 "sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta2"
expinfrav1 "sigs.k8s.io/cluster-api-provider-aws/v2/exp/api/v1beta2"
expclusterv1 "sigs.k8s.io/cluster-api/exp/api/v1beta1"
)
Expand All @@ -26,9 +25,6 @@ func TestNodePoolToRosaMachinePoolSpec(t *testing.T) {
NodeDrainGracePeriod: &metav1.Duration{
Duration: time.Minute * 10,
},
AdditionalTags: infrav1.Tags{
"tag1": "value1",
},
}

machinePoolSpec := expclusterv1.MachinePoolSpec{
Expand Down