-
Notifications
You must be signed in to change notification settings - Fork 35
Add Go SDK for GPUs #607
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
Open
pteranodan
wants to merge
5
commits into
NVIDIA:main
Choose a base branch
from
pteranodan:add-go-sdk
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add Go SDK for GPUs #607
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
1538ceb
introduce k8s-idiomatic Go SDK for Device API
pteranodan cfd3179
Merge branch 'main' into add-go-sdk
pteranodan 23d3870
use code gen exclusively
pteranodan 0b764aa
Merge branch 'main' into add-go-sdk
pteranodan 35a103a
coderabbit fixes
pteranodan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| # ============================================================================== | ||
| # GIT ATTRIBUTES | ||
| # ============================================================================== | ||
| # Use 'linguist-generated=true' to hide generated code from GitHub PR diffs. | ||
| # ============================================================================== | ||
|
|
||
| # Hide Kubernetes generated helpers (DeepCopy, Defaults, Conversions, OpenAPI, etc) | ||
| zz_generated.*.go linguist-generated=true | ||
|
|
||
| # Hide generated Protobuf Go bindings | ||
| *.pb.go linguist-generated=true | ||
|
|
||
| # Hide generated client library | ||
| client-go/client/** linguist-generated=true | ||
| client-go/listers/** linguist-generated=true | ||
| client-go/informers/** linguist-generated=true | ||
|
|
||
| # Hide copied, unmodified upstream code | ||
| code-generator/cmd/client-gen/types/** linguist-generated=true | ||
| code-generator/cmd/client-gen/generators/scheme/** linguist-generated=true | ||
| code-generator/cmd/client-gen/generators/util/** linguist-generated=true |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,7 @@ | |
| *.so | ||
| *.dylib | ||
| api/bin/* | ||
| client-go/bin/* | ||
|
|
||
| # Test binary, built with `go test -c` | ||
| *.test | ||
|
|
||
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| # API Development | ||
|
|
||
| ## Workflow | ||
|
|
||
| Follow these steps to add new resources or update existing fields: | ||
| 1. **Go Definitions**: Update `device/${VERSION}/${TYPE}_types.go`. Ensure you include the necessary marker comments (e.g., `// +k8s:deepcopy-gen`) required by the generators. | ||
| 2. **Proto Definitions**: Update `proto/device/${VERSION}/${TYPE}.proto`. Ensure Protobuf field numbers are never reused or changed once released. | ||
| 3. **Registration**: If adding a new **Kind**, register it in `device/${VERSION}/register.go` within the `addKnownTypes` function. | ||
| 4. **Conversion Logic**: Update the mapping interface in `device/${VERSION}/converter.go`. See [Goverter](https://github.com/jmattheis/goverter) documentation for additional details. | ||
| 5. **Generate**: Run `make code-gen`. This orchestrates `protoc`, `deepcopy-gen`, and `goverter` to refresh all artifacts. | ||
|
|
||
| ## Conventions | ||
|
|
||
| - **Kubernetes Resource Model (KRM)**: | ||
| - Go type definitions must strictly follow the standard [Kubernetes Resource Model](https://github.com/kubernetes/design-proposals-archive/blob/main/architecture/resource-management.md). | ||
| - **Separation of Concerns**: Use `Spec` for desired configuration and `Status` for observed state. | ||
|
|
||
| ## Housekeeping | ||
|
|
||
| If your generated files are out of sync or contain stale data: | ||
|
|
||
| ```bash | ||
| # Removes generated code (bindings, deepcopy, goverter) | ||
| make clean | ||
| ``` |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| # API Definitions | ||
|
|
||
| This module contains the canonical API definitions for the **NVIDIA Device API**. It serves as the single source of truth for resource schemas, gRPC wire formats, and Kubernetes-native Go types. | ||
|
|
||
| ## Structure | ||
|
|
||
| * **`device/`**: Contains the **Kubernetes Resource Model (KRM)** definitions. These types implement the `runtime.Object` interface. | ||
| * **`proto/`**: Contains the **Language-Agnostic Definitions**. Protobuf messages and gRPC service definitions that define the node-local communication contract. | ||
| * **`gen/go/`**: Contains the **Bindings**. The output of the `protoc` compiler (`.pb.go` and `_grpc.pb.go`). | ||
|
|
||
| ## Code Generation | ||
|
|
||
| This module relies on three distinct generation phases to maintain type safety: | ||
| 1. **Protobuf**: Compiles `.proto` files into Go structs. | ||
| 2. **DeepCopy**: Generates `zz_generated.deepcopy.go` to support Kubernetes object manipulation. | ||
| 3. **Conversion**: Generates `zz_generated.goverter.go` to map between Protobuf messages and KRM Go types (using Goverter). | ||
|
|
||
| To run the full pipeline: | ||
|
|
||
| ```bash | ||
| make code-gen | ||
| ``` | ||
|
|
||
| ## Development | ||
|
|
||
| Refer to [DEVELOPMENT.md](DEVELOPMENT.md) for instructions on adding new fields or resources to the API. |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,136 @@ | ||
| // Copyright (c) 2025, NVIDIA CORPORATION. All rights reserved. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package v1alpha1 | ||
|
|
||
| import ( | ||
| pb "github.com/nvidia/nvsentinel/api/gen/go/device/v1alpha1" | ||
| "google.golang.org/protobuf/types/known/timestamppb" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| ) | ||
|
|
||
| // Converter is the interface used to generate type conversion methods between the | ||
| // Kubernetes Resource Model structs and the Protobuf message structs. | ||
| // | ||
| // goverter:converter | ||
| // goverter:output:file ./zz_generated.goverter.go | ||
| // goverter:extend FromProtobufTypeMeta FromProtobufListTypeMeta FromProtobufTimestamp ToProtobufTimestamp | ||
| // goverter:useZeroValueOnPointerInconsistency | ||
| type Converter interface { | ||
| // FromProtobuf converts a protobuf Gpu message into a GPU object. | ||
| // | ||
| // goverter:map . TypeMeta | FromProtobufTypeMeta | ||
| // goverter:map Metadata ObjectMeta | ||
| FromProtobuf(source *pb.Gpu) GPU | ||
|
|
||
| // ToProtobuf converts a GPU object into a protobuf Gpu message. | ||
| // | ||
| // goverter:map ObjectMeta Metadata | ||
| // goverter:ignore state sizeCache unknownFields | ||
| ToProtobuf(source GPU) *pb.Gpu | ||
|
|
||
| // FromProtobufList converts a protobuf GpuList message into a GPUList object. | ||
| // | ||
| // goverter:map . TypeMeta | FromProtobufListTypeMeta | ||
| // goverter:map Metadata ListMeta | ||
| FromProtobufList(source *pb.GpuList) *GPUList | ||
|
|
||
| // ToProtobufList converts a GPUList object into a protobuf GpuList message. | ||
| // | ||
| // goverter:map ListMeta Metadata | ||
| // goverter:ignore state sizeCache unknownFields | ||
| ToProtobufList(source *GPUList) *pb.GpuList | ||
|
|
||
| // FromProtobufObjectMeta converts a protobuf ObjectMeta into a metav1.ObjectMeta object. | ||
| // | ||
| // goverter:ignoreMissing | ||
| FromProtobufObjectMeta(source *pb.ObjectMeta) metav1.ObjectMeta | ||
|
|
||
| // ToProtobufObjectMeta converts a metav1.ObjectMeta into a protobuf Object message. | ||
| // | ||
| // goverter:ignore state sizeCache unknownFields | ||
| ToProtobufObjectMeta(source metav1.ObjectMeta) *pb.ObjectMeta | ||
|
|
||
pteranodan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // FromProtobufListMeta converts a protobuf ListMeta into a metav1.ListMeta object. | ||
| // | ||
| // goverter:ignore SelfLink Continue RemainingItemCount | ||
| FromProtobufListMeta(source *pb.ListMeta) metav1.ListMeta | ||
|
|
||
| // ToProtobufListMeta converts a metav1.ListMeta into a protobuf ListMeta message. | ||
| // | ||
| // goverter:ignore state sizeCache unknownFields | ||
| ToProtobufListMeta(source metav1.ListMeta) *pb.ListMeta | ||
|
|
||
| // FromProtobufSpec converts a protobuf GpuSpec message into a GPUSpec object. | ||
| // | ||
| // goverter:map Uuid UUID | ||
| FromProtobufSpec(source *pb.GpuSpec) GPUSpec | ||
|
|
||
| // ToProtobufSpec converts a GPUSpec object into a protobuf GpuSpec message. | ||
| // | ||
| // goverter:map UUID Uuid | ||
| // goverter:ignore state sizeCache unknownFields | ||
| ToProtobufSpec(source GPUSpec) *pb.GpuSpec | ||
|
|
||
| // FromProtobufStatus converts a protobuf GpuStatus message into a GPUStatus object. | ||
| FromProtobufStatus(source *pb.GpuStatus) GPUStatus | ||
|
|
||
| // ToProtobufStatus converts a GPUStatus object into a protobuf GpuStatus message. | ||
| // | ||
| // goverter:ignore state sizeCache unknownFields | ||
| ToProtobufStatus(source GPUStatus) *pb.GpuStatus | ||
|
|
||
| // FromProtobufCondition converts a protobuf Condition message into a metav1.Condition object. | ||
| // | ||
| // goverter:ignore ObservedGeneration | ||
| // Note: ObservedGeneration is specific to k8s and not found in the protobuf Condition message. | ||
| FromProtobufCondition(source *pb.Condition) metav1.Condition | ||
|
|
||
| // ToProtobufCondition converts a metav1.Condition object into a protobuf Condition message. | ||
| // | ||
| // goverter:ignore state sizeCache unknownFields | ||
| ToProtobufCondition(source metav1.Condition) *pb.Condition | ||
| } | ||
|
|
||
| // FromProtobufTypeMeta generates the standard TypeMeta for the root GPU resource. | ||
| func FromProtobufTypeMeta(_ *pb.Gpu) metav1.TypeMeta { | ||
| return metav1.TypeMeta{ | ||
| Kind: "GPU", | ||
| APIVersion: SchemeGroupVersion.String(), | ||
| } | ||
| } | ||
|
|
||
| // FromProtobufListTypeMeta generates the standard TypeMeta for the GPUList resource. | ||
| func FromProtobufListTypeMeta(_ *pb.GpuList) metav1.TypeMeta { | ||
| return metav1.TypeMeta{ | ||
| Kind: "GPUList", | ||
| APIVersion: SchemeGroupVersion.String(), | ||
| } | ||
| } | ||
|
|
||
| // FromProtobufTimestamp converts a protobuf Timestamp message to a metav1.Time. | ||
| func FromProtobufTimestamp(source *timestamppb.Timestamp) metav1.Time { | ||
| if source == nil { | ||
| return metav1.Time{} | ||
| } | ||
| return metav1.NewTime(source.AsTime()) | ||
| } | ||
|
|
||
| // ToProtobufTimestamp converts a metav1.Time to a protobuf Timestamp message. | ||
| func ToProtobufTimestamp(source metav1.Time) *timestamppb.Timestamp { | ||
| if source.IsZero() { | ||
| return nil | ||
| } | ||
| return timestamppb.New(source.Time) | ||
| } | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| // Copyright (c) 2025, NVIDIA CORPORATION. All rights reserved. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| // +groupName=device.nvidia.com | ||
|
|
||
| // Package v1alpha1 contains the API Schema definitions for the device.nvidia.com v1alpha1 API group. | ||
| // This package includes types for GPU resources and conversions between Kubernetes and protobuf representations. | ||
| package v1alpha1 |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.