Skip to content

Refactor shared plugin types for DRA reuse#1276

Open
TomerNewman wants to merge 1 commit into
kubernetes-sigs:mainfrom
TomerNewman:MGMT-24467-refactor-shared-plugin-types
Open

Refactor shared plugin types for DRA reuse#1276
TomerNewman wants to merge 1 commit into
kubernetes-sigs:mainfrom
TomerNewman:MGMT-24467-refactor-shared-plugin-types

Conversation

@TomerNewman
Copy link
Copy Markdown
Collaborator

@TomerNewman TomerNewman commented May 27, 2026

Refactor shared plugin types for DRA reuse

Summary

Extracts shared container and pod configuration types (PluginContainerSpec, PluginSpec) from the existing DevicePluginContainerSpec and DevicePluginSpec structs. The original types are preserved as a backward-compatible type alias and inline embed, keeping JSON serialization and CRD schema identical.

This refactoring enables the upcoming DRA support to reuse the same base types without duplicating field definitions.

Changes

  • api/v1beta1/module_types.go:
    • Renamed DevicePluginContainerSpec to PluginContainerSpec (7 fields, all struct tags preserved)
    • Added type DevicePluginContainerSpec = PluginContainerSpec (backward-compatible alias)
    • Extracted pod-level fields into new PluginSpec struct (5 fields)
    • Changed DevicePluginSpec to embed PluginSpec with json:",inline"
  • api/v1beta1/zz_generated.deepcopy.go: Regenerated — deepcopy methods now generated for PluginContainerSpec and PluginSpec
  • internal/controllers/device_plugin_reconciler_test.go: Updated 3 struct literals to use PluginSpec: embedded field in composite literals

Testing

  • Unit tests: All existing tests pass without behavioral change (89.4% coverage in internal/controllers)
  • CRD diff: Zero — kmm.sigs.x-k8s.io_modules.yaml is identical before and after
  • Validation: make generate, make manifests, make fmt, make vet, make lint, make unit-test all pass

Acceptance Criteria

  • PluginContainerSpec is defined with fields: Command, Args, Env, Image, ImagePullPolicy, Resources, VolumeMounts
  • DevicePluginContainerSpec is a type alias for PluginContainerSpec (backward compatible)
  • PluginSpec is defined with fields: Container, InitContainer, ServiceAccountName, Volumes, AutomountServiceAccountToken
  • DevicePluginSpec embeds PluginSpec inline so existing YAML field names are unchanged
  • All existing references to DevicePluginContainerSpec and DevicePluginSpec compile without modification
  • Existing Device Plugin unit tests pass without behavioral change

@k8s-ci-robot
Copy link
Copy Markdown
Contributor

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label May 27, 2026
@netlify
Copy link
Copy Markdown

netlify Bot commented May 27, 2026

Deploy Preview for kubernetes-sigs-kmm ready!

Name Link
🔨 Latest commit e195f33
🔍 Latest deploy log https://app.netlify.com/projects/kubernetes-sigs-kmm/deploys/6a1d60082dc1800008955f11
😎 Deploy Preview https://deploy-preview-1276--kubernetes-sigs-kmm.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@k8s-ci-robot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: TomerNewman

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels May 27, 2026
@TomerNewman TomerNewman marked this pull request as ready for review May 27, 2026 11:48
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label May 27, 2026
Comment thread api/v1beta1/module_types.go Outdated
type DevicePluginSpec struct {
Container DevicePluginContainerSpec `json:"container"`
// DevicePluginContainerSpec is a backward-compatible alias for PluginContainerSpec.
type DevicePluginContainerSpec = PluginContainerSpec
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need this?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type alias keeps all existing code that references DevicePluginContainerSpec compiling without changes — controllers, tests, and the webhook all use this name. In the next PR (Story 2), the new DRASpec will reference PluginContainerSpec directly, so the shared type gets a generic name while the alias preserves backward compatibility.

Comment thread api/v1beta1/module_types.go Outdated
// DevicePluginContainerSpec is a backward-compatible alias for PluginContainerSpec.
type DevicePluginContainerSpec = PluginContainerSpec

type PluginSpec struct {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need PluginSpec and DevicePLuginSpec? We can keep DevicePluginSpec, which will contain the Container and InitContainer and PluginContainerSpec field

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PluginSpec is the shared base that both DevicePluginSpec and the upcoming DRASpec (Story 2) will use. DRA drivers need the same pod-level fields — container, init container, service account, volumes. Extracting them into PluginSpec now avoids duplicating those fields across both specs. DevicePluginSpec wraps it with json:",inline" so the existing CRD schema is unchanged (verified via zero CRD diff).

@TomerNewman TomerNewman force-pushed the MGMT-24467-refactor-shared-plugin-types branch from 2bf0ac0 to 38121f7 Compare May 27, 2026 12:35
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented May 27, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 72.97%. Comparing base (fa23a9b) to head (e195f33).
⚠️ Report is 374 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1276      +/-   ##
==========================================
- Coverage   79.09%   72.97%   -6.13%     
==========================================
  Files          51       66      +15     
  Lines        5109     4703     -406     
==========================================
- Hits         4041     3432     -609     
- Misses        882     1108     +226     
+ Partials      186      163      -23     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ybettan
Copy link
Copy Markdown
Contributor

ybettan commented May 28, 2026

Can we remove [MGMT-24467] from the commit message? (It is not relevant to this project).

@TomerNewman TomerNewman force-pushed the MGMT-24467-refactor-shared-plugin-types branch from 38121f7 to 7134479 Compare May 28, 2026 07:07
@ybettan
Copy link
Copy Markdown
Contributor

ybettan commented Jun 1, 2026

Something isn't clear to me.

  1. This PR is just renaming struct without any other change
  2. How this PR is related to Add DRA support to the Module CRD #1269?
  3. If this PR is just a "preparation" to 1269 I think it would be clearer to have a single PR since this PR has no purpose on its own and the commit message is confusing since nothing is really extracted.

DevicePlugin: &kmmv1beta1.DevicePluginSpec{
Container: kmmv1beta1.DevicePluginContainerSpec{Image: devicePluginImage},
Volumes: []v1.Volume{vol},
CommonSpec: kmmv1beta1.CommonSpec{
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets add a unit test that verifies the backword compatibility also

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added "DevicePluginSpec backward compatibility" unit test

@TomerNewman TomerNewman force-pushed the MGMT-24467-refactor-shared-plugin-types branch 3 times, most recently from cd6c2d4 to 881acc1 Compare June 1, 2026 08:44
Extract shared container and pod configuration types (CommonContainerSpec,
CommonSpec) from DevicePluginContainerSpec and DevicePluginSpec. The
original types are preserved as a type alias and inline embed respectively,
keeping JSON serialization and CRD schema identical.

This refactoring enables the upcoming DRA support to reuse the same base
types without duplicating field definitions.
@TomerNewman TomerNewman force-pushed the MGMT-24467-refactor-shared-plugin-types branch from 881acc1 to e195f33 Compare June 1, 2026 10:33
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jun 1, 2026
@yevgeny-shnaidman
Copy link
Copy Markdown
Contributor

/lgtm
/hold
/assign @ybettan
@ybettan please unhold once you are satisfied

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jun 1, 2026
@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants