Skip to content

Conversation

@afritzler
Copy link
Member

@afritzler afritzler commented Dec 18, 2025

Proposed Changes

  • Refactor BIOSVersion webhook
  • Updated tests

Summary by CodeRabbit

  • Refactor

    • Centralized test cleanup into AfterEach hooks with explicit clean-state verification; removed per-test deferred deletions.
    • Standardized webhook validation logging and normalized field-name usage in error messages.
  • Tests

    • Updated tests to use generate-name resource creation and rely on centralized cleanup (no explicit namespaces).
    • Test helpers realigned to current resource types and expanded zero-item validations.

✏️ Tip: You can customize this high-level summary in your review settings.

@afritzler afritzler requested a review from a team as a code owner December 18, 2025 12:34
@github-actions github-actions bot added enhancement New feature or request size/L labels Dec 18, 2025
@afritzler afritzler force-pushed the enh/biosvers-webhook branch from 120e510 to 7d1a12b Compare December 18, 2025 12:36
- Refactor `BIOSVersion` webhook
- Updated tests
@afritzler afritzler force-pushed the enh/biosvers-webhook branch 3 times, most recently from 7c52de4 to f5b59a6 Compare December 18, 2025 17:00
@afritzler afritzler force-pushed the enh/biosvers-webhook branch from f5b59a6 to 29649ae Compare December 18, 2025 17:11
@afritzler
Copy link
Member Author

@coderabbitai review

@coderabbitai
Copy link

coderabbitai bot commented Dec 19, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai
Copy link

coderabbitai bot commented Dec 19, 2025

Walkthrough

Centralizes test cleanup into AfterEach hooks that delete resource lists and call controller.EnsureCleanState(); embeds client.Client in the BIOSVersion validator; renames local vars/logs to version/versions and field paths to spec.serverRef.name; updates tests to use GenerateName and aligns test-helper list types.

Changes

Cohort / File(s) Summary
Console tests (cleanup)
internal/cmd/console/console_test.go
Add AfterEach teardown to delete Server/BMC/BMCSecret lists and call controller.EnsureCleanState(); remove per-test DeferCleanup calls; add context/controller imports.
BIOSVersion webhook implementation
internal/webhook/v1alpha1/biosversion_webhook.go
Embed client.Client in BIOSVersionCustomValidator; rename logger/vars to version/versions and versionLog; update list usage and checkForDuplicateBIOSVersionRefToServer signature; add nil-guards and change error field paths to spec.serverRef.name.
BIOSVersion webhook tests
internal/webhook/v1alpha1/biosversion_webhook_test.go
Remove explicit Namespace on created objects; replace per-test DeferCleanup with shared AfterEach that deletes BIOSVersion list and calls controller.EnsureCleanState(); adapt tests to renamed vars/validation flows and GenerateName usage; import controller.
BMCSettings webhook tests
internal/webhook/v1alpha1/bmcsettings_webhook_test.go
Add AfterEach teardown deleting BMCSettings list and calling controller.EnsureCleanState(); remove per-test DeferCleanup; import controller.
BMCVersion webhook tests
internal/webhook/v1alpha1/bmcversion_webhook_test.go
Add AfterEach teardown deleting BMCVersion list and calling controller.EnsureCleanState(); remove per-test DeferCleanup calls; import controller.
Endpoint webhook tests
internal/webhook/v1alpha1/endpoint_webhook_test.go
Add AfterEach teardown deleting Endpoint list and calling controller.EnsureCleanState(); remove per-test DeferCleanup; import controller.
Server webhook tests
internal/webhook/v1alpha1/server_webhook_test.go
Add AfterEach teardown deleting Server list and calling controller.EnsureCleanState(); remove per-test DeferCleanup; remove one finalizer mutation from a test; add context/controller imports.
Test helper list checks
internal/controller/test_helper.go
Update list variable names and types to match current APIs (swap BMCListEndpointList, add/rename lists like bmcVersionSets, bmcVersions, biosVersions, biosSettingsSets, maintenances, servers, bmcs, claims); preserve zero-length assertions.
BIOSSettings test description
internal/webhook/v1alpha1/biossettings_webhook_test.go
Minor test description wording change to reference spec.serverRef lowercase; no logic changes.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 1 | ❌ 2
❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
Description check ❓ Inconclusive The description is incomplete; it lists only generic items without explaining what the refactoring entails or why it was necessary. Provide specific details about the refactoring changes, such as the restructuring of cleanup logic, variable renaming, and the adoption of GenerateName-based object creation.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately reflects the main change in the PR, which is refactoring the BIOSVersion webhook and its tests.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

📜 Recent review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ceda80d and 2b7ed78.

📒 Files selected for processing (4)
  • internal/controller/test_helper.go
  • internal/webhook/v1alpha1/biossettings_webhook_test.go
  • internal/webhook/v1alpha1/biosversion_webhook.go
  • internal/webhook/v1alpha1/biosversion_webhook_test.go
✅ Files skipped from review due to trivial changes (1)
  • internal/webhook/v1alpha1/biossettings_webhook_test.go
🧰 Additional context used
🧬 Code graph analysis (3)
internal/webhook/v1alpha1/biosversion_webhook_test.go (5)
api/v1alpha1/biosversion_types.go (6)
  • BIOSVersion (130-136)
  • BIOSVersionSpec (51-63)
  • BIOSVersionTemplate (32-48)
  • ImageSpec (65-78)
  • BIOSVersionStateInProgress (19-19)
  • BIOSVersionStateCompleted (21-21)
internal/controller/test_helper.go (1)
  • EnsureCleanState (15-57)
api/v1alpha1/servermaintenance_types.go (2)
  • ServerMaintenancePolicy (51-51)
  • ServerMaintenancePolicyEnforced (57-57)
api/v1alpha1/common_types.go (1)
  • ObjectReference (16-27)
api/v1alpha1/constants.go (2)
  • OperationAnnotation (21-21)
  • OperationAnnotationForceUpdateInProgress (44-44)
internal/webhook/v1alpha1/biosversion_webhook.go (2)
api/v1alpha1/biosversion_types.go (3)
  • BIOSVersion (130-136)
  • BIOSVersionList (141-145)
  • BIOSVersionStateInProgress (19-19)
internal/webhook/v1alpha1/helper.go (2)
  • ShouldAllowForceUpdateInProgress (12-18)
  • ShouldAllowForceDeleteInProgress (21-27)
internal/controller/test_helper.go (11)
api/v1alpha1/endpoint_types.go (1)
  • EndpointList (46-50)
api/v1alpha1/bmc_types.go (1)
  • BMCList (259-263)
api/v1alpha1/bmcsecret_types.go (1)
  • BMCSecretList (62-66)
api/v1alpha1/serverclaim_types.go (1)
  • ServerClaimList (80-84)
api/v1alpha1/bmcversionset_types.go (1)
  • BMCVersionSetList (60-64)
api/v1alpha1/bmcversion_types.go (1)
  • BMCVersionList (94-98)
api/v1alpha1/biosversion_types.go (1)
  • BIOSVersionList (141-145)
api/v1alpha1/biossettingsset_types.go (1)
  • BIOSSettingsSetList (60-64)
api/v1alpha1/biossettings_types.go (1)
  • BIOSSettingsList (151-155)
api/v1alpha1/servermaintenance_types.go (1)
  • ServerMaintenanceList (99-103)
api/v1alpha1/server_types.go (1)
  • ServerList (439-443)
🔇 Additional comments (8)
internal/controller/test_helper.go (1)

19-53: LGTM! Comprehensive resource cleanup verification.

The updated EnsureCleanState function now checks a comprehensive set of resource lists with consistent variable naming and verification patterns. The additions (endpoints, claims, bmcVersions, biosVersions, etc.) ensure proper test isolation across all webhook and controller tests.

internal/webhook/v1alpha1/biosversion_webhook_test.go (2)

42-48: LGTM! Centralized cleanup pattern.

The AfterEach block properly cleans up all BIOSVersion resources and verifies clean state, replacing the previous DeferCleanup pattern. This centralization improves test maintainability and is consistent with other webhook tests in the PR.


50-193: LGTM! Comprehensive webhook validation tests.

The test suite thoroughly covers BIOSVersion webhook validation scenarios:

  • Duplicate and non-duplicate serverRef handling during create/update
  • In-progress state restrictions for updates and deletes
  • Force update/delete annotation behavior

The tests properly use GenerateName for object creation and call validator methods directly, which is the correct approach for webhook testing.

internal/webhook/v1alpha1/biosversion_webhook.go (5)

40-41: LGTM! Idiomatic use of embedded client.

Embedding client.Client is the idiomatic pattern in controller-runtime webhooks. This promotes client methods directly to the validator and simplifies method calls throughout the code (e.g., v.List() instead of v.Client.List()).


47-59: LGTM! Clean variable naming and proper error handling.

The refactored ValidateCreate uses consistent variable naming (version, versions) and properly handles type assertions and list operations. The duplicate check receives the correct parameters.


62-89: LGTM! Proper update validation with clear old/new distinction.

The ValidateUpdate method correctly:

  • Distinguishes between oldVersion and newVersion with clear variable names
  • Validates in-progress state restrictions (blocks updates when in progress with maintenance ref, unless force annotation is present)
  • Checks for duplicate serverRef in the updated version

92-103: LGTM! Proper deletion validation.

The ValidateDelete method correctly blocks deletion when the BIOSVersion is in progress, unless the force delete annotation is present. The error message is clear and grammatically correct.


105-129: LGTM! Robust duplicate detection with proper nil checks.

The checkForDuplicateBIOSVersionRefToServer function is well-implemented:

  • Nil checks for ServerRef (lines 106-108, 114-116) prevent nil pointer dereferences
  • Correctly skips the same object during updates (lines 111-112)
  • Field path "spec".Child("serverRef").Child("name") matches the JSON schema
  • Clear error messages identify both conflicting resources

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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

🧹 Nitpick comments (1)
internal/webhook/v1alpha1/server_webhook_test.go (1)

46-52: Inconsistent pattern: use type pointer instead of instance.

Line 48 passes server (the instance) to DeleteAllOf, whereas all other webhook tests use the type pointer pattern (e.g., &metalv1alpha1.Server{}). While both work functionally, using the instance is inconsistent and could cause issues if server were unexpectedly nil.

🔎 Suggested fix for consistency
 	AfterEach(func(ctx context.Context) {
 		By("Deleting the server")
-		Expect(k8sClient.DeleteAllOf(ctx, server)).To(Succeed())
+		Expect(k8sClient.DeleteAllOf(ctx, &metalv1alpha1.Server{})).To(Succeed())

 		By("Ensuring clean state")
 		controller.EnsureCleanState()
 	})
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1d36a58 and 29649ae.

📒 Files selected for processing (7)
  • internal/cmd/console/console_test.go (2 hunks)
  • internal/webhook/v1alpha1/biosversion_webhook.go (2 hunks)
  • internal/webhook/v1alpha1/biosversion_webhook_test.go (2 hunks)
  • internal/webhook/v1alpha1/bmcsettings_webhook_test.go (2 hunks)
  • internal/webhook/v1alpha1/bmcversion_webhook_test.go (2 hunks)
  • internal/webhook/v1alpha1/endpoint_webhook_test.go (2 hunks)
  • internal/webhook/v1alpha1/server_webhook_test.go (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (7)
internal/webhook/v1alpha1/biosversion_webhook_test.go (5)
api/v1alpha1/biosversion_types.go (6)
  • BIOSVersion (130-136)
  • BIOSVersionSpec (51-63)
  • BIOSVersionTemplate (32-48)
  • ImageSpec (65-78)
  • BIOSVersionStateInProgress (19-19)
  • BIOSVersionStateCompleted (21-21)
internal/controller/test_helper.go (1)
  • EnsureCleanState (15-51)
api/v1alpha1/servermaintenance_types.go (2)
  • ServerMaintenancePolicy (51-51)
  • ServerMaintenancePolicyEnforced (57-57)
api/v1alpha1/common_types.go (1)
  • ObjectReference (16-27)
api/v1alpha1/constants.go (2)
  • OperationAnnotation (21-21)
  • OperationAnnotationForceUpdateInProgress (44-44)
internal/webhook/v1alpha1/endpoint_webhook_test.go (2)
api/v1alpha1/endpoint_types.go (1)
  • Endpoint (35-41)
internal/controller/test_helper.go (1)
  • EnsureCleanState (15-51)
internal/cmd/console/console_test.go (1)
internal/controller/test_helper.go (1)
  • EnsureCleanState (15-51)
internal/webhook/v1alpha1/server_webhook_test.go (1)
internal/controller/test_helper.go (1)
  • EnsureCleanState (15-51)
internal/webhook/v1alpha1/bmcversion_webhook_test.go (2)
api/v1alpha1/bmcversion_types.go (1)
  • BMCVersion (83-89)
internal/controller/test_helper.go (1)
  • EnsureCleanState (15-51)
internal/webhook/v1alpha1/biosversion_webhook.go (2)
api/v1alpha1/biosversion_types.go (3)
  • BIOSVersion (130-136)
  • BIOSVersionList (141-145)
  • BIOSVersionStateInProgress (19-19)
internal/webhook/v1alpha1/helper.go (2)
  • ShouldAllowForceUpdateInProgress (12-18)
  • ShouldAllowForceDeleteInProgress (21-27)
internal/webhook/v1alpha1/bmcsettings_webhook_test.go (2)
api/v1alpha1/bmcsettings_types.go (1)
  • BMCSettings (80-86)
internal/controller/test_helper.go (1)
  • EnsureCleanState (15-51)
🔇 Additional comments (9)
internal/webhook/v1alpha1/biosversion_webhook.go (5)

25-25: LGTM: Improved log variable naming.

The rename from biosversionlog to versionLog follows Go naming conventions and improves readability.


40-42: LGTM: Idiomatic use of embedded client.

Embedding client.Client promotes its methods and enables cleaner method calls (v.List() vs v.Client.List()). This is a common and recommended pattern in controller-runtime.


47-59: LGTM: Clean validation logic.

The variable renames (version, versions) and use of the promoted v.List() method improve code consistency. The validation logic correctly checks for duplicate ServerRef references.


62-89: LGTM: Correct update validation logic.

The validation properly prevents updates to in-progress BIOS versions (unless force annotation is present) and checks for duplicate ServerRef references. The use of newVersion in the duplicate check correctly handles the case where the object being updated is in the list.


105-130: LGTM: Well-structured duplicate detection.

The refactored function correctly identifies duplicate ServerRef references with proper early returns and clear error messages. The logic correctly handles both create and update scenarios by skipping self-comparison via name matching.

internal/webhook/v1alpha1/bmcsettings_webhook_test.go (1)

45-51: LGTM!

The AfterEach cleanup correctly deletes all BMCSettings resources and verifies cleanup via controller.EnsureCleanState(), which includes BMCSettingsList verification.

internal/webhook/v1alpha1/bmcversion_webhook_test.go (1)

47-53: LGTM!

The AfterEach cleanup properly handles BMCVersion resource deletion and state verification.

internal/cmd/console/console_test.go (1)

20-28: LGTM!

The AfterEach cleanup correctly handles all three resource types (Server, BMC, BMCSecret) created in the tests, and EnsureCleanState() verifies all of them.

internal/webhook/v1alpha1/biosversion_webhook_test.go (1)

50-193: LGTM on test logic!

The refactored tests comprehensively cover:

  • Create/update validation for duplicate ServerRef
  • In-progress state blocking with force override support
  • Delete prevention during in-progress state

The tests properly reset state to Completed before cleanup, ensuring AfterEach can succeed.

@github-actions github-actions bot added size/XL and removed size/L labels Dec 19, 2025
@afritzler
Copy link
Member Author

@coderabbitai generate docstrings

@coderabbitai
Copy link

coderabbitai bot commented Dec 19, 2025

✅ Actions performed

Initiated docstring generation; will generate only if new commits exist.

@coderabbitai
Copy link

coderabbitai bot commented Dec 19, 2025

Note

Docstrings generation - SUCCESS
Generated docstrings for this pull request at #577

coderabbitai bot added a commit that referenced this pull request Dec 19, 2025
Docstrings generation was requested by @afritzler.

* #575 (comment)

The following files were modified:

* `internal/controller/test_helper.go`
* `internal/webhook/v1alpha1/biosversion_webhook.go`
Copy link
Contributor

@Nuckal777 Nuckal777 left a comment

Choose a reason for hiding this comment

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

Thanks. 👍 Just some nitpicks from my side.

@afritzler afritzler force-pushed the enh/biosvers-webhook branch from a21bb3e to 6b81d2f Compare January 7, 2026 08:56
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: 1

🤖 Fix all issues with AI agents
In @internal/webhook/v1alpha1/biosversion_webhook_test.go:
- Around line 181-193: Test comment has a typo and the delete assertion is
inconsistent with other tests; update the comment "Deleting the BIOSSettings V1
should fail" to "Deleting the BIOSVersion V1 should fail" and replace the
integration-style call Expect(k8sClient.Delete(ctx,
biosVersionV1)).To(Not(Succeed())) with a validator call for consistency, e.g.,
call validator.ValidateDelete(ctx, biosVersionV1) and assert it returns the
expected error (or document why k8sClient.Delete is necessary if integration
behavior is required); locate symbols biosVersionV1, k8sClient.Delete, and
validator.ValidateDelete (and the surrounding UpdateStatus helper) to apply the
changes.
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a21bb3e and 6b81d2f.

📒 Files selected for processing (3)
  • internal/controller/test_helper.go
  • internal/webhook/v1alpha1/biosversion_webhook.go
  • internal/webhook/v1alpha1/biosversion_webhook_test.go
🧰 Additional context used
🧬 Code graph analysis (3)
internal/webhook/v1alpha1/biosversion_webhook_test.go (4)
api/v1alpha1/biosversion_types.go (4)
  • BIOSVersion (130-136)
  • BIOSVersionSpec (51-63)
  • BIOSVersionTemplate (32-48)
  • ImageSpec (65-78)
internal/controller/test_helper.go (1)
  • EnsureCleanState (15-57)
api/v1alpha1/servermaintenance_types.go (2)
  • ServerMaintenancePolicy (51-51)
  • ServerMaintenancePolicyEnforced (57-57)
api/v1alpha1/common_types.go (1)
  • ObjectReference (16-27)
internal/controller/test_helper.go (10)
api/v1alpha1/endpoint_types.go (1)
  • EndpointList (46-50)
api/v1alpha1/bmc_types.go (1)
  • BMCList (259-263)
api/v1alpha1/bmcsecret_types.go (1)
  • BMCSecretList (62-66)
api/v1alpha1/bmcsettings_types.go (1)
  • BMCSettingsList (91-95)
api/v1alpha1/bmcversionset_types.go (1)
  • BMCVersionSetList (60-64)
api/v1alpha1/bmcversion_types.go (1)
  • BMCVersionList (94-98)
api/v1alpha1/biosversion_types.go (1)
  • BIOSVersionList (141-145)
api/v1alpha1/biossettingsset_types.go (1)
  • BIOSSettingsSetList (60-64)
api/v1alpha1/biossettings_types.go (1)
  • BIOSSettingsList (151-155)
api/v1alpha1/servermaintenance_types.go (1)
  • ServerMaintenanceList (99-103)
internal/webhook/v1alpha1/biosversion_webhook.go (2)
api/v1alpha1/biosversion_types.go (3)
  • BIOSVersion (130-136)
  • BIOSVersionList (141-145)
  • BIOSVersionStateInProgress (19-19)
internal/webhook/v1alpha1/helper.go (2)
  • ShouldAllowForceUpdateInProgress (12-18)
  • ShouldAllowForceDeleteInProgress (21-27)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: Run test chart
  • GitHub Check: Run test e2e
  • GitHub Check: Run linter
  • GitHub Check: Run tests
🔇 Additional comments (7)
internal/controller/test_helper.go (4)

19-29: LGTM!

The new resource list checks for EndpointList, BMCList, BMCSecretList, and ServerClaimList are correctly implemented and follow the established pattern with consistent naming conventions.


34-38: LGTM!

The BMCVersionSetList and BMCVersionList checks are correctly implemented with consistent variable naming.


40-47: LGTM!

The BIOS-related resource checks are correctly implemented. The biosSettingsList naming is appropriate given that BIOSSettings is already plural, as previously discussed.


49-53: LGTM!

The ServerMaintenanceList and ServerList checks complete the comprehensive resource cleanup verification with consistent naming.

internal/webhook/v1alpha1/biosversion_webhook.go (1)

25-129: LGTM! Clean refactoring with improved code quality.

The refactoring improves the codebase in several ways:

  • Embedding client.Client (line 41) enables more idiomatic method calls (v.List() vs. v.Client.List())
  • Variable renaming (biosversionversion, biosVersionListversions) is more concise and clearer
  • Early return for nil ServerRef (lines 106-108) is good defensive coding
  • All validation logic remains correct and consistent
internal/webhook/v1alpha1/biosversion_webhook_test.go (2)

42-48: LGTM! Cleanup approach is correct.

The centralized AfterEach cleanup using DeleteAllOf and controller.EnsureCleanState() aligns with the pattern used across other webhook tests in this PR.


50-153: LGTM! Test structure is clear and comprehensive.

The tests properly cover:

  • Duplicate ServerRef validation on create and update
  • Non-duplicate scenarios
  • Different field duplication (which should be allowed)

All tests consistently use the validator directly and have clear descriptions.

@afritzler afritzler force-pushed the enh/biosvers-webhook branch from 6b81d2f to f482e18 Compare January 7, 2026 09:01
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: 1

🤖 Fix all issues with AI agents
In @internal/webhook/v1alpha1/biosversion_webhook_test.go:
- Line 155: Update the test description string passed to the It(...) call in the
BIOSVersion webhook tests: change "Should no allow update a BIOSVersion is in
progress, but should allow to force update it" to "Should not allow update a
BIOSVersion that is in progress, but should allow forcing the update" (or
similar grammatically-correct phrasing) so the test description reads clearly;
locate the It(...) invocation in the biosversion_webhook_test.go test block and
replace only the string literal.
🧹 Nitpick comments (1)
internal/webhook/v1alpha1/biosversion_webhook.go (1)

118-122: Minor: Inconsistent capitalization in error message.

The message uses lowercase "server" initially but uppercase "Server" later. Consider making it consistent.

Proposed fix
-		err := fmt.Errorf("server (%s) referred in %s is duplicate of Server (%s) referred in %s",
+		err := fmt.Errorf("server (%s) referred in %s is duplicate of server (%s) referred in %s",
 			version.Spec.ServerRef.Name,
 			version.Name,
 			bv.Spec.ServerRef.Name,
 			bv.Name,
 		)
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6b81d2f and f482e18.

📒 Files selected for processing (3)
  • internal/controller/test_helper.go
  • internal/webhook/v1alpha1/biosversion_webhook.go
  • internal/webhook/v1alpha1/biosversion_webhook_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • internal/controller/test_helper.go
🧰 Additional context used
🧬 Code graph analysis (2)
internal/webhook/v1alpha1/biosversion_webhook_test.go (5)
api/v1alpha1/biosversion_types.go (6)
  • BIOSVersion (130-136)
  • BIOSVersionSpec (51-63)
  • BIOSVersionTemplate (32-48)
  • ImageSpec (65-78)
  • BIOSVersionStateInProgress (19-19)
  • BIOSVersionStateCompleted (21-21)
internal/controller/test_helper.go (1)
  • EnsureCleanState (15-57)
api/v1alpha1/servermaintenance_types.go (2)
  • ServerMaintenancePolicy (51-51)
  • ServerMaintenancePolicyEnforced (57-57)
api/v1alpha1/common_types.go (1)
  • ObjectReference (16-27)
api/v1alpha1/constants.go (2)
  • OperationAnnotation (21-21)
  • OperationAnnotationForceUpdateInProgress (44-44)
internal/webhook/v1alpha1/biosversion_webhook.go (2)
api/v1alpha1/biosversion_types.go (3)
  • BIOSVersion (130-136)
  • BIOSVersionList (141-145)
  • BIOSVersionStateInProgress (19-19)
internal/webhook/v1alpha1/helper.go (2)
  • ShouldAllowForceUpdateInProgress (12-18)
  • ShouldAllowForceDeleteInProgress (21-27)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Run test chart
  • GitHub Check: Run tests
  • GitHub Check: Run test e2e
🔇 Additional comments (6)
internal/webhook/v1alpha1/biosversion_webhook_test.go (2)

42-48: LGTM - Centralized cleanup pattern looks good.

The AfterEach block properly cleans up BIOSVersion resources and calls EnsureCleanState() to ensure test isolation. This aligns with the cleanup pattern used in other webhook test files.


50-153: LGTM - Comprehensive ServerRef duplication tests.

Good coverage of both create and update validation scenarios. Tests properly verify that:

  • Duplicate ServerRef is rejected on create/update
  • Non-duplicate ServerRef is allowed
  • Duplication in other fields (like Image) doesn't trigger rejection
internal/webhook/v1alpha1/biosversion_webhook.go (4)

40-41: Good refactor using embedded client.

Embedding client.Client directly is idiomatic Go and enables cleaner method calls (e.g., v.List() instead of v.Client.List()).


47-88: LGTM - Validation logic is sound.

Both ValidateCreate and ValidateUpdate properly:

  • Cast and validate the object type
  • Check for duplicate ServerRef across existing resources
  • ValidateUpdate additionally blocks updates when in-progress (unless force annotation is present)

99-100: LGTM - Grammar fix applied.

The error message now reads correctly: "The BIOS version is in progress and cannot be deleted".


105-129: LGTM - Duplicate check implementation is correct.

Good defensive coding with:

  • Early return when ServerRef is nil (line 106-108)
  • Self-exclusion to avoid false positives during updates (line 111-113)
  • Proper field path construction matching JSON tags (spec.serverRef.name)

@afritzler afritzler force-pushed the enh/biosvers-webhook branch from f482e18 to 27142c6 Compare January 7, 2026 09:31
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: 1

🤖 Fix all issues with AI agents
In @internal/webhook/v1alpha1/biosversion_webhook_test.go:
- Line 155: Update the test description string inside the It(...) block in
biosversion_webhook_test.go to fix the grammar; replace "Should no allow update
a BIOSVersion is in progress, but should allow to force update it" with a
corrected sentence such as "Should not allow updating a BIOSVersion that is in
progress, but should allow forcing an update" so the test description is clear
and grammatically correct.
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f482e18 and 27142c6.

📒 Files selected for processing (3)
  • internal/controller/test_helper.go
  • internal/webhook/v1alpha1/biosversion_webhook.go
  • internal/webhook/v1alpha1/biosversion_webhook_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • internal/controller/test_helper.go
🧰 Additional context used
🧬 Code graph analysis (2)
internal/webhook/v1alpha1/biosversion_webhook.go (2)
api/v1alpha1/biosversion_types.go (3)
  • BIOSVersion (130-136)
  • BIOSVersionList (141-145)
  • BIOSVersionStateInProgress (19-19)
internal/webhook/v1alpha1/helper.go (2)
  • ShouldAllowForceUpdateInProgress (12-18)
  • ShouldAllowForceDeleteInProgress (21-27)
internal/webhook/v1alpha1/biosversion_webhook_test.go (5)
api/v1alpha1/biosversion_types.go (4)
  • BIOSVersion (130-136)
  • BIOSVersionSpec (51-63)
  • BIOSVersionTemplate (32-48)
  • ImageSpec (65-78)
internal/controller/test_helper.go (1)
  • EnsureCleanState (15-57)
api/v1alpha1/servermaintenance_types.go (2)
  • ServerMaintenancePolicy (51-51)
  • ServerMaintenancePolicyEnforced (57-57)
api/v1alpha1/common_types.go (1)
  • ObjectReference (16-27)
api/v1alpha1/constants.go (2)
  • OperationAnnotation (21-21)
  • OperationAnnotationForceUpdateInProgress (44-44)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Run test chart
  • GitHub Check: Run tests
  • GitHub Check: Run test e2e
🔇 Additional comments (7)
internal/webhook/v1alpha1/biosversion_webhook_test.go (1)

181-193: Fix comment typo and consider test consistency.

Two issues remain from previous review:

  1. Line 187: Comment says "BIOSSettings V1" but should say "BIOSVersion V1" (copy-paste error)

  2. Line 188: Inconsistent test approach - this test uses k8sClient.Delete() while all other validation tests call validator methods directly (see lines 65, 106, 129, 152, 169, 173). Consider using validator.ValidateDelete(ctx, biosVersionV1) for consistency with the test suite pattern.

📝 Proposed fix
-		By("Deleting the BIOSSettings V1 should fail")
-		Expect(k8sClient.Delete(ctx, biosVersionV1)).To(Not(Succeed()))
+		By("Deleting the BIOSVersion V1 should fail")
+		Expect(validator.ValidateDelete(ctx, biosVersionV1)).Error().To(HaveOccurred())

Likely an incorrect or invalid review comment.

internal/webhook/v1alpha1/biosversion_webhook.go (6)

25-25: LGTM! Clean refactoring of logging variable and client embedding.

The rename from biosversionlog to versionLog improves clarity, and embedding client.Client (line 41) follows idiomatic Go patterns. The embedded client is correctly used throughout (lines 55, 84).

Also applies to: 41-41


47-59: LGTM! ValidateCreate method refactored with improved naming.

Variable naming (version, versions) is more concise and consistent. The list operation correctly uses the embedded client pattern.


62-89: LGTM! ValidateUpdate method refactored with clearer variable names.

The rename to newVersion and oldVersion improves code readability. The in-progress validation logic correctly checks the old version's state while applying restrictions to the new version.


92-103: LGTM! ValidateDelete method refactored consistently.

Variable naming aligns with the other validation methods. The grammar fix from the previous review has been correctly applied (line 100).


105-108: LGTM! Defensive nil check prevents potential panic.

The nil check for version.Spec.ServerRef (lines 106-108) is essential defensive programming. Without it, line 117 would panic when attempting to access version.Spec.ServerRef.Name. Returning nil when ServerRef is nil is correct—there's no duplicate to check.


110-130: LGTM! Correct field path casing and sound duplicate detection logic.

The name comparison (lines 111-113) correctly handles both create and update scenarios—it skips the object being validated during updates (preventing false positives) and is harmless during creates (when the object isn't in the list yet).

The field path change from "ServerRef" to "serverRef" (line 126) is important: Kubernetes field paths in error messages must use JSON field names (lowerCamelCase convention) rather than Go struct names (PascalCase). This ensures error messages correctly identify the problematic field in API requests.

@afritzler afritzler force-pushed the enh/biosvers-webhook branch from 27142c6 to c1634b3 Compare January 7, 2026 09:48
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 (1)
internal/webhook/v1alpha1/biosversion_webhook_test.go (1)

50-66: Minor grammar issue in test descriptions.

The article "an" before "BIOSVersion" should be "a" since "BIOS" starts with a consonant sound (/b/). This appears in multiple By() statements throughout the file.

📝 Proposed fix for this and similar occurrences
 	By("Creating an BIOSVersion")
+	By("Creating a BIOSVersion")

Apply similar fixes to lines 25, 51, 69, 87, 103, 110, 126, 133, and 149.

📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 27142c6 and c1634b3.

📒 Files selected for processing (3)
  • internal/controller/test_helper.go
  • internal/webhook/v1alpha1/biosversion_webhook.go
  • internal/webhook/v1alpha1/biosversion_webhook_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • internal/controller/test_helper.go
🧰 Additional context used
🧬 Code graph analysis (1)
internal/webhook/v1alpha1/biosversion_webhook.go (2)
api/v1alpha1/biosversion_types.go (3)
  • BIOSVersion (130-136)
  • BIOSVersionList (141-145)
  • BIOSVersionStateInProgress (19-19)
internal/webhook/v1alpha1/helper.go (2)
  • ShouldAllowForceUpdateInProgress (12-18)
  • ShouldAllowForceDeleteInProgress (21-27)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Run test chart
  • GitHub Check: Run test e2e
  • GitHub Check: Run tests
🔇 Additional comments (5)
internal/webhook/v1alpha1/biosversion_webhook_test.go (2)

42-48: Cleanup logic looks correct.

The centralized AfterEach cleanup properly deletes all BIOSVersion resources and invokes controller.EnsureCleanState() to ensure a clean test environment.


155-179: In-progress validation test is well structured.

The test properly validates that updates are blocked when in InProgress state with a maintenance reference, and allows updates when the force annotation is present. The state transitions are correctly tested.

internal/webhook/v1alpha1/biosversion_webhook.go (3)

40-42: Embedded client.Client is a valid pattern.

Using an embedded field allows calling v.List(ctx, versions) directly without the v.Client.List() syntax. Note that line 30 still uses {Client: mgr.GetClient()} which works fine with embedded types in Go.


105-129: Improved duplicate check with proper nil guards.

The refactored function now includes:

  1. Early return if version.Spec.ServerRef is nil (lines 106-108)
  2. Self-exclusion check to skip the current version during updates (lines 111-113)
  3. Nil check for each item's ServerRef (lines 114-116)

These guards prevent nil pointer dereferences and ensure correct behavior during both create and update operations.


73-80: Update validation logic correctly handles in-progress state.

The condition properly checks:

  1. Old version is in InProgress state
  2. Force update annotation is not present
  3. ServerMaintenanceRef is set

This ensures users cannot accidentally modify an in-progress BIOS update while still allowing force overrides when needed.

@afritzler afritzler force-pushed the enh/biosvers-webhook branch from c1634b3 to 99de57b Compare January 7, 2026 09:55
@afritzler
Copy link
Member Author

@coderabbitai review

@coderabbitai
Copy link

coderabbitai bot commented Jan 7, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

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 (1)
internal/webhook/v1alpha1/biosversion_webhook_test.go (1)

181-193: Consider using validator method for consistency.

This test uses k8sClient.Delete(ctx, biosVersionV1) (line 188) while all other tests in this file call validator methods directly (e.g., lines 65, 106, 129, 152). For consistency and clearer unit-test focus, consider using validator.ValidateDelete(ctx, biosVersionV1) instead.

If full webhook integration testing is specifically needed here, this is fine—but document why.

♻️ Proposed fix for consistency
-		By("Deleting the BIOSVersion V1 should fail")
-		Expect(k8sClient.Delete(ctx, biosVersionV1)).To(Not(Succeed()))
+		By("Validating deletion of BIOSVersion V1 should fail")
+		Expect(validator.ValidateDelete(ctx, biosVersionV1)).Error().To(HaveOccurred())
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c1634b3 and 99de57b.

📒 Files selected for processing (3)
  • internal/controller/test_helper.go
  • internal/webhook/v1alpha1/biosversion_webhook.go
  • internal/webhook/v1alpha1/biosversion_webhook_test.go
🧰 Additional context used
🧬 Code graph analysis (2)
internal/webhook/v1alpha1/biosversion_webhook.go (2)
api/v1alpha1/biosversion_types.go (2)
  • BIOSVersion (130-136)
  • BIOSVersionList (141-145)
internal/webhook/v1alpha1/helper.go (2)
  • ShouldAllowForceUpdateInProgress (12-18)
  • ShouldAllowForceDeleteInProgress (21-27)
internal/controller/test_helper.go (12)
api/v1alpha1/endpoint_types.go (1)
  • EndpointList (46-50)
api/v1alpha1/bmc_types.go (1)
  • BMCList (259-263)
api/v1alpha1/bmcsecret_types.go (1)
  • BMCSecretList (62-66)
api/v1alpha1/serverclaim_types.go (1)
  • ServerClaimList (80-84)
api/v1alpha1/bmcsettings_types.go (1)
  • BMCSettingsList (91-95)
api/v1alpha1/bmcversionset_types.go (1)
  • BMCVersionSetList (60-64)
api/v1alpha1/bmcversion_types.go (1)
  • BMCVersionList (94-98)
api/v1alpha1/biosversion_types.go (1)
  • BIOSVersionList (141-145)
api/v1alpha1/biossettingsset_types.go (1)
  • BIOSSettingsSetList (60-64)
api/v1alpha1/biossettings_types.go (1)
  • BIOSSettingsList (151-155)
api/v1alpha1/servermaintenance_types.go (1)
  • ServerMaintenanceList (99-103)
api/v1alpha1/server_types.go (1)
  • ServerList (439-443)
🔇 Additional comments (8)
internal/webhook/v1alpha1/biosversion_webhook_test.go (2)

42-48: LGTM!

The AfterEach cleanup is well-structured and comprehensive. Using DeleteAllOf followed by controller.EnsureCleanState() ensures proper test isolation.


50-180: LGTM!

The test cases are well-structured with clear scenarios:

  • Duplicate and non-duplicate ServerRef validation
  • Update validation for in-progress BIOSVersions
  • Force update with annotations

The use of GenerateName ensures proper test isolation.

internal/controller/test_helper.go (1)

19-53: LGTM!

The EnsureCleanState function comprehensively validates that all resource lists are empty. The addition of ServerClaimList (lines 28-29) and BIOSVersionList (lines 40-41) properly extends the cleanup verification to cover the new resource types introduced in this refactor.

internal/webhook/v1alpha1/biosversion_webhook.go (5)

25-42: LGTM!

Good refactoring:

  • Logger renamed to versionLog for clarity
  • Embedding client.Client (line 41) is idiomatic and cleaner than a named field

47-59: LGTM!

The refactored ValidateCreate is cleaner with improved naming (version, versions) and correctly uses the embedded client via v.List().


62-89: LGTM!

The ValidateUpdate refactoring improves clarity with newVersion/oldVersion naming. The in-progress state check correctly references the old state and validates against force-update annotations.


92-103: LGTM!

The ValidateDelete refactoring uses consistent naming and has a clear, grammatically correct error message (line 100).


105-129: LGTM!

Excellent refactoring of the duplicate check function:

  • Nil check for version.Spec.ServerRef (lines 106-108) prevents panics
  • Skip logic for same-name resources (lines 111-112) prevents false positives
  • Field path uses proper camelCase "serverRef" and "name" (line 126), aligning with JSON field naming

@afritzler afritzler force-pushed the enh/biosvers-webhook branch from 99de57b to 8ec8269 Compare January 7, 2026 10:11
@afritzler
Copy link
Member Author

@coderabbitai review

@coderabbitai
Copy link

coderabbitai bot commented Jan 7, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

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

📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 99de57b and 8ec8269.

📒 Files selected for processing (3)
  • internal/controller/test_helper.go
  • internal/webhook/v1alpha1/biosversion_webhook.go
  • internal/webhook/v1alpha1/biosversion_webhook_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • internal/webhook/v1alpha1/biosversion_webhook.go
🔇 Additional comments (7)
internal/webhook/v1alpha1/biosversion_webhook_test.go (6)

50-66: LGTM!

The test correctly validates that duplicate spec.serverRef values are rejected during creation.


68-84: LGTM!

The test correctly verifies that a BIOSVersion with a unique spec.serverRef can be successfully created. Using k8sClient.Create here (rather than just validator.ValidateCreate) appropriately tests the end-to-end creation flow.


86-107: LGTM!

The test correctly validates that updating to a duplicate spec.serverRef is rejected.


109-130: LGTM!

The test correctly verifies that duplicate values in fields other than spec.serverRef (such as spec.image) are allowed.


132-153: LGTM!

The test correctly validates that updating to a unique spec.serverRef is allowed.


181-193: LGTM!

The test correctly validates that deletion is blocked when BIOSVersion is in InProgress state.

internal/controller/test_helper.go (1)

19-53: LGTM!

The expanded cleanup verification correctly covers all relevant CRD types including the newly added EndpointList, BMCSecretList, ServerClaimList, BIOSVersionList, ServerMaintenanceList, and ServerList. The implementation is consistent and follows the established pattern.

@afritzler afritzler force-pushed the enh/biosvers-webhook branch from 8ec8269 to 9ca3765 Compare January 7, 2026 11:37
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 (1)
internal/webhook/v1alpha1/biosversion_webhook_test.go (1)

86-107: Minor grammar issue in comments.

Lines 87 and 103 use "an BIOSVersion" which should be "a BIOSVersion" (since "BIOS" is pronounced with a consonant sound).

📝 Proposed fix
-		By("Creating an BIOSVersion with different ServerRef")
+		By("Creating a BIOSVersion with different ServerRef")
...
-		By("Updating an BIOSVersion V2 to conflicting spec.serverRef")
+		By("Updating BIOSVersion V2 to conflicting spec.serverRef")
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8ec8269 and 9ca3765.

📒 Files selected for processing (3)
  • internal/controller/test_helper.go
  • internal/webhook/v1alpha1/biosversion_webhook.go
  • internal/webhook/v1alpha1/biosversion_webhook_test.go
🧰 Additional context used
🧬 Code graph analysis (3)
internal/webhook/v1alpha1/biosversion_webhook_test.go (5)
api/v1alpha1/biosversion_types.go (6)
  • BIOSVersion (130-136)
  • BIOSVersionSpec (51-63)
  • BIOSVersionTemplate (32-48)
  • ImageSpec (65-78)
  • BIOSVersionStateInProgress (19-19)
  • BIOSVersionStateCompleted (21-21)
internal/controller/test_helper.go (1)
  • EnsureCleanState (15-57)
api/v1alpha1/servermaintenance_types.go (2)
  • ServerMaintenancePolicy (51-51)
  • ServerMaintenancePolicyEnforced (57-57)
api/v1alpha1/common_types.go (1)
  • ObjectReference (16-27)
api/v1alpha1/constants.go (2)
  • OperationAnnotation (21-21)
  • OperationAnnotationForceUpdateInProgress (44-44)
internal/controller/test_helper.go (11)
api/v1alpha1/endpoint_types.go (1)
  • EndpointList (46-50)
api/v1alpha1/bmc_types.go (1)
  • BMCList (259-263)
api/v1alpha1/bmcsecret_types.go (1)
  • BMCSecretList (62-66)
api/v1alpha1/serverclaim_types.go (1)
  • ServerClaimList (80-84)
api/v1alpha1/bmcversionset_types.go (1)
  • BMCVersionSetList (60-64)
api/v1alpha1/bmcversion_types.go (1)
  • BMCVersionList (94-98)
api/v1alpha1/biosversion_types.go (1)
  • BIOSVersionList (141-145)
api/v1alpha1/biossettingsset_types.go (1)
  • BIOSSettingsSetList (60-64)
api/v1alpha1/biossettings_types.go (1)
  • BIOSSettingsList (151-155)
api/v1alpha1/servermaintenance_types.go (1)
  • ServerMaintenanceList (99-103)
api/v1alpha1/server_types.go (1)
  • ServerList (439-443)
internal/webhook/v1alpha1/biosversion_webhook.go (2)
api/v1alpha1/biosversion_types.go (3)
  • BIOSVersion (130-136)
  • BIOSVersionList (141-145)
  • BIOSVersionStateInProgress (19-19)
internal/webhook/v1alpha1/helper.go (2)
  • ShouldAllowForceUpdateInProgress (12-18)
  • ShouldAllowForceDeleteInProgress (21-27)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Run test e2e
  • GitHub Check: Run tests
  • GitHub Check: Run test chart
🔇 Additional comments (15)
internal/webhook/v1alpha1/biosversion_webhook_test.go (8)

6-15: LGTM!

The imports are correctly organized, and the new controller package import is appropriately added to support the EnsureCleanState() call in the AfterEach block.


17-40: LGTM!

The BeforeEach setup is well-structured with:

  • Proper validator initialization with embedded client
  • Use of GenerateName for test isolation
  • Clean resource creation pattern

42-48: LGTM!

The AfterEach cleanup is properly implemented with accurate comments and comprehensive state verification via EnsureCleanState().


50-66: LGTM!

The test correctly validates that duplicate spec.serverRef values are denied during creation. The direct validator call is appropriate for unit testing.


68-84: LGTM!

The test correctly validates that non-duplicate spec.serverRef values allow creation. Using k8sClient.Create here appropriately tests the full webhook integration for the success path.


109-130: LGTM!

The test correctly validates that updating non-serverRef fields (even if they become duplicates) is allowed. The validation logic appropriately focuses only on serverRef uniqueness.


132-153: LGTM!

The test correctly validates that updating serverRef to a non-duplicate value is allowed.


155-179: LGTM!

The test correctly validates:

  1. Updates are denied when BIOSVersion is in InProgress state
  2. Updates are allowed with the ForceUpdateInProgress annotation
  3. State transitions are properly tested

The previous comment about the misleading "finalizer" reference has been addressed.

internal/controller/test_helper.go (1)

19-53: LGTM! Clean and consistent refactoring.

The variable naming improvements (e.g., bmcs, endpoints, versions) are more concise and idiomatic. All resource types are checked consistently using the same pattern, and the additions of EndpointList, ServerClaimList, and BIOSVersionList align with the webhook refactoring objectives.

internal/webhook/v1alpha1/biosversion_webhook.go (6)

25-25: LGTM! Improved logger naming.

The rename from biosversionlog to versionLog is more idiomatic and consistent with Go naming conventions.


40-42: LGTM! Embedding the client simplifies the API.

Embedding client.Client instead of using a named field allows direct method calls (e.g., v.List) without the extra .Client indirection, which is a common and cleaner pattern for validators.


47-59: LGTM! Clean refactoring with improved naming.

The variable renames (version, versions) are more concise while maintaining clarity. The logic remains correct and the embedded client is used appropriately.


62-89: LGTM! Update validation logic is sound.

The refactored code correctly checks the old version's state while using the new version for error construction. Variable naming is clear and consistent throughout.


92-103: LGTM! Delete validation is correct.

The validation properly checks the in-progress state and uses the improved error message that was addressed in the previous review.


105-130: LGTM! Improved duplicate checking with proper nil safety.

The additions significantly improve robustness:

  • Lines 106-108: Nil check for version.Spec.ServerRef prevents panics
  • Lines 111-113: Skipping self-comparison is essential for update validation
  • Line 114: Nil check for bv.Spec.ServerRef prevents panics during iteration
  • Line 126: Field path updated to lowerCamelCase ("serverRef", "name") aligns with JSON naming conventions

@afritzler afritzler force-pushed the enh/biosvers-webhook branch from 9ca3765 to ceda80d Compare January 7, 2026 11:44
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 (7)
internal/webhook/v1alpha1/biosversion_webhook_test.go (6)

50-66: Consider more concise comment wording.

The test logic is correct. The comment on line 50 could be more concise: "Should deny creation if spec.serverRef is duplicate" (instead of "a spec.serverRef field is duplicate").


68-84: Consider consistent testing approach.

Line 83 uses k8sClient.Create for integration testing, while other tests (e.g., line 65) use validator.ValidateCreate for unit testing. For consistency across the test suite, consider using the validator method directly:

-	Expect(k8sClient.Create(ctx, biosVersionV2)).To(Succeed())
+	Expect(validator.ValidateCreate(ctx, biosVersionV2)).Error().ToNot(HaveOccurred())

This maintains consistency with the unit-test approach used elsewhere in the file.


86-107: Minor comment improvements.

Two optional improvements for clarity:

  1. Line 86: Simplify to "Should deny update if spec.serverRef is duplicate"
  2. Line 103: Grammar fix - "Updating a BIOSVersion" (not "an BIOSVersion")

109-130: Clarify comment on line 126.

The comment mentions "conflicting spec.biosVersionSpec" but the code actually updates spec.image (line 128). Consider updating the comment to be more specific:

-	By("Updating an BIOSVersion V2 to conflicting spec.biosVersionSpec")
+	By("Updating BIOSVersion V2 to duplicate spec.image")

Also fixes the grammar ("an BIOSVersion" → "BIOSVersion").


132-153: Minor grammar fix.

Line 149: "Updating a BIOSVersion" (not "an BIOSVersion").


155-179: Minor style improvement.

Line 161: For consistency with other "By" statements that use gerunds (e.g., "Creating", "Updating", "Patching"), consider "Adding ServerMaintenance reference" instead of "Add ServerMaintenance reference".

internal/webhook/v1alpha1/biosversion_webhook.go (1)

105-130: LGTM: Critical improvements to duplicate detection logic.

This refactor includes two important enhancements:

  1. Lines 106-108: The nil check for version.Spec.ServerRef is excellent defensive coding that prevents potential nil pointer dereferences.

  2. Lines 111-113: The self-comparison skip (version.Name == bv.Name) is critical for ValidateUpdate to work correctly—without it, updating a BIOSVersion would always fail with a false duplicate detection since ValidateUpdate fetches all BIOSVersions and checks the updated version against the entire list.

  3. Line 126: The field path uses camelCase "serverRef" and "name", which correctly matches the JSON tags in BIOSVersionSpec.

Optional: Consider consistent capitalization in error message.

Lines 118-119 use inconsistent capitalization: "server (%s) referred in %s is duplicate of Server (%s)". For polish, consider using consistent capitalization (either all lowercase "server" or title case "Server").

✨ Optional: Consistent capitalization
-		err := fmt.Errorf("server (%s) referred in %s is duplicate of Server (%s) referred in %s",
+		err := fmt.Errorf("server (%s) referred in %s is duplicate of server (%s) referred in %s",
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9ca3765 and ceda80d.

📒 Files selected for processing (3)
  • internal/controller/test_helper.go
  • internal/webhook/v1alpha1/biosversion_webhook.go
  • internal/webhook/v1alpha1/biosversion_webhook_test.go
🧰 Additional context used
🧬 Code graph analysis (2)
internal/webhook/v1alpha1/biosversion_webhook_test.go (5)
api/v1alpha1/biosversion_types.go (6)
  • BIOSVersion (130-136)
  • BIOSVersionSpec (51-63)
  • BIOSVersionTemplate (32-48)
  • ImageSpec (65-78)
  • BIOSVersionStateInProgress (19-19)
  • BIOSVersionStateCompleted (21-21)
internal/controller/test_helper.go (1)
  • EnsureCleanState (15-57)
api/v1alpha1/servermaintenance_types.go (2)
  • ServerMaintenancePolicy (51-51)
  • ServerMaintenancePolicyEnforced (57-57)
api/v1alpha1/common_types.go (1)
  • ObjectReference (16-27)
api/v1alpha1/constants.go (2)
  • OperationAnnotation (21-21)
  • OperationAnnotationForceUpdateInProgress (44-44)
internal/webhook/v1alpha1/biosversion_webhook.go (2)
api/v1alpha1/biosversion_types.go (2)
  • BIOSVersion (130-136)
  • BIOSVersionList (141-145)
internal/webhook/v1alpha1/helper.go (2)
  • ShouldAllowForceUpdateInProgress (12-18)
  • ShouldAllowForceDeleteInProgress (21-27)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Run tests
  • GitHub Check: Run test chart
  • GitHub Check: Run test e2e
🔇 Additional comments (10)
internal/controller/test_helper.go (3)

19-29: LGTM! Enhanced test coverage with new resource types.

The addition of EndpointList and ServerClaimList checks improves the cleanup verification. The variable naming (endpoints, bmcs, bmcSecrets, claims) follows a consistent lowercase pattern.


34-41: LGTM! BIOSVersionList check added and naming consistency improved.

The new biosVersions check for BIOSVersionList aligns well with the PR's BIOSVersion webhook refactoring objective. Variable renamings (bmcVersionSets, bmcVersions, biosVersions) enhance consistency across the function.


46-47: Naming pattern acknowledged.

The List suffix on biosSettingsList (and bmcSettingsList at line 31) follows the rationale discussed in previous reviews: since "Settings" is already plural, the suffix distinguishes the list from individual items. This pattern is consistent and reasonable.

internal/webhook/v1alpha1/biosversion_webhook_test.go (2)

42-48: LGTM - Clean AfterEach implementation.

The cleanup logic properly deletes all BIOSVersion resources and ensures clean state. The comment accurately reflects the operations being performed.


181-193: LGTM - InProgress deletion test is correct.

The test properly validates that deletion fails when the BIOSVersion is in InProgress state, and correctly resets to Completed state to allow AfterEach cleanup to succeed.

internal/webhook/v1alpha1/biosversion_webhook.go (5)

25-25: LGTM: Improved logger naming.

The rename to versionLog is more concise and follows common Go conventions.


40-42: LGTM: Excellent use of embedded client.

The embedded client.Client field is a cleaner pattern that allows direct method calls (v.List) instead of v.Client.List, improving code readability throughout the validator.


47-59: LGTM: Clean variable naming and consistent refactoring.

The changes improve readability with more concise variable names (version, versions) and work correctly with the embedded client pattern.


62-89: LGTM: Clearer variable naming for update validation.

The newVersion and oldVersion naming is more explicit and improves code clarity. The validation logic correctly handles in-progress state checks and duplicate detection.


91-103: LGTM: Consistent refactoring with previous fix applied.

The variable renaming is consistent with the rest of the file, and the grammar fix from the previous review has been correctly applied.

@afritzler afritzler force-pushed the enh/biosvers-webhook branch from ceda80d to 2b7ed78 Compare January 7, 2026 11:58
@afritzler
Copy link
Member Author

@coderabbitai review

@coderabbitai
Copy link

coderabbitai bot commented Jan 7, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@Nuckal777 Nuckal777 merged commit 30361f9 into main Jan 7, 2026
16 checks passed
@Nuckal777 Nuckal777 deleted the enh/biosvers-webhook branch January 7, 2026 17:07
@github-project-automation github-project-automation bot moved this to Done in Roadmap Jan 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request size/XL

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants