DRA: read ResourceClaim in DRA drivers

This is the second and final step towards making kubelet independent of the
resource.k8s.io API versioning because it now doesn't need to copy structs
defined by that API from the driver to the API server.

Kubernetes-commit: 348f94ab55053ec9b4382de880406e27a730d8cd
This commit is contained in:
Patrick Ohly 2024-04-11 16:20:34 +02:00 committed by Kubernetes Publisher
parent 63f4c6d282
commit 45d6a8ccfb
2 changed files with 34 additions and 178 deletions

View File

@ -29,7 +29,6 @@ import (
codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status"
io "io"
v1alpha2 "k8s.io/api/resource/v1alpha2"
math "math"
math_bits "math/bits"
reflect "reflect"
@ -351,18 +350,9 @@ type Claim struct {
Uid string `protobuf:"bytes,2,opt,name=uid,proto3" json:"uid,omitempty"`
// The name of the Resource claim (ResourceClaim.meta.Name)
// This field is REQUIRED.
Name string `protobuf:"bytes,3,opt,name=name,proto3" json:"name,omitempty"`
// Resource handle (AllocationResult.ResourceHandles[*].Data)
// This field is REQUIRED.
ResourceHandle string `protobuf:"bytes,4,opt,name=resource_handle,json=resourceHandle,proto3" json:"resource_handle,omitempty"`
// Structured parameter resource handle (AllocationResult.ResourceHandles[*].StructuredData).
// This field is OPTIONAL. If present, it needs to be used
// instead of resource_handle. It will only have a single entry.
//
// Using "repeated" instead of "optional" is a workaround for https://github.com/gogo/protobuf/issues/713.
StructuredResourceHandle []*v1alpha2.StructuredResourceHandle `protobuf:"bytes,5,rep,name=structured_resource_handle,json=structuredResourceHandle,proto3" json:"structured_resource_handle,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_sizecache int32 `json:"-"`
Name string `protobuf:"bytes,3,opt,name=name,proto3" json:"name,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *Claim) Reset() { *m = Claim{} }
@ -418,20 +408,6 @@ func (m *Claim) GetName() string {
return ""
}
func (m *Claim) GetResourceHandle() string {
if m != nil {
return m.ResourceHandle
}
return ""
}
func (m *Claim) GetStructuredResourceHandle() []*v1alpha2.StructuredResourceHandle {
if m != nil {
return m.StructuredResourceHandle
}
return nil
}
func init() {
proto.RegisterType((*NodePrepareResourcesRequest)(nil), "v1alpha3.NodePrepareResourcesRequest")
proto.RegisterType((*NodePrepareResourcesResponse)(nil), "v1alpha3.NodePrepareResourcesResponse")
@ -447,43 +423,37 @@ func init() {
func init() { proto.RegisterFile("api.proto", fileDescriptor_00212fb1f9d3bf1c) }
var fileDescriptor_00212fb1f9d3bf1c = []byte{
// 562 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x54, 0xcd, 0x6e, 0xd3, 0x40,
0x10, 0xce, 0x36, 0x49, 0x45, 0x26, 0x52, 0x8b, 0x56, 0x15, 0xb2, 0x42, 0x31, 0x91, 0x45, 0x49,
0x0e, 0x60, 0x0b, 0x07, 0x50, 0x05, 0xe2, 0x92, 0x16, 0x54, 0x10, 0x42, 0xc8, 0x88, 0x0b, 0x97,
0xb0, 0xb1, 0x07, 0xc7, 0x4a, 0x62, 0x9b, 0x5d, 0x3b, 0x52, 0x6f, 0x3c, 0x02, 0x8f, 0xd5, 0x03,
0x07, 0xc4, 0x89, 0x53, 0x45, 0xcd, 0x8d, 0xa7, 0x40, 0x5e, 0xdb, 0x69, 0x13, 0x39, 0x4d, 0xa5,
0xde, 0x66, 0xe7, 0xef, 0x9b, 0xfd, 0xe6, 0x07, 0x1a, 0x2c, 0xf4, 0xf4, 0x90, 0x07, 0x51, 0x40,
0x6f, 0xcc, 0x1e, 0xb1, 0x49, 0x38, 0x62, 0xbd, 0xd6, 0x43, 0xd7, 0x8b, 0x46, 0xf1, 0x50, 0xb7,
0x83, 0xa9, 0xe1, 0x06, 0x6e, 0x60, 0x48, 0x87, 0x61, 0xfc, 0x45, 0xbe, 0xe4, 0x43, 0x4a, 0x59,
0x60, 0xeb, 0xc1, 0x78, 0x5f, 0xe8, 0x5e, 0x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9f, 0xa9, 0x95, 0x6f, 0x89, 0x4a, 0x4e, 0x12, 0x95, 0xfc,
0x4c, 0x54, 0xf2, 0x27, 0x51, 0xc9, 0xf7, 0xbf, 0x6a, 0xe5, 0xd3, 0xbd, 0xfc, 0xd8, 0x8d, 0xe3,
0x21, 0x4e, 0x30, 0x32, 0xc2, 0xb1, 0x9b, 0x1e, 0x3e, 0x61, 0x38, 0x9c, 0x15, 0x47, 0xaf, 0x37,
0xdc, 0x94, 0xb7, 0xae, 0xf7, 0x3f, 0x00, 0x00, 0xff, 0xff, 0xfd, 0x14, 0x30, 0xd4, 0x5f, 0x05,
0x00, 0x00,
// 480 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x54, 0x4d, 0x6f, 0xd3, 0x40,
0x10, 0xcd, 0x36, 0x4d, 0x85, 0x27, 0x12, 0xa0, 0x55, 0x85, 0xa2, 0x50, 0x4c, 0x64, 0x51, 0x92,
0x0b, 0xb6, 0x48, 0x41, 0xaa, 0x40, 0x5c, 0xd2, 0x82, 0xf8, 0x12, 0x42, 0x96, 0xb8, 0x70, 0x81,
0xb5, 0x3d, 0xb8, 0xab, 0x7c, 0xec, 0xb2, 0x6b, 0x47, 0xea, 0x8d, 0x9f, 0xc0, 0xcf, 0xea, 0x81,
0x03, 0xe2, 0xc4, 0xa9, 0xa2, 0xe6, 0x8f, 0x20, 0xaf, 0x9d, 0xf4, 0x43, 0x4e, 0x5d, 0x89, 0xdb,
0xcc, 0x78, 0x67, 0xde, 0x9b, 0xf7, 0x46, 0x06, 0x8b, 0x49, 0xee, 0x4a, 0x25, 0x12, 0x41, 0xaf,
0xcd, 0x1f, 0xb2, 0x89, 0x3c, 0x60, 0x3b, 0xdd, 0x07, 0x31, 0x4f, 0x0e, 0xd2, 0xc0, 0x0d, 0xc5,
0xd4, 0x8b, 0x45, 0x2c, 0x3c, 0xf3, 0x20, 0x48, 0xbf, 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, 0x30, 0xeb, 0xd1, 0x79, 0x51, 0x56, 0x77, 0x56, 0x5a, 0x10, 0xd4, 0x59, 0xf0, 0xec,
0xbc, 0x05, 0xfd, 0x1a, 0xb4, 0x2a, 0x13, 0x1e, 0xaf, 0x90, 0x67, 0xb9, 0xd2, 0x52, 0x55, 0x72,
0x56, 0xd5, 0x37, 0xd0, 0x32, 0xd4, 0xe8, 0x16, 0x58, 0x33, 0x36, 0x45, 0x2d, 0x59, 0x88, 0xe5,
0x93, 0xd3, 0x42, 0x4e, 0x39, 0xe5, 0x51, 0x69, 0x48, 0x1e, 0x52, 0x0a, 0xeb, 0xf9, 0xe7, 0x4e,
0xd3, 0x94, 0x4c, 0x3c, 0x3c, 0x26, 0xb0, 0x9e, 0x93, 0xa0, 0x31, 0x6c, 0x56, 0xdd, 0x29, 0xdd,
0xae, 0xbb, 0x63, 0xe3, 0x64, 0xf7, 0xfe, 0xd5, 0xce, 0xdd, 0x69, 0xd0, 0x29, 0xdc, 0xaa, 0xf6,
0x83, 0xf6, 0xeb, 0x1d, 0x2b, 0xc0, 0x06, 0x57, 0xb5, 0xd6, 0x69, 0x8c, 0x46, 0x47, 0x27, 0x36,
0xf9, 0x7d, 0x62, 0x37, 0xbe, 0x65, 0x36, 0x39, 0xca, 0x6c, 0xf2, 0x33, 0xb3, 0xc9, 0x9f, 0xcc,
0x26, 0xdf, 0xff, 0xda, 0x8d, 0x8f, 0xf7, 0xc6, 0xbb, 0xda, 0xe5, 0xc2, 0x1b, 0xa7, 0x01, 0x4e,
0x30, 0xf1, 0xe4, 0x38, 0xf6, 0x98, 0xe4, 0xda, 0x8b, 0x14, 0xf3, 0x16, 0x20, 0xc1, 0x86, 0xf9,
0x97, 0xec, 0xfc, 0x0b, 0x00, 0x00, 0xff, 0xff, 0xac, 0xa8, 0xa3, 0x6a, 0x91, 0x04, 0x00, 0x00,
}
// Reference imports to suppress errors if they are not otherwise used.
@ -875,27 +845,6 @@ func (m *Claim) MarshalToSizedBuffer(dAtA []byte) (int, error) {
_ = i
var l int
_ = l
if len(m.StructuredResourceHandle) > 0 {
for iNdEx := len(m.StructuredResourceHandle) - 1; iNdEx >= 0; iNdEx-- {
{
size, err := m.StructuredResourceHandle[iNdEx].MarshalToSizedBuffer(dAtA[:i])
if err != nil {
return 0, err
}
i -= size
i = encodeVarintApi(dAtA, i, uint64(size))
}
i--
dAtA[i] = 0x2a
}
}
if len(m.ResourceHandle) > 0 {
i -= len(m.ResourceHandle)
copy(dAtA[i:], m.ResourceHandle)
i = encodeVarintApi(dAtA, i, uint64(len(m.ResourceHandle)))
i--
dAtA[i] = 0x22
}
if len(m.Name) > 0 {
i -= len(m.Name)
copy(dAtA[i:], m.Name)
@ -1055,16 +1004,6 @@ func (m *Claim) Size() (n int) {
if l > 0 {
n += 1 + l + sovApi(uint64(l))
}
l = len(m.ResourceHandle)
if l > 0 {
n += 1 + l + sovApi(uint64(l))
}
if len(m.StructuredResourceHandle) > 0 {
for _, e := range m.StructuredResourceHandle {
l = e.Size()
n += 1 + l + sovApi(uint64(l))
}
}
return n
}
@ -1169,17 +1108,10 @@ func (this *Claim) String() string {
if this == nil {
return "nil"
}
repeatedStringForStructuredResourceHandle := "[]*StructuredResourceHandle{"
for _, f := range this.StructuredResourceHandle {
repeatedStringForStructuredResourceHandle += strings.Replace(fmt.Sprintf("%v", f), "StructuredResourceHandle", "v1alpha2.StructuredResourceHandle", 1) + ","
}
repeatedStringForStructuredResourceHandle += "}"
s := strings.Join([]string{`&Claim{`,
`Namespace:` + fmt.Sprintf("%v", this.Namespace) + `,`,
`Uid:` + fmt.Sprintf("%v", this.Uid) + `,`,
`Name:` + fmt.Sprintf("%v", this.Name) + `,`,
`ResourceHandle:` + fmt.Sprintf("%v", this.ResourceHandle) + `,`,
`StructuredResourceHandle:` + repeatedStringForStructuredResourceHandle + `,`,
`}`,
}, "")
return s
@ -2039,72 +1971,6 @@ func (m *Claim) Unmarshal(dAtA []byte) error {
}
m.Name = string(dAtA[iNdEx:postIndex])
iNdEx = postIndex
case 4:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field ResourceHandle", wireType)
}
var stringLen uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowApi
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
stringLen |= uint64(b&0x7F) << shift
if b < 0x80 {
break
}
}
intStringLen := int(stringLen)
if intStringLen < 0 {
return ErrInvalidLengthApi
}
postIndex := iNdEx + intStringLen
if postIndex < 0 {
return ErrInvalidLengthApi
}
if postIndex > l {
return io.ErrUnexpectedEOF
}
m.ResourceHandle = string(dAtA[iNdEx:postIndex])
iNdEx = postIndex
case 5:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field StructuredResourceHandle", wireType)
}
var msglen int
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowApi
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
msglen |= int(b&0x7F) << shift
if b < 0x80 {
break
}
}
if msglen < 0 {
return ErrInvalidLengthApi
}
postIndex := iNdEx + msglen
if postIndex < 0 {
return ErrInvalidLengthApi
}
if postIndex > l {
return io.ErrUnexpectedEOF
}
m.StructuredResourceHandle = append(m.StructuredResourceHandle, &v1alpha2.StructuredResourceHandle{})
if err := m.StructuredResourceHandle[len(m.StructuredResourceHandle)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
return err
}
iNdEx = postIndex
default:
iNdEx = preIndex
skippy, err := skipApi(dAtA[iNdEx:])

View File

@ -22,7 +22,6 @@ package v1alpha3;
option go_package = "k8s.io/kubelet/pkg/apis/dra/v1alpha3";
import "github.com/gogo/protobuf/gogoproto/gogo.proto";
import "k8s.io/api/resource/v1alpha2/generated.proto";
option (gogoproto.goproto_stringer_all) = false;
option (gogoproto.stringer_all) = true;
@ -102,13 +101,4 @@ message Claim {
// The name of the Resource claim (ResourceClaim.meta.Name)
// This field is REQUIRED.
string name = 3;
// Resource handle (AllocationResult.ResourceHandles[*].Data)
// This field is REQUIRED.
string resource_handle = 4;
// Structured parameter resource handle (AllocationResult.ResourceHandles[*].StructuredData).
// This field is OPTIONAL. If present, it needs to be used
// instead of resource_handle. It will only have a single entry.
//
// Using "repeated" instead of "optional" is a workaround for https://github.com/gogo/protobuf/issues/713.
repeated k8s.io.api.resource.v1alpha2.StructuredResourceHandle structured_resource_handle = 5;
}