Skip to content

Conversation

@samuelkarp
Copy link
Member

@samuelkarp samuelkarp commented Jan 15, 2026

⚠️ AI-assisted code ⚠️


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

Copy link
Contributor

@chrishenzie chrishenzie left a 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>
@samuelkarp samuelkarp marked this pull request as ready for review January 15, 2026 21:09
klihub added a commit to klihub/nri that referenced this pull request Jan 16, 2026
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>
@klihub
Copy link
Member

klihub commented Jan 16, 2026

@samuelkarp Thank you ! This looks pretty good. I have two comments, one related to documentation, the other to OCI hooks ownership tracking.

  1. Should we document somewhere, probably either in owers.go or in owners_generated.go what one needs to do to implement ownership tracking and conflict resolution for newly added fields ?

  2. AFAICT, this implementation alters how OCI Hook ownership is tracked vs. how it is intended to be tracked... sans the broken implementation in current HEAD (which went completely unnoticed as we lack any proper test case for it). OCI hook ownership is supposed to be accumulated not conflicting. IOW, if plugins p0, p1, and p2 adjust hooks, we should end up with all of them recorded as owners (ugly-ishly as a comma-separated string) instead of adjustment by p1 conflicting with p0 and failing. So I think we'll need to introduce another exception/override here in the generator for fields where ownership tracking is semantically cumulative, so we can generate it correctly.

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.

klihub added a commit to klihub/nri that referenced this pull request Jan 16, 2026
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
Copy link
Member Author

Should we document somewhere, probably either in owers.go or in owners_generated.go what one needs to do to implement ownership tracking and conflict resolution for newly added fields ?

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 compoundKeys can just be a naming override for the parameter if it makes sense. But I'm happy to add a comment pointing this out for now.

AFAICT, this implementation alters how OCI Hook ownership is tracked vs. how it is intended to be tracked...

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants