Fix event driven reconciliation example#22
Merged
alexlovelltroy merged 8 commits intoOpenCHAMI:mainfrom Nov 10, 2025
Merged
Conversation
Signed-off-by: Ben McDonald <ben.mcdonald@hpe.com>
Signed-off-by: Ben McDonald <ben.mcdonald@hpe.com>
Signed-off-by: Ben McDonald <ben.mcdonald@hpe.com>
Signed-off-by: Ben McDonald <ben.mcdonald@hpe.com>
Signed-off-by: Ben McDonald <ben.mcdonald@hpe.com>
Signed-off-by: Ben McDonald <ben.mcdonald@hpe.com>
Signed-off-by: Ben McDonald <ben.mcdonald@hpe.com>
Signed-off-by: Ben McDonald <ben.mcdonald@hpe.com>
35ec6bb to
5f58e28
Compare
alexlovelltroy
approved these changes
Nov 10, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR fixes a series of bugs in the code generator that prevented event-driven reconciliation from working out-of-the-box.
Previously,
POST-ing a new resource (like aRack) would succeed but would not trigger its associated reconciler. This was due to a couple of issues, including a disconnected event bus, improper resource initialization in handlers, and a data contract mismatch in the reconciler.These changes modify the code generation templates to fix the identified issues, resulting in a fully functional reconciliation loop on a newly generated project.
List of Fixes
main.go.tmpl:events.SetGlobalEventBus) and thereconcile.Controller.events.SetEventConfigto ensure the event system is globally enabled before any handlers or controllers are initialized.handlers.go.tmpl:Createfunction for all resources now correctly initializes metadata by settingCreatedAt/UpdatedAttimestamps.Status.Phase = "Pending"on creation. This is the change that gives the reconciler an initial state to act upon.reconciler_generated.go.tmpl:Reconcilefunction now correctly unmarshals thejson.RawMessageit receives from the event bus into a typed struct (e.g.,*rack.Rack). This fixes ainterface conversionpanic..reconciledevent at the end of the function is commented out to prevent the infinite reconciliation loop I observed.examples/04-rack-reconciliation/pkg/reconcilers/rack_reconciler.go:&rackResource(a**rack.Rack) was being passed to the client instead ofrackResource(a*rack.Rack).Testing
1. Server Logs
Before (Buggy):
The
POSTrequest is logged, but no reconciliation is triggered. The server is silent.After (Fixed):
The
POSTrequest immediately triggers the reconciliation controller, which provisions all child resources.2.
curlResponse forPOST /racksBefore (Buggy):
The
POSTresponse shows an emptyphasein the status, failing to indicate that it's pending reconciliation.$ curl -X POST http://localhost:8080/racks ... { "apiVersion": "v1", "kind": "Rack", ... "status": { - "phase": "", "totalChassis": 0, ... } }After (Fixed):
The
POSTresponse now correctly shows"phase": "Pending", as set by the fixed handler template.$ curl -X POST http://localhost:8080/racks ... { "apiVersion": "v1", "kind": "Rack", ... "status": { + "phase": "Pending", "totalChassis": 0, ... } }And finally: