-
Notifications
You must be signed in to change notification settings - Fork 624
🐛 ROSA: Fix RosaControlPlane sync default RosaMachinePool #5629
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
base: main
Are you sure you want to change the base?
Conversation
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
490e22e
to
2cbe834
Compare
/cc @marek-veber |
@serngawy: GitHub didn't allow me to request PR reviews from the following users: marek-veber. Note that only kubernetes-sigs members and repo collaborators can review this PR, and authors cannot review their own PRs. In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
/cc @nrb |
/hold |
/unhold |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left some thoughts, thanks!
ControllerName: "", | ||
Logger: log, | ||
NewStsClient: r.NewStsClient, | ||
}) | ||
if err != nil { | ||
return ctrl.Result{}, fmt.Errorf("failed to create rosa controlplane scope: %w", err) | ||
} | ||
|
||
if r.NewOCMClient == nil { | ||
return ctrl.Result{}, fmt.Errorf("failed to create OCM client: NewOCMClient is nil") | ||
} | ||
|
||
ocmClient, err := r.NewOCMClient(ctx, rosaScope) | ||
if err != nil || ocmClient == nil { | ||
return ctrl.Result{}, fmt.Errorf("failed to create OCM client: %w", err) | ||
} | ||
|
||
nodePools, err := ocmClient.GetNodePools(rosaScope.ControlPlane.Status.ID) | ||
if err != nil { | ||
return ctrl.Result{}, fmt.Errorf("failed to get nodePools: %w", err) | ||
} | ||
|
||
rosaMPNames, err := r.getRosaMachinePoolNames(ctx, cluster) | ||
if err != nil { | ||
return ctrl.Result{}, fmt.Errorf("failed to get Rosa machinePool names: %w", err) | ||
} | ||
|
||
var errs []error | ||
for _, nodePool := range nodePools { | ||
// continue if nodePool is not in ready state. | ||
if !rosa.IsNodePoolReady(nodePool) { | ||
continue | ||
} | ||
// continue if nodePool exist | ||
if rosaMPNames[nodePool.ID()] { | ||
continue | ||
} | ||
|
||
// create RosaMachinePool | ||
rosaMPSpec := utils.NodePoolToRosaMachinePoolSpec(nodePool) | ||
rosaMachinePool := &expinfrav1.ROSAMachinePool{ | ||
TypeMeta: metav1.TypeMeta{ | ||
APIVersion: expinfrav1.GroupVersion.String(), | ||
Kind: "ROSAMachinePool", | ||
}, | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: nodePool.ID(), | ||
Namespace: controlPlane.Namespace, | ||
Labels: map[string]string{ | ||
clusterv1.ClusterNameLabel: cluster.Name, | ||
}, | ||
}, | ||
Spec: rosaMPSpec, | ||
} | ||
log.Info(fmt.Sprintf("Create ROSAMachinePool %s", rosaMachinePool.Name)) | ||
if err = r.Client.Create(ctx, rosaMachinePool); err != nil { | ||
errs = append(errs, err) | ||
} | ||
|
||
// create MachinePool | ||
machinePool := &expclusterv1.MachinePool{ | ||
TypeMeta: metav1.TypeMeta{ | ||
APIVersion: expclusterv1.GroupVersion.String(), | ||
Kind: "MachinePool", | ||
}, | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: nodePool.ID(), | ||
Namespace: cluster.Namespace, | ||
Labels: map[string]string{ | ||
clusterv1.ClusterNameLabel: cluster.Name, | ||
}, | ||
}, | ||
Spec: expclusterv1.MachinePoolSpec{ | ||
ClusterName: cluster.Name, | ||
Replicas: ptr.To(int32(1)), | ||
Template: clusterv1.MachineTemplateSpec{ | ||
Spec: clusterv1.MachineSpec{ | ||
ClusterName: cluster.Name, | ||
Bootstrap: clusterv1.Bootstrap{ | ||
DataSecretName: ptr.To(string("")), | ||
}, | ||
InfrastructureRef: corev1.ObjectReference{ | ||
APIVersion: expinfrav1.GroupVersion.String(), | ||
Kind: "ROSAMachinePool", | ||
Name: rosaMachinePool.Name, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
log.Info(fmt.Sprintf("Create MachinePool %s", machinePool.Name)) | ||
if err = r.Client.Create(ctx, machinePool); err != nil { | ||
errs = append(errs, err) | ||
} | ||
} | ||
|
||
if len(errs) > 0 { | ||
return ctrl.Result{}, kerrors.NewAggregate(errs) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it'd be nice to extract this into a separate function with a descriptive name.
Also I'd add some comments on what is happening here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add buildROSAMachinePool func and more comments
80cbf54
to
8671a32
Compare
if controlPlane.Status.Ready { | ||
rosaScope, err := scope.NewROSAControlPlaneScope(scope.ROSAControlPlaneScopeParams{ | ||
Client: r.Client, | ||
Cluster: cluster, | ||
ControlPlane: controlPlane, | ||
ControllerName: "", | ||
Logger: log, | ||
NewStsClient: r.NewStsClient, | ||
}) | ||
if err != nil { | ||
return ctrl.Result{}, fmt.Errorf("failed to create rosa controlplane scope: %w", err) | ||
} | ||
|
||
if r.NewOCMClient == nil { | ||
return ctrl.Result{}, fmt.Errorf("failed to create OCM client: NewOCMClient is nil") | ||
} | ||
|
||
ocmClient, err := r.NewOCMClient(ctx, rosaScope) | ||
if err != nil || ocmClient == nil { | ||
return ctrl.Result{}, fmt.Errorf("failed to create OCM client: %w", err) | ||
} | ||
|
||
// List the ROSA-HCP nodePools and MachinePools | ||
nodePools, err := ocmClient.GetNodePools(rosaScope.ControlPlane.Status.ID) | ||
if err != nil { | ||
return ctrl.Result{}, fmt.Errorf("failed to get nodePools: %w", err) | ||
} | ||
|
||
rosaMPNames, err := r.getRosaMachinePoolNames(ctx, cluster) | ||
if err != nil { | ||
return ctrl.Result{}, fmt.Errorf("failed to get Rosa machinePool names: %w", err) | ||
} | ||
|
||
// Ensure every NodePool has a MachinePool and create a corresponding MachinePool if it does not exist. | ||
var errs []error | ||
for _, nodePool := range nodePools { | ||
// continue if nodePool is not in ready state. | ||
if !rosa.IsNodePoolReady(nodePool) { | ||
continue | ||
} | ||
// continue if nodePool exist | ||
if rosaMPNames[nodePool.ID()] { | ||
continue | ||
} | ||
// create ROSAMachinePool & MachinePool | ||
rosaMachinePool, machinePool := r.buildROSAMachinePool(nodePool.ID(), cluster.Name, cluster.Namespace, nodePool) | ||
|
||
log.Info(fmt.Sprintf("Create ROSAMachinePool %s", rosaMachinePool.Name)) | ||
if err = r.Client.Create(ctx, rosaMachinePool); err != nil { | ||
errs = append(errs, err) | ||
} | ||
|
||
log.Info(fmt.Sprintf("Create MachinePool %s", machinePool.Name)) | ||
if err = r.Client.Create(ctx, machinePool); err != nil { | ||
errs = append(errs, err) | ||
} | ||
} | ||
|
||
if len(errs) > 0 { | ||
return ctrl.Result{}, kerrors.NewAggregate(errs) | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this entire block could be extracted out to a function with a good name and that simplifies reading this and gaining context without delving into the details
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okay, done
8671a32
to
3641b8a
Compare
/test pull-cluster-api-provider-aws-apidiff-main |
3641b8a
to
1600047
Compare
Signed-off-by: serngawy <[email protected]>
What type of PR is this?
/kind bug
CAPA does not automatically manage the default "workers" machinepool created by ROSAControlPlane
What this PR does / why we need it:
Which issue(s) this PR fixes (optional, in
fixes #<issue number>(, fixes #<issue_number>, ...)
format, will close the issue(s) when PR gets merged):Fixes #
Special notes for your reviewer:
Checklist:
Release note: