Skip to content

Instantly share code, notes, and snippets.

@klueska
Created February 12, 2024 10:24
Show Gist options
  • Save klueska/8d50cc37879f49cf690493a6bb53e302 to your computer and use it in GitHub Desktop.
Save klueska/8d50cc37879f49cf690493a6bb53e302 to your computer and use it in GitHub Desktop.
NodeResourceSliceSpec
package main
import (
semverv4 "github.com/blang/semver/v4"
"k8s.io/apimachinery/pkg/api/resource"
)
type NodeResourceSliceSpec struct {
// NodeName identifies the node where the capacity is available.
// A field selector can be used to list only NodeResources
// objects with a certain node name.
NodeName string `json:"nodeName"`
// DriverName identifies the DRA driver providing the capacity information.
// A field selector can be used to list only NodeResources
// objects with a certain driver name.
DriverName string `json:"driverName"`
NodeResourceModel `json:""`
}
// NodeResourceModel must have one and only one field set.
type NodeResourceModel struct {
NamedResourcesWithAttributes *NamedResourcesWithAttributes `json:"namedResourcesWithAttributes,omitempty"`
}
type NamedResourcesWithAttributes struct {
Resources []NamedResourceWithAttributes `json:"resources"`
}
type NamedResourceWithAttributes struct {
Name string `json:"name"`
Attributes []Attribute `json:"attributes,omitempty"`
}
type Attribute struct {
Name string `json:"name"`
AttributeValue `json:""`
}
// AttributeValue must have one and only one field set.
type AttributeValue struct {
Quantity *resource.Quantity `json:"quantity,omitempty"`
Bool *bool `json:"bool,omitempty"`
Int *int64 `json:"int,omitempty"`
IntSlice *[]int64 `json:"intSlice,omitempty"`
String *string `json:"string,omitempty"`
StringSlice *[]string `json:"stringSlice,omitempty"`
Version *SemVersion `json:"version,omitempty"`
}
// A wrapper around https://pkg.go.dev/github.com/blang/semver/v4#Version which
// is encoded as a string. During decoding, it validates that the string
// can be parsed using tolerant parsing (currently trims spaces, removes a "v" prefix,
// adds a 0 patch number to versions with only major and minor components specified,
// and removes leading 0s).
type SemVersion struct {
semverv4.Version `json:""`
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment