NO-ISSUE: Change BareMetalHostRef's type to LocalObjectReference#827
NO-ISSUE: Change BareMetalHostRef's type to LocalObjectReference#827giladravid16 wants to merge 1 commit intoopenshift:mainfrom
Conversation
|
@giladravid16: This pull request explicitly references no jira issue. DetailsIn 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 openshift-eng/jira-lifecycle-plugin repository. |
WalkthroughReplaces the custom Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes 🚥 Pre-merge checks | ✅ 10 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (10 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Review rate limit: 9/10 reviews remaining, refill in 6 minutes. Comment |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: giladravid16 The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
controllers/imageclusterinstall_controller.go (1)
610-633:⚠️ Potential issue | 🟠 Major | ⚡ Quick winFilter the BMH watch mapping by namespace, not just name.
After dropping the namespace field from the index, this mapper now enqueues every
ImageClusterInstallwhosespec.bareMetalHostRef.namematches the changed BMH name anywhere in the cluster. A change tons-a/host-0will also trigger reconciles forns-bICIs that reference their ownhost-0, which can fan out badly in all-namespaces mode.Suggested fix
var requests []reconcile.Request for _, ici := range iciList.Items { + if ici.Namespace != bmhNamespace { + continue + } // Create a request only if the installation hasn't started if ici.Status.BootTime.IsZero() { req := reconcile.Request{ NamespacedName: types.NamespacedName{ Namespace: ici.Namespace,🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@controllers/imageclusterinstall_controller.go` around lines 610 - 633, The current mapper uses only ".spec.bareMetalHostRef.name" to list ImageClusterInstalls, causing cross-namespace matches; update the mapping to also restrict by namespace—either add a second MatchingFields entry for ".spec.bareMetalHostRef.namespace" using the BMH namespace variable (e.g., bmhNamespace) or, after calling r.List into iciList, filter the results by comparing each ici.Spec.BareMetalHostRef.Namespace to the BMH namespace before appending the reconcile.Request; keep the existing check for ici.Status.BootTime.IsZero() when building requests.api/v1alpha1/imageclusterinstall_types.go (1)
92-128:⚠️ Potential issue | 🔴 Critical | ⚡ Quick winRegenerate the API deepcopy/webhook artifacts before merging.
Typecheck is currently broken after this type swap:
ImageClusterInstallno longer satisfiesruntime.Object, andImageClusterInstallSpec.DeepCopyis missing in the webhook path. That usually means the generated deepcopy files were not refreshed after changing these API fields. Please rerun the API generators and commit the updated generated artifacts.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@api/v1alpha1/imageclusterinstall_types.go` around lines 92 - 128, The API types were changed (e.g., ImageClusterInstall, ImageClusterInstallSpec and ImageClusterInstallStatus) but the generated deepcopy/webhook artifacts were not updated, causing ImageClusterInstall to no longer satisfy runtime.Object and ImageClusterInstallSpec.DeepCopy to be missing; regenerate the codegen artifacts (deepcopy, client, listers/webhooks as your project uses) by rerunning your repository's API generators (e.g., controller-gen and/or your project's hack/update-codegen scripts), commit the updated generated files, and verify ImageClusterInstall now implements runtime.Object and that ImageClusterInstallSpec.DeepCopy exists.
🧹 Nitpick comments (1)
controllers/imageclusterinstall_controller_test.go (1)
2638-2644: ⚡ Quick winAdd a cross-namespace collision test for
mapBMHToICIWith name-only indexing (Line [2638]-Line [2644]), please add one regression test that creates two
ImageClusterInstallobjects in different namespaces referencing the same BMH name, then asserts only the BMH’s namespace is enqueued. This protects the new LocalObjectReference behavior from accidental cross-namespace matches.Proposed test addition
+It("does not return requests from other namespaces with the same BMH name", func() { + bmh := &bmh_v1alpha1.BareMetalHost{ + ObjectMeta: metav1.ObjectMeta{ + Name: "test-bmh", + Namespace: clusterInstallNamespace, + }, + } + Expect(c.Create(ctx, bmh)).To(Succeed()) + + sameNS := &v1alpha1.ImageClusterInstall{ + ObjectMeta: metav1.ObjectMeta{ + Name: clusterInstallName, + Namespace: clusterInstallNamespace, + }, + Spec: v1alpha1.ImageClusterInstallSpec{ + BareMetalHostRef: &corev1.LocalObjectReference{Name: bmh.Name}, + }, + } + Expect(c.Create(ctx, sameNS)).To(Succeed()) + + otherNS := &v1alpha1.ImageClusterInstall{ + ObjectMeta: metav1.ObjectMeta{ + Name: "other-ns-ici", + Namespace: "other-namespace", + }, + Spec: v1alpha1.ImageClusterInstallSpec{ + BareMetalHostRef: &corev1.LocalObjectReference{Name: bmh.Name}, + }, + } + Expect(c.Create(ctx, otherNS)).To(Succeed()) + + requests := r.mapBMHToICI(ctx, bmh) + Expect(requests).To(HaveLen(1)) + Expect(requests[0].NamespacedName).To(Equal(types.NamespacedName{ + Name: clusterInstallName, + Namespace: clusterInstallNamespace, + })) +})🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@controllers/imageclusterinstall_controller_test.go` around lines 2638 - 2644, Add a regression test for mapBMHToICI: when the index is name-only (WithIndex key ".spec.bareMetalHostRef.name"), create two ImageClusterInstall objects in different namespaces that both reference a BareMetalHost with the same Name, then call mapBMHToICI and assert the resulting reconcile request enqueues only the BareMetalHost's namespace (not both ImageClusterInstall namespaces); locate test helpers and usages around WithIndex and the mapBMHToICI invocation in controllers/imageclusterinstall_controller_test.go and ensure the test constructs ImageClusterInstall.Spec.BareMetalHostRef as a LocalObjectReference to exercise the cross-namespace protection.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@api/v1alpha1/imageclusterinstall_types.go`:
- Around line 90-92: The change removed namespace information from the
BareMetalHostRef causing CRs that referenced BareMetalHosts in other namespaces
to be misresolved; revert to an explicit namespaced reference and add
validation: change the BareMetalHostRef field type from
corev1.LocalObjectReference to corev1.ObjectReference (so it includes Name and
Namespace) in the ImageClusterInstall spec, update the field comment to require
Namespace when referencing cross-namespace BMHs, and add/adjust the
ImageClusterInstall admission validation (ValidateCreate/ValidateUpdate) to
reject empty or ambiguous namespaces (or explicitly require a migration step) so
existing persisted CRs keep their intended target rather than silently resolving
to ici.Namespace.
---
Outside diff comments:
In `@api/v1alpha1/imageclusterinstall_types.go`:
- Around line 92-128: The API types were changed (e.g., ImageClusterInstall,
ImageClusterInstallSpec and ImageClusterInstallStatus) but the generated
deepcopy/webhook artifacts were not updated, causing ImageClusterInstall to no
longer satisfy runtime.Object and ImageClusterInstallSpec.DeepCopy to be
missing; regenerate the codegen artifacts (deepcopy, client, listers/webhooks as
your project uses) by rerunning your repository's API generators (e.g.,
controller-gen and/or your project's hack/update-codegen scripts), commit the
updated generated files, and verify ImageClusterInstall now implements
runtime.Object and that ImageClusterInstallSpec.DeepCopy exists.
In `@controllers/imageclusterinstall_controller.go`:
- Around line 610-633: The current mapper uses only
".spec.bareMetalHostRef.name" to list ImageClusterInstalls, causing
cross-namespace matches; update the mapping to also restrict by namespace—either
add a second MatchingFields entry for ".spec.bareMetalHostRef.namespace" using
the BMH namespace variable (e.g., bmhNamespace) or, after calling r.List into
iciList, filter the results by comparing each
ici.Spec.BareMetalHostRef.Namespace to the BMH namespace before appending the
reconcile.Request; keep the existing check for ici.Status.BootTime.IsZero() when
building requests.
---
Nitpick comments:
In `@controllers/imageclusterinstall_controller_test.go`:
- Around line 2638-2644: Add a regression test for mapBMHToICI: when the index
is name-only (WithIndex key ".spec.bareMetalHostRef.name"), create two
ImageClusterInstall objects in different namespaces that both reference a
BareMetalHost with the same Name, then call mapBMHToICI and assert the resulting
reconcile request enqueues only the BareMetalHost's namespace (not both
ImageClusterInstall namespaces); locate test helpers and usages around WithIndex
and the mapBMHToICI invocation in
controllers/imageclusterinstall_controller_test.go and ensure the test
constructs ImageClusterInstall.Spec.BareMetalHostRef as a LocalObjectReference
to exercise the cross-namespace protection.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository: openshift/coderabbit/.coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: 45f51792-42ce-47d6-9d93-5c86092bf7de
⛔ Files ignored due to path filters (1)
api/v1alpha1/zz_generated.deepcopy.gois excluded by!**/zz_generated*
📒 Files selected for processing (11)
api/v1alpha1/imageclusterinstall_types.goapi/v1alpha1/imageclusterinstall_webhook_test.gobundle/manifests/extensions.hive.openshift.io_imageclusterinstalls.yamlbundle/manifests/image-based-install-operator.clusterserviceversion.yamlconfig/crd/bases/extensions.hive.openshift.io_imageclusterinstalls.yamlconfig/samples/extensions_v1alpha1_imageclusterinstall.yamlcontrollers/imageclusterinstall_controller.gocontrollers/imageclusterinstall_controller_test.gocontrollers/imageclusterinstall_monitor.gocontrollers/imageclusterinstall_monitor_test.gohack/integration-test/imageclusterinstall.yaml
💤 Files with no reviewable changes (2)
- hack/integration-test/imageclusterinstall.yaml
- config/samples/extensions_v1alpha1_imageclusterinstall.yaml
| // BareMetalHostRef identifies a BareMetalHost object to be used to attach the configuration to the host. | ||
| // +optional | ||
| BareMetalHostRef *BareMetalHostReference `json:"bareMetalHostRef,omitempty"` | ||
| BareMetalHostRef *corev1.LocalObjectReference `json:"bareMetalHostRef,omitempty"` |
There was a problem hiding this comment.
This silently changes the meaning of existing CRs that used a different BMH namespace.
Before this change, persisted spec.bareMetalHostRef.namespace values were honored; after this change the controller resolves the BMH from ici.Namespace instead. Any existing ImageClusterInstall that referenced a host in another namespace will now either stop finding it or, worse, resolve a same-named BMH in the ICI namespace. This needs an explicit migration/validation story before rollout.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@api/v1alpha1/imageclusterinstall_types.go` around lines 90 - 92, The change
removed namespace information from the BareMetalHostRef causing CRs that
referenced BareMetalHosts in other namespaces to be misresolved; revert to an
explicit namespaced reference and add validation: change the BareMetalHostRef
field type from corev1.LocalObjectReference to corev1.ObjectReference (so it
includes Name and Namespace) in the ImageClusterInstall spec, update the field
comment to require Namespace when referencing cross-namespace BMHs, and
add/adjust the ImageClusterInstall admission validation
(ValidateCreate/ValidateUpdate) to reject empty or ambiguous namespaces (or
explicitly require a migration step) so existing persisted CRs keep their
intended target rather than silently resolving to ici.Namespace.
|
/hold |
|
@giladravid16: The following tests failed, say
Full PR test history. Your PR dashboard. DetailsInstructions 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. I understand the commands that are listed here. |
Summary by CodeRabbit
Release Notes
Breaking Changes
spec.bareMetalHostRefandstatus.bareMetalHostRef).Refactor