Skip to content

Conversation

serngawy
Copy link
Contributor

@serngawy serngawy commented Aug 23, 2025

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:

  • squashed commits
  • includes documentation
  • includes emoji in title
  • adds unit tests
  • adds or updates e2e tests

Release note:

Fix ROSA control plane manage default ROSA machine pool 

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. kind/bug Categorizes issue or PR as related to a bug. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Aug 23, 2025
@k8s-ci-robot k8s-ci-robot added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. needs-priority labels Aug 23, 2025
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign neolit123 for approval. For more information see the Code Review Process.

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Aug 23, 2025
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 23, 2025
@serngawy serngawy force-pushed the rosacluster branch 2 times, most recently from 490e22e to 2cbe834 Compare August 25, 2025 08:30
@serngawy
Copy link
Contributor Author

/cc @marek-veber

@k8s-ci-robot
Copy link
Contributor

@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:

/cc @marek-veber

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.

@serngawy
Copy link
Contributor Author

/cc @nrb

@k8s-ci-robot k8s-ci-robot requested a review from nrb August 25, 2025 09:17
@AndiDog AndiDog changed the title 🐛 ROSA: Fix RosaControlPlane sync defaulet RosaMachinePool 🐛 ROSA: Fix RosaControlPlane sync default RosaMachinePool Aug 27, 2025
@serngawy
Copy link
Contributor Author

/hold

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Aug 27, 2025
@serngawy
Copy link
Contributor Author

/unhold

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Aug 27, 2025
Copy link
Member

@damdo damdo left a 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!

Comment on lines 135 to 151
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)
}
}
Copy link
Member

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.

Copy link
Contributor Author

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

@serngawy serngawy force-pushed the rosacluster branch 2 times, most recently from 80cbf54 to 8671a32 Compare September 10, 2025 13:07
Comment on lines 136 to 152
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)
}
}

Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay, done

@serngawy
Copy link
Contributor Author

/test pull-cluster-api-provider-aws-apidiff-main

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. needs-priority release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants