-
Notifications
You must be signed in to change notification settings - Fork 9
Refactor BIOSVersion webhook
#575
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
120e510 to
7d1a12b
Compare
- Refactor `BIOSVersion` webhook - Updated tests
7c52de4 to
f5b59a6
Compare
f5b59a6 to
29649ae
Compare
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
WalkthroughConsolidates per-test DeferCleanup deletions into AfterEach cleanup hooks calling controller.EnsureCleanState(), and refactors BIOSVersionCustomValidator to embed client.Client (updating calls and validation helpers); tests updated to use GenerateName-based metadata and rely on centralized cleanup. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: defaults Review profile: CHILL Plan: Pro 📒 Files selected for processing (3)
🧰 Additional context used🧬 Code graph analysis (1)internal/webhook/v1alpha1/biosversion_webhook.go (2)
⏰ 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)
🔇 Additional comments (9)
Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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) toDeleteAllOf, 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 ifserverwere 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
📒 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
biosversionlogtoversionLogfollows Go naming conventions and improves readability.
40-42: LGTM: Idiomatic use of embedded client.Embedding
client.Clientpromotes its methods and enables cleaner method calls (v.List()vsv.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 promotedv.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
newVersionin 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
BMCSettingsresources and verifies cleanup viacontroller.EnsureCleanState(), which includesBMCSettingsListverification.internal/webhook/v1alpha1/bmcversion_webhook_test.go (1)
47-53: LGTM!The AfterEach cleanup properly handles
BMCVersionresource 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, andEnsureCleanState()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
Completedbefore cleanup, ensuringAfterEachcan succeed.
|
@coderabbitai generate docstrings |
✅ Actions performedInitiated docstring generation; will generate only if new commits exist. |
|
Note Docstrings generation - SUCCESS |
Docstrings generation was requested by @afritzler. * #575 (comment) The following files were modified: * `internal/controller/test_helper.go` * `internal/webhook/v1alpha1/biosversion_webhook.go`
Proposed Changes
BIOSVersionwebhookSummary by CodeRabbit
Refactor
Tests
✏️ Tip: You can customize this high-level summary in your review settings.