Skip to content

refactor: deduplicate shared code across ocsf builders and driver crates#1526

Open
ericcurtin wants to merge 1 commit into
NVIDIA:mainfrom
ericcurtin:refactor/deduplicate-shared-code/ec
Open

refactor: deduplicate shared code across ocsf builders and driver crates#1526
ericcurtin wants to merge 1 commit into
NVIDIA:mainfrom
ericcurtin:refactor/deduplicate-shared-code/ec

Conversation

@ericcurtin
Copy link
Copy Markdown
Contributor

Summary

Eliminate several categories of repeated code identified across the OCSF builder layer and compute driver crates. No behavioral changes — pure structural deduplication.

Related Issue

N/A

Changes

openshell-ocsf — OCSF builder deduplication (~90 lines removed)

  • Add impl_builder_setters! macro in builders/mod.rs that generates the identical severity(), status(), and message() setter methods present on all 7 OCSF event builders (two variants: with and without status)
  • Add SandboxContext::apply_common_fields() to consolidate the four-line finalization pattern (set_status, set_message, set_device, set_container) repeated in every builder's build() method
  • Update all 7 builder files to use the macro and helper

openshell-core — two new shared driver utilities

  • driver_utils::sandbox_token_path(driver_subdir, namespace, sandbox_id) — centralizes the XDG state path construction for sandbox JWT token files previously duplicated between the Docker and Podman drivers
  • driver_utils::build_capabilities_response(name, version, image, gpu) — centralizes the GetCapabilitiesResponse struct literal repeated across the Docker, Podman, and Kubernetes compute drivers

openshell-driver-docker, openshell-driver-podman, openshell-driver-kubernetes

  • Token path functions and capabilities() methods now delegate to the shared helpers above

Skipped (differences were too significant to abstract cleanly): gRPC ComputeDriverService adapters (different error types and method signatures between k8s and podman), persistence store backends, test PKI helpers, provider boilerplate files.

Testing

  • mise run pre-commit passes
  • Unit tests added/updated
  • E2E tests added/updated (if applicable)

Checklist

  • Follows Conventional Commits
  • Commits are signed off (DCO)

Extract repeated patterns into shared helpers:

- Add impl_builder_setters! macro to openshell-ocsf/builders that
  generates the identical severity(), status(), and message() setter
  methods present on all 7 OCSF event builders
- Add SandboxContext::apply_common_fields() to consolidate the
  four-line build() finalization (set_status, set_message, set_device,
  set_container) repeated in every builder
- Add driver_utils::sandbox_token_path() to centralize the XDG state
  path construction for sandbox JWT files used by both the Docker and
  Podman drivers
- Add driver_utils::build_capabilities_response() to eliminate the
  identical GetCapabilitiesResponse struct literal repeated across the
  Docker, Podman, and Kubernetes compute drivers
@copy-pr-bot
Copy link
Copy Markdown

copy-pr-bot Bot commented May 22, 2026

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@pimlock
Copy link
Copy Markdown
Collaborator

pimlock commented May 22, 2026

/ok to test 9aae562

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