Skip to content

Use controllerutil for create or update #121

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

Merged

Conversation

carbonin
Copy link
Contributor

@carbonin carbonin commented Apr 2, 2025

The current create or update function causes problems when called for an update with a resource that was freshly created in code (not queried from the existing cluster).

This is solved by using controllerutil.CreateOrPatch which handles doing this query, applying changes, and only updating if changes were made.

This PR updates all our uses of the existing util function to the controllerutil version as well as cleans up some existing functions to ensure 😉 they're only doing one thing.


WIP until I take care of the last caller and remove the function.

Summary by CodeRabbit

  • New Features
    • Enhanced the cluster management process with improved logic for managing cluster deployment references and configurations.
    • Updated image registry configuration generation to return simplified data outputs.
  • Refactor
    • Streamlined the reconciliation process for cluster deployments and image registry configurations.
  • Bug Fixes
    • Addressed issues related to error handling in the cluster deployment logic.
  • Tests
    • Adjusted test cases to align with the updated function names and logic for image registry data generation.
  • Chores
    • Removed outdated utility functions and test files to clean up the codebase.

carbonin added 9 commits April 2, 2025 15:09
When updating this causes an error like:
```
2025-04-02T18:57:32Z	ERROR	failed creating ClusterImageSet	{"controller": "clusterdeployment", "controllerGroup": "hive.openshift.io", "controllerKind": "ClusterDeployment", "ClusterDeployment": {"name":"test-multinode","namespace":"test-capi"}, "namespace": "test-capi", "name": "test-multinode", "reconcileID": "18ea3061-27ad-4efb-ab87-f9f859a301d9", "error": "clusterimagesets.hive.openshift.io \"test-multinode\" is invalid: metadata.resourceVersion: Invalid value: 0x0: must be specified for an update"}
github.com/openshift-assisted/cluster-api-agent/controlplane/internal/controller.(*ClusterDeploymentReconciler).ensureAgentClusterInstall
	/workspace/controlplane/internal/controller/clusterdeployment_controller.go:114
github.com/openshift-assisted/cluster-api-agent/controlplane/internal/controller.(*ClusterDeploymentReconciler).Reconcile
	/workspace/controlplane/internal/controller/clusterdeployment_controller.go:91
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller[...]).Reconcile
	/go/pkg/mod/sigs.k8s.io/controller-runtime@v0.19.6/pkg/internal/controller/controller.go:116
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller[...]).reconcileHandler
	/go/pkg/mod/sigs.k8s.io/controller-runtime@v0.19.6/pkg/internal/controller/controller.go:303
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller[...]).processNextWorkItem
	/go/pkg/mod/sigs.k8s.io/controller-runtime@v0.19.6/pkg/internal/controller/controller.go:263
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller[...]).Start.func2.2
	/go/pkg/mod/sigs.k8s.io/controller-runtime@v0.19.6/pkg/internal/controller/controller.go:224
```
@openshift-ci openshift-ci bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Apr 2, 2025
Copy link

coderabbitai bot commented Apr 2, 2025

Walkthrough

This update refactors parts of the control plane by modifying key reconciliation functions and renaming several image registry functions. In the ClusterDeployment controller, error handling is streamlined by having the ensureAgentClusterInstall method return only an error while consolidating mutation logic. Additionally, the computation of the ClusterImageSet has been revised by replacing computeClusterImageSet with ensureClusterImageSet. In the image registry package, the function for generating configuration data has been renamed from GenerateImageRegistryConfigmap to GenerateImageRegistryData and now returns a map instead of a ConfigMap, with corresponding test updates.

Changes

File(s) Summary of Changes
controlplane/internal/controller/clusterdeployment_controller.go Refactored reconciliation logic:
- Reconcile now retrieves architecture from bootstrap configs and ensures creation of a ClusterImageSet.
- ensureAgentClusterInstall now returns only an error and leverages controllerutil.CreateOrPatch for mutating AgentClusterInstall.
- updateClusterDeploymentRef updated to use the ClusterDeployment name.
- Replaced computeClusterImageSet with ensureClusterImageSet.
controlplane/internal/imageregistry/image_registry.go
controlplane/internal/imageregistry/image_registry_test.go
Renamed function from GenerateImageRegistryConfigmap to GenerateImageRegistryData and updated its return type from (*corev1.ConfigMap, error) to (map[string]string, error).
The function now focuses on generating key-value pairs for registry manifests, and test cases have been updated accordingly.
assistedinstaller/clusterdeployment.go Deleted file containing the GetClusterDeploymentFromConfig function, which created and returned a ClusterDeployment object based on provided configurations.
controlplane/internal/controller/openshiftassistedcontrolplane_controller.go Updated OpenshiftAssistedControlPlaneReconciler:
- Modified ensureClusterDeployment to construct a ClusterDeployment directly instead of using the deleted function.
- Added setClusterDeploymentRef method for updating the ClusterDeployment reference.
util/suite_test.go Deleted file containing a test suite for utility functions using the Ginkgo framework.
util/util.go Removed CreateOrUpdate function responsible for creating or updating Kubernetes objects, eliminating associated logic for handling these operations.
util/util_test.go Deleted file containing a test suite for the CreateOrUpdate function, which validated the behavior of utility functions in managing Kubernetes deployments.

Possibly related PRs

  • MGMT-20162: improve usage of CreateOrUpdate #103: The changes in the main PR are related to those in the retrieved PR as both involve modifications to the ClusterDeploymentReconciler class in clusterdeployment_controller.go, specifically focusing on the handling of the ensureAgentClusterInstall method and the integration of the CreateOrUpdate logic.
  • MGMT-20067: remove arch suffix from Spec.DistributionVersion #102: The changes in the main PR are related to those in the retrieved PR as both involve modifications to how architecture information is handled in the context of OpenshiftAssistedConfig and image retrieval processes, specifically focusing on the integration of architecture data into method signatures and logic.

Suggested labels

do-not-merge/hold, jira/valid-reference, size/L

Suggested reviewers

  • adriengentil
  • CrystalChun

Poem

I’m a rabbit hopping through lines of code,
Tweaking functions along a winding road.
Methods simplify with every bound,
New names and types cheerfully found.
Carrots and commits, side by side,
In our digital warren, joy does abide!
🐇✨

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (1.64.8)

level=warning msg="The linter 'exportloopref' is deprecated (since v1.60.2) due to: Since Go1.22 (loopvar) this linter is no longer relevant. Replaced by copyloopvar."
level=error msg="[linters_context] exportloopref: This linter is fully inactivated: it will not produce any reports."
{"Issues":[],"Report":{"Warnings":[{"Text":"The linter 'exportloopref' is deprecated (since v1.60.2) due to: Since Go1.22 (loopvar) this linter is no longer relevant. Replaced by copyloopvar."}],"Linters":[{"Name":"asasalint"},{"Name":"asciicheck"},{"Name":"bidichk"},{"Name":"bodyclose"},{"Name":"canonicalheader"},{"Name":"containedctx"},{"Name":"contextcheck"},{"Name":"copyloopvar"},{"Name":"cyclop"},{"Name":"decorder"},{"Name":"deadcode"},{"Name":"depguard"},{"Name":"dogsled"},{"Name":"dupl","Enabled":true},{"Name":"dupword"},{"Name":"durationcheck"},{"Name":"errcheck","Enabled":true,"EnabledByDefault":true},{"Name":"errchkjson"},{"Name":"errname"},{"Name":"errorlint"},{"Name":"execinquery"},{"Name":"exhaustive"},{"Name":"exhaustivestruct"},{"Name":"exhaustruct"},{"Name":"exportloopref","Enabled":true},{"Name":"exptostd"},{"Name":"forbidigo"},{"Name":"forcetypeassert"},{"Name":"fatcontext"},{"Name":"funlen"},{"Name":"gci"},{"Name":"ginkgolinter"},{"Name":"gocheckcompilerdirectives"},{"Name":"gochecknoglobals"},{"Name":"gochecknoinits"},{"Name":"gochecksumtype"},{"Name":"gocognit"},{"Name":"goconst","Enabled":true},{"Name":"gocritic"},{"Name":"gocyclo","Enabled":true},{"Name":"godot"},{"Name":"godox"},{"Name":"err113"},{"Name":"gofmt","Enabled":true},{"Name":"gofumpt"},{"Name":"goheader"},{"Name":"goimports","Enabled":true},{"Name":"golint"},{"Name":"mnd"},{"Name":"gomnd"},{"Name":"gomoddirectives"},{"Name":"gomodguard"},{"Name":"goprintffuncname"},{"Name":"gosec"},{"Name":"gosimple","Enabled":true,"EnabledByDefault":true},{"Name":"gosmopolitan"},{"Name":"govet","Enabled":true,"EnabledByDefault":true},{"Name":"grouper"},{"Name":"ifshort"},{"Name":"iface"},{"Name":"importas"},{"Name":"inamedparam"},{"Name":"ineffassign","Enabled":true,"EnabledByDefault":true},{"Name":"interfacebloat"},{"Name":"interfacer"},{"Name":"intrange"},{"Name":"ireturn"},{"Name":"lll","Enabled":true},{"Name":"loggercheck"},{"Name":"maintidx"},{"Name":"makezero"},{"Name":"maligned"},{"Name":"mirror"},{"Name":"misspell","Enabled":true},{"Name":"musttag"},{"Name":"nakedret","Enabled":true},{"Name":"nestif"},{"Name":"nilerr"},{"Name":"nilnesserr"},{"Name":"nilnil"},{"Name":"nlreturn"},{"Name":"noctx"},{"Name":"nonamedreturns"},{"Name":"nosnakecase"},{"Name":"nosprintfhostport"},{"Name":"paralleltest"},{"Name":"perfsprint"},{"Name":"prealloc","Enabled":true},{"Name":"predeclared"},{"Name":"promlinter"},{"Name":"protogetter"},{"Name":"reassign"},{"Name":"recvcheck"},{"Name":"revive"},{"Name":"rowserrcheck"},{"Name":"sloglint"},{"Name":"scopelint"},{"Name":"sqlclosecheck"},{"Name":"spancheck"},{"Name":"staticcheck","Enabled":true,"EnabledByDefault":true},{"Name":"structcheck"},{"Name":"stylecheck"},{"Name":"tagalign"},{"Name":"tagliatelle"},{"Name":"tenv"},{"Name":"testableexamples"},{"Name":"testifylint"},{"Name":"testpackage"},{"Name":"thelper"},{"Name":"tparallel"},{"Name":"typecheck","Enabled":true,"EnabledByDefault":true},{"Name":"unconvert","Enabled":true},{"Name":"unparam","Enabled":true},{"Name":"unused","Enabled":true,"EnabledByDefault":true},{"Name":"usestdlibvars"},{"Name":"usetesting"},{"Name":"varcheck"},{"Name":"varnamelen"},{"Name":"wastedassign"},{"Name":"whitespace"},{"Name":"wrapcheck"},{"Name":"wsl"},{"Name":"zerologlint"},{"Name":"nolintlint"}],"Error":"exportloopref: This linter is fully inactivated: it will not produce any reports."}}

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@openshift-ci openshift-ci bot requested review from CrystalChun and eranco74 April 2, 2025 20:56
@openshift-ci openshift-ci bot added approved Indicates a PR has been approved by an approver from all required OWNERS files. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Apr 2, 2025
@rccrdpccl
Copy link
Contributor

/lgtm
/approve

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Apr 3, 2025
@rccrdpccl
Copy link
Contributor

I finally understand why controlleruitls' CreateOrUpdate it's so inconvenient to use.. 😓

We should probably remove our CreateOrUpdate within this PR too

@carbonin
Copy link
Contributor Author

carbonin commented Apr 3, 2025

Yeah, there's still one more caller I need to change, but that was my goal.

@openshift-ci openshift-ci bot removed lgtm Indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Apr 3, 2025
@carbonin carbonin changed the title [WIP] Use controllerutil for create or update Use controllerutil for create or update Apr 3, 2025
@openshift-ci openshift-ci bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. labels Apr 3, 2025
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
controlplane/internal/controller/openshiftassistedcontrolplane_controller.go (1)

191-194: Typographical fix needed in log message.
The word "ClusterDeploment" is misspelled on line 192. Consider correcting it to "ClusterDeployment".

- log.Error(err, "failed to set OACP ClusterDeploment reference")
+ log.Error(err, "failed to set OACP ClusterDeployment reference")
controlplane/internal/controller/clusterdeployment_controller.go (1)

101-107: Image registry creation logic is triggered conditionally.
Consider naming the helper as ensureImageRegistry for clarity.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 20d7cd5 and 05bb6a6.

📒 Files selected for processing (6)
  • assistedinstaller/clusterdeployment.go (0 hunks)
  • controlplane/internal/controller/clusterdeployment_controller.go (5 hunks)
  • controlplane/internal/controller/openshiftassistedcontrolplane_controller.go (4 hunks)
  • util/suite_test.go (0 hunks)
  • util/util.go (0 hunks)
  • util/util_test.go (0 hunks)
💤 Files with no reviewable changes (4)
  • util/suite_test.go
  • util/util.go
  • assistedinstaller/clusterdeployment.go
  • util/util_test.go
🧰 Additional context used
🧬 Code Definitions (1)
controlplane/internal/controller/openshiftassistedcontrolplane_controller.go (2)
util/util.go (1)
  • ControlPlaneMachineLabelsForCluster (42-61)
controlplane/api/v1alpha2/openshiftassistedcontrolplane_types.go (1)
  • OpenshiftAssistedControlPlane (239-245)
🔇 Additional comments (39)
controlplane/internal/controller/openshiftassistedcontrolplane_controller.go (12)

28-28: No concerns regarding this new import.


38-38: Import looks correct.


40-40: No issues with this added import.


512-513: Confirm necessity of skipping updates.
If the ClusterDeploymentRef is already set, the remaining logic is bypassed. Verify that this behavior is intended if changes to acp.Spec.Config occur after the reference is initially established.


516-517: Override of cluster name is clear and logical.
No issues identified.


520-520: Constructing a new ClusterDeployment object.
No concerns here.


521-525: Metadata assignment looks good.
No issues identified.


527-548: CreateOrPatch usage is appropriate.
The reference to controllerutil.SetOwnerReference ensures correct ownership. Spec fields appear consistent with HPC logic.


549-550: Returning the CreateOrPatch error is clean.
No issues identified.


552-560: Introducing setClusterDeploymentRef helper.
Implementation approach is clear for setting the status reference.


563-563: Logging the Get operation outcome is handled up the call chain.
No issues here.


572-577: Reference extraction ensures accurate status.
Storing a reference to the retrieved ClusterDeployment object is correct.

controlplane/internal/controller/clusterdeployment_controller.go (27)

46-46: Added controllerutil for resource patching/creation.
No issues here.


92-95: Architecture retrieval is straightforward.
Error handling is appropriate.


96-100: Potential naming conflict for ClusterImageSet creation.
Using clusterDeployment.Name as the ClusterImageSet name might cause collisions if multiple ClusterDeployment objects share the same name across namespaces. Verify uniqueness or consider a namespaced or hashed scheme.


108-110: EnsureAgentClusterInstall invocation is consistent with the new flow.
No issues identified.


119-120: Signature returns only an error now.
This simplifies error flow.


125-125: Returning early on error.
Implementation is aligned with newly simplified logic.


128-131: Gathering worker node count and cluster config references.
Variables are neatly assembled.


132-136: Instantiating AgentClusterInstall CR.
Construct is straightforward and consistent with hive extension.


139-144: Setting labels for ACI object.
The usage of util.ControlPlaneMachineLabelsForCluster is consistent with labeling strategy.


146-146: OwnerReference is properly set with OACP.
This ensures correct ownership in the cluster's resource graph.


148-169: AgentClusterInstall spec definition.
Fields correctly map to relevant fields in OpenshiftAssistedConfig. The logic for forcing baremetal platform when VIPs are set is coherent.


170-170: ACICapabilities call is properly invoked.
No issues identified.


171-173: Error returned if capabilities setting fails.
The fallback logic looks clean.


175-175: CreateOrPatch usage for AgentClusterInstall.
Practice aligns with recommended controller patterns.


176-178: Error handling logs a clear message.
Implementation is consistent with the rest of the file.


227-228: New ensureClusterImageSet function.
Naming conveys intention clearly. No issues identified.


234-238: CreateOrPatch with a function closure for imageSet.
Pattern is appropriate for reconciling cluster-wide resources.


239-239: Returning the final error.
Logic is clean and consistent.


242-242: Utility for retrieving cluster networks.
Function signature correctly returns a pair of networks.


255-256: Returning computed cluster networks.
No issues identified.


258-258: Function retrieving additional manifests references.
Naming is clear; content is consistent with the rest of the code.


268-268: Returning aggregated manifest references.
No issues identified.


271-271: createImageRegistry method introduced.
Implements retrieval of an existing configmap and generating new image registry config if needed.


277-278: Delegates data generation to imageregistry package.
Error handling is appropriate.


282-286: Initialize the new ConfigMap object.
Approach is consistent with the standard K8s resource creation patterns.


