-
Notifications
You must be signed in to change notification settings - Fork 7
feat: Implement BMCSettingsSet controller with reconciliation logic #471
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
27d9690 to
fa7c2fa
Compare
| //avoid unnecessary updates | ||
| if r.refsAreEqual(bmcSettingsCopy.Spec.ServerMaintenanceRefs, mergedRefs) && | ||
| r.templatesAreEqual(&bmcSettingsCopy.Spec.BMCSettingsTemplate, bmcSettingsTemplate) { | ||
| log.V(2).Info("No changes needed for BMCSettings", "BMCSettings", bmcSettingsCopy.Name) | ||
| return nil | ||
| } |
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.
isnt this duplicate?
the method CreateOrPatch already checks before updating/patching the resources.
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.
correct removed the duplicate check and the unnecessary functions for check this in the new pr
- Added BMCSettingsSetReconciler to manage BMCSettingsSet resources. - Implemented reconciliation logic for creating, updating, and deleting BMCSettings based on BMC resources. - Introduced finalizer handling for BMCSettingsSet to manage cleanup during deletion. - Added methods to handle owned BMCSettings and update their status based on the reconciliation state. - Implemented logic to create missing BMCSettings and delete orphaned ones. - Added tests for BMCSettingsSet controller to ensure correct reconciliation behavior. test: Add unit tests for BMCSettingsSet controller - Created comprehensive tests for BMCSettingsSet controller to validate reconciliation logic. - Ensured correct behavior when BMC resources are created, updated, or deleted. - Verified that BMCSettings are generated correctly based on BMC labels. - Added tests for updating BMCSettingsSet and ensuring status updates are reflected. chore: Update test suite to include BMCSettingsSet reconciler - Modified suite_test.go to register BMCSettingsSetReconciler with the test manager. - Ensured all resources are cleaned up after tests, including BMCSettingsSet. fix: Update BMCSettings webhook to include BMCSettingsTemplate - Refactored BMCSettingsSpec to include BMCSettingsTemplate for better structure. - Updated webhook tests to validate the new structure of BMCSettings resources.
…cumentation and tests. To ensure make and lint works
…ing; adjust RBAC roles and CRD version
…enanceRefs filtering logic with clientutils.ListAndFilter
b98ae3d to
22f5cc3
Compare
… in CRD Add an update in BMCSettingSet test to check the patch Mechanism
…prove server state handling. For this use the new server claim handling Update biossettings_controller_test: add const for bar variable that go lint works correctly
| Eventually(Update(serverClaim02, func() { | ||
| metautils.SetAnnotation(serverClaim02, metalv1alpha1.ServerMaintenanceApprovalKey, "true") | ||
| })).Should(Succeed()) | ||
|
|
||
| Eventually(Object(bmcSettings02)).Should(SatisfyAny( | ||
| HaveField("Status.State", metalv1alpha1.BMCSettingsStateInProgress), | ||
| HaveField("Status.State", metalv1alpha1.BMCSettingsStateApplied), | ||
| )) | ||
|
|
||
| Eventually(Object(bmcSettings02)).Should(SatisfyAll( | ||
| HaveField("Status.State", metalv1alpha1.BMCSettingsStateApplied), | ||
| )) |
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.
duplicate code?
| RunSpecs(t, "Controller Suite") | ||
| } | ||
|
|
||
| func DeleteAllMetalResources(ctx context.Context, namespace string) { |
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.
this was removed recently, can we switch to have the newer method and remove this code?
Nuckal777
left a 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.
Thanks. 👍 PR needs a rebase and the test need to be adjusted due to the removal of DeleteAllMetalResources(). Also, I would consider removing support for ServerMaintenanceRefs on the BMCSettingsSet. It complicates the code a lot and for practical uses I would imagine most people would just like to apply the set and have ServerMaintenances be automatically managed, instead of micro-managing them.
| foo: bar | ||
| foo2: bar2 |
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.
Indentation is off. Newline at the end of the file would also be appreciated.
| // added const field for go linting | ||
| const ( | ||
| testBarValue = "bar" | ||
| ) | ||
|
|
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.
Probably, we should not run the goconst (?) linter on the test files, instead of introducing an inconsistently used constant.
| if bmcSettings.Status.State != metalv1alpha1.BMCSettingsStateInProgress { | ||
| delTableBMCSettings[bmcSettings.Name] = struct{}{} | ||
| } else if len(bmcSettings.Spec.ServerMaintenanceRefs) == 0 { | ||
| // If no ServerMaintenanceRefs is set, the BMCSettings is not actively being processed | ||
| delTableBMCSettings[bmcSettings.Name] = struct{}{} | ||
| } |
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.
Please unify both checks in a single if block.
| var serverMaintenanceRefsMerged []metalv1alpha1.ServerMaintenanceRefItem | ||
| if len(serverMaintenancesRefsCreated) > 0 && len(serverMaintenanceRefsProvided) > 0 { |
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.
Shouldn't both list contain non-overlapping sets of maintenances (serverMaintenanceRefsCreated = refsOnBMCSettingsObject - refsProvidedOnBMCSettingsSet)? If yes, the special handling for merging these can be removed.
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.
@Nuckal777 I do not think that is always the case, user might end up providing a new maintenanceRef after child object has created one... ?
|
|
||
| serverMaintenanceRefs := []metalv1alpha1.ServerMaintenanceRefItem{} | ||
| for _, serverMaintenance := range serverMaintenanceList.Items { | ||
| if ref, exists := serverMaintenanceRefMap[serverMaintenance.Name]; exists { |
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.
Is a negation missing here by chance?
Added BMCSettingsSetReconciler to manage BMCSettingsSet resources.
fixes: #419