-
Notifications
You must be signed in to change notification settings - Fork 86
api: generate field ownership functions #263
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
chrishenzie
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.
Nice change, this cuts down on a lot of boilerplate. Left some small comments. It looks like this isn't passing DCO checks yet and needs a signature
Introduce a `protoc` generator (`tools/protoc-gen-owners`) to automatically generate the repetitive field ownership tracking functions. This refactors the `pkg/api/owners.go` file. The new generator uses the `Field` enum in `api.proto` as the source of truth. The original `owners.go` file has been split logically into generated and handwritten parts: - `owners_generated.go`: Contains the auto-generated boilerplate for most fields. - `owners.go`: Retains the core handwritten logic, including constructors, conflict resolution, and special-cased handlers for fields with custom logic (`OciHooks`, `Rdt`). This change reduces manual boilerplate, improves maintainability, and ensures consistency between the protobuf definitions and the Go API. Assisted-by: gemini-cli Signed-off-by: Samuel Karp <samuelkarp@google.com>
Signed-off-by: Samuel Karp <samuelkarp@google.com>
f4818e9 to
13d8f93
Compare
Fix hook ownership tracking and add a proper test case for it. Ownership tracking for OCI hooks is supposed to be accumulative. The implementation tried to accumulate owners, but it was buggy. It tried to delete existing ownership by unclaiming which marks ownershipdeleted by the plugin instead of clearing it. This went unnoticed since we lacked any kind of proper test for hook ownership accumulation. It was only noticed thanks to containerd#263 which switches much of the ownership tracking code to generated from hand-written. Signed-off-by: Krisztian Litkey <krisztian.litkey@intel.com>
|
@samuelkarp Thank you ! This looks pretty good. I have two comments, one related to documentation, the other to OCI hooks ownership tracking.
I filed #264 to fix the currently broken OCI Hook ownership tracking in main/HEAD and add a unit test for it. I rebased this branch on top of it to check with what minimum changes I could get cumulative hook ownership tracking generated to pass the new test. Here is the resulting branch with 2 small changes: https://github.com/klihub/nri/commits/devel/samuelkarp/protoc-gen-owners. |
Fix hook ownership tracking and add a proper test case for it. Ownership tracking for OCI hooks is supposed to be accumulative. The implementation tried to accumulate owners, but it was buggy. It tried to delete existing ownership by unclaiming which marks ownershipdeleted by the plugin instead of clearing it. This went unnoticed since we lacked any kind of proper test for hook ownership accumulation. It was only noticed thanks to containerd#263 which switches much of the ownership tracking code to generated from hand-written. Signed-off-by: Krisztian Litkey <krisztian.litkey@intel.com>
I think in the general case it should be automatic. Right now the simple/compound distinction is manual; I want to take another look at seeing if that can be detected and then the
I missed that Hook ownership was special. Let's get #264 in, then I'll revert the top commit on this and rebase. The Hook functions can continue to be handwritten because they're unique. |
Introduce a
protocgenerator (tools/protoc-gen-owners) to automatically generate the repetitive field ownership tracking functions. This refactors thepkg/api/owners.gofile.The new generator uses the
Fieldenum inapi.protoas the source of truth. The originalowners.gofile has been split logically into generated and handwritten parts:owners_generated.go: Contains the auto-generated boilerplate for most fields.owners.go: Retains the core handwritten logic, including constructors, conflict resolution, and special-cased handlers for fields with custom logic (OciHooks,Rdt).This change reduces manual boilerplate, improves maintainability, and ensures consistency between the protobuf definitions and the Go API.
Assisted-by: gemini-cli