Skip to content
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

Update kubeletplugin API for DRA to v1alpha2 #116558

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 24 additions & 6 deletions api/openapi-spec/swagger.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 29 additions & 6 deletions api/openapi-spec/v3/apis__resource.k8s.io__v1alpha2_openapi.json
Expand Up @@ -83,19 +83,28 @@
"x-kubernetes-map-type": "atomic"
},
"io.k8s.api.resource.v1alpha2.AllocationResult": {
"description": "AllocationResult contains attributed of an allocated resource.",
"description": "AllocationResult contains attributes of an allocated resource.",
"properties": {
"availableOnNodes": {
"allOf": [
{
"$ref": "#/components/schemas/io.k8s.api.core.v1.NodeSelector"
}
],
"description": "This field will get set by the resource driver after it has allocated the resource driver to inform the scheduler where it can schedule Pods using the ResourceClaim.\n\nSetting this field is optional. If null, the resource is available everywhere."
"description": "This field will get set by the resource driver after it has allocated the resource to inform the scheduler where it can schedule Pods using the ResourceClaim.\n\nSetting this field is optional. If null, the resource is available everywhere."
},
"resourceHandle": {
"description": "ResourceHandle contains arbitrary data returned by the driver after a successful allocation. This is opaque for Kubernetes. Driver documentation may explain to users how to interpret this data if needed.\n\nThe maximum size of this field is 16KiB. This may get increased in the future, but not reduced.",
"type": "string"
"resourceHandles": {
"description": "ResourceHandles contain the state associated with an allocation that should be maintained throughout the lifetime of a claim. Each ResourceHandle contains data that should be passed to a specific kubelet plugin once it lands on a node. This data is returned by the driver after a successful allocation and is opaque to Kubernetes. Driver documentation may explain to users how to interpret this data if needed.\n\nSetting this field is optional. It has a maximum size of 32 entries. If null (or empty), it is assumed this allocation will be processed by a single kubelet plugin with no ResourceHandle data attached. The name of the kubelet plugin invoked will match the DriverName set in the ResourceClaimStatus this AllocationResult is embedded in.",
"items": {
"allOf": [
{
"$ref": "#/components/schemas/io.k8s.api.resource.v1alpha2.ResourceHandle"
}
],
"default": {}
},
"type": "array",
"x-kubernetes-list-type": "atomic"
},
"shareable": {
"description": "Shareable determines whether the resource supports more than one consumer at a time.",
Expand Down Expand Up @@ -445,7 +454,7 @@
"$ref": "#/components/schemas/io.k8s.api.resource.v1alpha2.AllocationResult"
}
],
"description": "Allocation is set by the resource driver once a resource has been allocated successfully. If this is not specified, the resource is not yet allocated."
"description": "Allocation is set by the resource driver once a resource or set of resources has been allocated successfully. If this is not specified, the resources have not been allocated yet."
},
"deallocationRequested": {
"description": "DeallocationRequested indicates that a ResourceClaim is to be deallocated.\n\nThe driver then must deallocate this claim and reset the field together with clearing the Allocation field.\n\nWhile DeallocationRequested is set, no new consumers may be added to ReservedFor.",
Expand Down Expand Up @@ -715,6 +724,20 @@
],
"type": "object"
},
"io.k8s.api.resource.v1alpha2.ResourceHandle": {
"description": "ResourceHandle holds opaque resource data for processing by a specific kubelet plugin.",
"properties": {
"data": {
"description": "Data contains the opaque data associated with this ResourceHandle. It is set by the controller component of the resource driver whose name matches the DriverName set in the ResourceClaimStatus this ResourceHandle is embedded in. It is set at allocation time and is intended for processing by the kubelet plugin whose name matches the DriverName set in this ResourceHandle.\n\nThe maximum size of this field is 16KiB. This may get increased in the future, but not reduced.",
"type": "string"
},
"driverName": {
"description": "DriverName specifies the name of the resource driver whose kubelet plugin should be invoked to process this ResourceHandle's data once it lands on a node. This may differ from the DriverName set in ResourceClaimStatus this ResourceHandle is embedded in.",
"type": "string"
}
},
"type": "object"
},
"io.k8s.apimachinery.pkg.apis.meta.v1.APIResource": {
"description": "APIResource specifies the name of a resource and whether it is namespaced.",
"properties": {
Expand Down
64 changes: 48 additions & 16 deletions pkg/apis/resource/types.go
Expand Up @@ -97,9 +97,9 @@ type ResourceClaimStatus struct {
// +optional
DriverName string

// Allocation is set by the resource driver once a resource has been
// allocated successfully. If this is not specified, the resource is
// not yet allocated.
// Allocation is set by the resource driver once a resource or set of
// resources has been allocated successfully. If this is not specified, the
// resources have not been allocated yet.
// +optional
Allocation *AllocationResult

Expand Down Expand Up @@ -128,21 +128,28 @@ type ResourceClaimStatus struct {
// claim.status.reservedFor.
const ResourceClaimReservedForMaxSize = 32

// AllocationResult contains attributed of an allocated resource.
// AllocationResult contains attributes of an allocated resource.
type AllocationResult struct {
// ResourceHandle contains arbitrary data returned by the driver after a
// successful allocation. This is opaque for
// Kubernetes. Driver documentation may explain to users how to
// interpret this data if needed.
// ResourceHandles contain the state associated with an allocation that
// should be maintained throughout the lifetime of a claim. Each
// ResourceHandle contains data that should be passed to a specific kubelet
// plugin once it lands on a node. This data is returned by the driver
// after a successful allocation and is opaque to Kubernetes. Driver
// documentation may explain to users how to interpret this data if needed.
//
// The maximum size of this field is 16KiB. This may get
// increased in the future, but not reduced.
// Setting this field is optional. It has a maximum size of 32 entries.
// If null (or empty), it is assumed this allocation will be processed by a
// single kubelet plugin with no ResourceHandle data attached. The name of
// the kubelet plugin invoked will match the DriverName set in the
// ResourceClaimStatus this AllocationResult is embedded in.
//
// +listType=atomic
// +optional
ResourceHandle string
ResourceHandles []ResourceHandle

// This field will get set by the resource driver after it has
// allocated the resource driver to inform the scheduler where it can
// schedule Pods using the ResourceClaim.
// This field will get set by the resource driver after it has allocated
// the resource to inform the scheduler where it can schedule Pods using
// the ResourceClaim.
//
// Setting this field is optional. If null, the resource is available
// everywhere.
Expand All @@ -155,8 +162,33 @@ type AllocationResult struct {
Shareable bool
}

// ResourceHandleMaxSize is the maximum size of allocation.resourceHandle.
const ResourceHandleMaxSize = 16 * 1024
// AllocationResultResourceHandlesMaxSize represents the maximum number of
// entries in allocation.resourceHandles.
const AllocationResultResourceHandlesMaxSize = 32

// ResourceHandle holds opaque resource data for processing by a specific kubelet plugin.
type ResourceHandle struct {
// DriverName specifies the name of the resource driver whose kubelet
// plugin should be invoked to process this ResourceHandle's data once it
// lands on a node. This may differ from the DriverName set in
// ResourceClaimStatus this ResourceHandle is embedded in.
DriverName string

// Data contains the opaque data associated with this ResourceHandle. It is
// set by the controller component of the resource driver whose name
// matches the DriverName set in the ResourceClaimStatus this
// ResourceHandle is embedded in. It is set at allocation time and is
// intended for processing by the kubelet plugin whose name matches
// the DriverName set in this ResourceHandle.
//
// The maximum size of this field is 16KiB. This may get increased in the
// future, but not reduced.
// +optional
Data string
}

// ResourceHandleDataMaxSize represents the maximum size of resourceHandle.data.
const ResourceHandleDataMaxSize = 16 * 1024

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

Expand Down
36 changes: 34 additions & 2 deletions pkg/apis/resource/v1alpha2/zz_generated.conversion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 25 additions & 2 deletions pkg/apis/resource/validation/validation.go
Expand Up @@ -155,6 +155,11 @@ func ValidateClaimStatusUpdate(resourceClaim, oldClaim *resource.ResourceClaim)
}
}

// Updates to a populated resourceClaim.Status.Allocation are not allowed
if oldClaim.Status.Allocation != nil && resourceClaim.Status.Allocation != nil {
allErrs = append(allErrs, apimachineryvalidation.ValidateImmutableField(resourceClaim.Status.Allocation, oldClaim.Status.Allocation, fldPath.Child("allocation"))...)
}

if !oldClaim.Status.DeallocationRequested &&
resourceClaim.Status.DeallocationRequested &&
len(resourceClaim.Status.ReservedFor) > 0 {
Expand Down Expand Up @@ -185,8 +190,8 @@ func ValidateClaimStatusUpdate(resourceClaim, oldClaim *resource.ResourceClaim)
func validateAllocationResult(allocation *resource.AllocationResult, fldPath *field.Path) field.ErrorList {
var allErrs field.ErrorList
if allocation != nil {
if len(allocation.ResourceHandle) > resource.ResourceHandleMaxSize {
allErrs = append(allErrs, field.TooLongMaxLength(fldPath.Child("resourceHandle"), len(allocation.ResourceHandle), resource.ResourceHandleMaxSize))
if len(allocation.ResourceHandles) > 0 {
allErrs = append(allErrs, validateResourceHandles(allocation.ResourceHandles, resource.AllocationResultResourceHandlesMaxSize, fldPath.Child("resourceHandles"))...)
}
if allocation.AvailableOnNodes != nil {
allErrs = append(allErrs, corevalidation.ValidateNodeSelector(allocation.AvailableOnNodes, fldPath.Child("availableOnNodes"))...)
Expand All @@ -195,6 +200,24 @@ func validateAllocationResult(allocation *resource.AllocationResult, fldPath *fi
return allErrs
}

func validateResourceHandles(resourceHandles []resource.ResourceHandle, maxSize int, fldPath *field.Path) field.ErrorList {
var allErrs field.ErrorList
for i, resourceHandle := range resourceHandles {
idxPath := fldPath.Index(i)
allErrs = append(allErrs, validateResourceDriverName(resourceHandle.DriverName, idxPath.Child("driverName"))...)
if len(resourceHandle.Data) > resource.ResourceHandleDataMaxSize {
allErrs = append(allErrs, field.TooLongMaxLength(idxPath.Child("data"), len(resourceHandle.Data), resource.ResourceHandleDataMaxSize))
}
}
if len(resourceHandles) > maxSize {
// Dumping the entire field into the error message is likely to be too long,
// in particular when it is already beyond the maximum size. Instead this
// just shows the number of entries.
allErrs = append(allErrs, field.TooLongMaxLength(fldPath, len(resourceHandles), maxSize))
}
return allErrs
}

func validateResourceClaimUserReference(ref resource.ResourceClaimConsumerReference, fldPath *field.Path) field.ErrorList {
var allErrs field.ErrorList
if ref.Resource == "" {
Expand Down