288-292: Setting ConfigMap data via CreateOrPatch.
Implementation ensures idempotent creation or update.


293-293: Return the final error.
Conclusion of the creation logic. Looks good.

Comment on lines +511 to +513
if acp.Status.ClusterDeploymentRef != nil {
return nil
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Wouldn't we still want to go through the create or patch function below even if the cluster deployment ref is set in the ACP's status? Like in the event the ACP's pull secret ref change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree generally, but this was the behavior before so I just kept it as is for this PR.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Gotcha, sorry didn't catch that it was prior behavior.

@CrystalChun
Copy link
Collaborator

One question, but looks great otherwise!

@carbonin
Copy link
Contributor Author

carbonin commented Apr 3, 2025

/hold

Want to fix one more thing

@openshift-ci openshift-ci bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Apr 3, 2025
@carbonin
Copy link
Contributor Author

carbonin commented Apr 3, 2025

/unhold

@openshift-ci openshift-ci bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Apr 3, 2025
carbonin added 5 commits April 3, 2025 13:54
This avoids the case where the controller attempts to update and already
altered object which results in an error, it also issues fewer changes
to the server as only the fields we want to change are considered an
update.
This was attempting to set the `UserManagedNetworking` field to nil
when it had previously been defaulted to some value by the
assisted-service controllers.

This error can be seen in logs like:

```
2025-04-03T16:17:55Z	ERROR	Reconciler error	{"controller": "clusterdeployment", "controllerGroup": "hive.openshift.io", "controllerKind": "ClusterDeployment", "ClusterDeployment": {"name":"test-multinode","namespace":"test-capi"}, "namespace": "test-capi", "name": "test-multinode", "reconcileID": "316eee13-3248-4919-9569-f40026a9a95f", "error": "admission webhook \"agentclusterinstallvalidators.admission.agentinstall.openshift.io\" denied the request: Attempted to change AgentClusterInstall.Spec which is immutable after install started, except for ClusterMetadata,IgnitionEndpoint fields. Unsupported change: \n\tNetworking.UserManagedNetworking: (0xc000988c4c => <nil>)"}
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller[...]).reconcileHandler
	/go/pkg/mod/sigs.k8s.io/controller-runtime@v0.19.6/pkg/internal/controller/controller.go:316
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller[...]).processNextWorkItem
	/go/pkg/mod/sigs.k8s.io/controller-runtime@v0.19.6/pkg/internal/controller/controller.go:263
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller[...]).Start.func2.2
	/go/pkg/mod/sigs.k8s.io/controller-runtime@v0.19.6/pkg/internal/controller/controller.go:224
```
@carbonin carbonin force-pushed the fix-create-or-update branch from 96e0af3 to 8a0e537 Compare April 3, 2025 17:54
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
controlplane/internal/controller/openshiftassistedcontrolplane_controller.go (2)

511-513: Consider updating on existing references as well.
Returning early if the cluster deployment reference is already set means changes won't propagate if updates are needed (e.g., re-synchronizing with new specs).

 if acp.Status.ClusterDeploymentRef != nil {
-    return nil
+    // Optionally check if the existing reference needs to be updated or re-synced
 }

519-525: Potential logging enhancement.
Creating a new ClusterDeployment object is beneficial for visibility. Consider adding a debug/info log before the CreateOrPatch call.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 05bb6a6 and 8a0e537.

📒 Files selected for processing (6)
  • assistedinstaller/clusterdeployment.go (0 hunks)
  • controlplane/internal/controller/clusterdeployment_controller.go (5 hunks)
  • controlplane/internal/controller/openshiftassistedcontrolplane_controller.go (4 hunks)
  • util/suite_test.go (0 hunks)
  • util/util.go (0 hunks)
  • util/util_test.go (0 hunks)
💤 Files with no reviewable changes (4)
  • util/suite_test.go
  • assistedinstaller/clusterdeployment.go
  • util/util_test.go
  • util/util.go
🧰 Additional context used
🧬 Code Definitions (1)
controlplane/internal/controller/clusterdeployment_controller.go (2)
util/util.go (1)
  • ControlPlaneMachineLabelsForCluster (42-61)
controlplane/internal/imageregistry/image_registry.go (2)
  • ImageConfigMapName (20-20)
  • GenerateImageRegistryData (38-90)
🔇 Additional comments (29)
controlplane/internal/controller/openshiftassistedcontrolplane_controller.go (5)

28-40: New imports appear consistent with the API usage.
Imports for v1alpha2, hiveextension/v1beta1, and the Hive agent package correctly align with the references in this file. No concerns.


190-195: Proper integration with setClusterDeploymentRef.
This invocation appropriately handles error logging and returning, neatly tying in the newly introduced function that sets the reference in the ACP status.


515-517: Clear, concise cluster name override.
If acp.Spec.Config.ClusterName is specified, it correctly takes precedence. Implementation is straightforward.


527-550: Safe creation or patch for ClusterDeployment.
Utilizing CreateOrPatch and setting necessary fields (owner reference, labels, platform) aligns well with best practices for reconcilers.


552-579: Robust function for setting the ACP status reference.
Good handling of a non-existent ClusterDeployment and clearing the reference if not found. Error handling is clear.

controlplane/internal/controller/clusterdeployment_controller.go (24)

46-46: Import for controllerutil
This import is necessary for the CreateOrPatch usage throughout the controller.


92-107: Ensuring the cluster image set and optional image registry creation.
• Fetching the architecture before calling ensureClusterImageSet is logical.
• The conditional creation of image registry resources based on acp.Spec.Config.ImageRegistryRef is nicely structured.
No critical issues found.


108-112: Final steps in Reconcile flow.
Cleanly ensures the AgentClusterInstall and updates the ClusterDeploymentRef. This clear ordering helps maintainers.


119-119: Refactored signature to return only error.
This simplifies error handling, reducing confusion about separate ctrl.Result.


129-129: Determining worker node count.
Extraction into getWorkerNodesCount is a neat separation of concerns, enhancing readability.


130-131: Retrieving cluster networks.
Storing the networks at this stage supports building the ACI spec properly.


132-138: Initializing AgentClusterInstall resource.
Good approach: using the ClusterDeployment name and namespace for consistency.


139-144: Setting labels & owner references.
Leverages utility functions to keep label logic consistent across the codebase.


148-149: ClusterDeploymentRef assignment in the ACI spec.
Accurately references the parent cluster deployment. Straightforward approach.


150-153: Provision requirements.
Assigning control plane and worker agent counts addresses the bare-metal provisioning logic effectively.


154-157: Configuration assignments.
Applying the user-specified DiskEncryption, MastersSchedulable, Proxy, SSHAuthorizedKey ensures consistent configurations.


158-161: Cluster networking.
Populating ClusterNetwork and ServiceNetwork from the retrieved data. No issues.


162-162: Appending manifest config references.
Allows additional cluster manifests to be deployed as part of the installation.


163-167: Bare metal VIP handling.
Manages custom VIP values for APIVIPs and IngressVIPs, switching the platform type to BareMetal.


168-168: Setting capabilities.
The call to setACICapabilities is consistent with the rest of the configuration logic.


174-174: CreateOrPatch for ACI
Ensures the resource is created or updated in a single transaction. Proper usage.


175-176: Error logging
Logs any failure from the patch operation. Sufficient detail is provided.


220-220: Assigning ClusterInstallRef
Points the cluster deployment to the AgentClusterInstall object, aligning with Hive's relationships.


225-238: ensureClusterImageSet
Creates or patches the ClusterImageSet with the correct release image. Straightforward approach.


240-254: Gathering cluster network CIDR blocks.
Using the Cluster.Spec.ClusterNetwork fields for building the ACI's networking arrays.


256-256: Manifest references aggregator function.
Combining user-specified config map references with the registry config map if present.


269-269: Creating image registry.
Fetches the registry configmap and reuses its data to generate a new config for the spoke cluster.


275-275: Generating image registry data.
Leverages the extracted logic in imageregistry.GenerateImageRegistryData, centralizing registry setup.


280-291: Constructing or patching the final ConfigMap.
Populating cm.Data with the generated config ensures that the image registry info is correctly conveyed to the cluster.

Copy link
Collaborator

@CrystalChun CrystalChun left a comment

Choose a reason for hiding this comment

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

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Apr 3, 2025
Copy link

openshift-ci bot commented Apr 3, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: carbonin, CrystalChun, rccrdpccl

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:
  • OWNERS [CrystalChun,carbonin,rccrdpccl]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-merge-bot openshift-merge-bot bot merged commit 52da144 into openshift-assisted:master Apr 3, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. 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