Skip to content

Commit

Permalink
Merge pull request #128646 from pohly/dra-kubelet-separate-beta-api
Browse files Browse the repository at this point in the history
DRA kubelet: separate beta and alpha gRPC APIs

Kubernetes-commit: 33c64b380a11ba5a4d18a55b73d5f0a3ce89dc85
  • Loading branch information
k8s-publishing-bot committed Nov 8, 2024
2 parents 1a76702 + 4109653 commit 2466f75
Show file tree
Hide file tree
Showing 8 changed files with 2,897 additions and 67 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ require (
google.golang.org/grpc v1.65.0
k8s.io/api v0.0.0-20241108114310-4772861d607e
k8s.io/apimachinery v0.0.0-20241106231735-d941d9fb4c83
k8s.io/apiserver v0.0.0-20241108130125-a16a110639e2
k8s.io/apiserver v0.0.0-20241108130127-67b987f568cf
k8s.io/client-go v0.0.0-20241107030607-c57dbd8decb0
k8s.io/component-base v0.0.0-20241107031631-88ede593c6c4
k8s.io/cri-api v0.0.0-20241107034520-f9fb3fa09445
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ k8s.io/api v0.0.0-20241108114310-4772861d607e h1:SJxpg9FSTdq3qp/R+LRlZv+xjY+miO+
k8s.io/api v0.0.0-20241108114310-4772861d607e/go.mod h1:h7yaPC7+0KxMELdLjLoo6n6m3EWq6AeHEY25PjH4cPI=
k8s.io/apimachinery v0.0.0-20241106231735-d941d9fb4c83 h1:4KfMPmiiRIpvYJQ8cBYFEFht59EKysW1anuJWzHLHNg=
k8s.io/apimachinery v0.0.0-20241106231735-d941d9fb4c83/go.mod h1:HqhdaJUgQqky29T1V0o2yFkt/pZqLFIDyn9Zi/8rxoY=
k8s.io/apiserver v0.0.0-20241108130125-a16a110639e2 h1:q71K5wAlFyryMU0XhOTkatQ0yOG7bQoIayw04x2xiXo=
k8s.io/apiserver v0.0.0-20241108130125-a16a110639e2/go.mod h1:VLDdKhkEntyKQ7rqi4HyQPg0SPHjCBtQDzr65k2Juyk=
k8s.io/apiserver v0.0.0-20241108130127-67b987f568cf h1:eyiHXn+VALd4XtK8p1qiDaNWCqCJNXpXDrfB/L6H+Lk=
k8s.io/apiserver v0.0.0-20241108130127-67b987f568cf/go.mod h1:VLDdKhkEntyKQ7rqi4HyQPg0SPHjCBtQDzr65k2Juyk=
k8s.io/client-go v0.0.0-20241107030607-c57dbd8decb0 h1:oDzLA4eLxznpJJ7JNIpfFwtH1ItBtE6BS+YBhPJYoJE=
k8s.io/client-go v0.0.0-20241107030607-c57dbd8decb0/go.mod h1:rCMwfXeYh7ZWimHMUemazxHxkYOS3cd0ZjlzAQjtt78=
k8s.io/component-base v0.0.0-20241107031631-88ede593c6c4 h1:BK9K3H+e0KCAmVfWLpKPnFbDGyDj32JWiyLRFd995kk=
Expand Down
187 changes: 187 additions & 0 deletions pkg/apis/dra/v1alpha4/conversion.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
/*
Copyright 2024 The Kubernetes Authors.
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 v1alpha4

import (
context "context"
fmt "fmt"

grpc "google.golang.org/grpc"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/kubelet/pkg/apis/dra/v1beta1"
)

var (
localSchemeBuilder runtime.SchemeBuilder
AddToScheme = localSchemeBuilder.AddToScheme
)

// V1Beta1ServerWrapper implements the [NodeServer] interface by wrapping a [v1beta1.DRAPluginServer].
type V1Beta1ServerWrapper struct {
v1beta1.DRAPluginServer
}

var _ NodeServer = V1Beta1ServerWrapper{}

func (w V1Beta1ServerWrapper) NodePrepareResources(ctx context.Context, req *NodePrepareResourcesRequest) (*NodePrepareResourcesResponse, error) {
var convertedReq v1beta1.NodePrepareResourcesRequest
if err := Convert_v1alpha4_NodePrepareResourcesRequest_To_v1beta1_NodePrepareResourcesRequest(req, &convertedReq, nil); err != nil {
return nil, fmt.Errorf("internal error converting NodePrepareResourcesRequest from v1alpha4 to v1beta1: %w", err)
}
resp, err := w.DRAPluginServer.NodePrepareResources(ctx, &convertedReq)
if err != nil {
return nil, err
}
var convertedResp NodePrepareResourcesResponse
if err := Convert_v1beta1_NodePrepareResourcesResponse_To_v1alpha4_NodePrepareResourcesResponse(resp, &convertedResp, nil); err != nil {
return nil, fmt.Errorf("internal error converting NodePrepareResourcesResponse from v1beta1 to v1alpha4: %w", err)
}
return &convertedResp, nil
}

func (w V1Beta1ServerWrapper) NodeUnprepareResources(ctx context.Context, req *NodeUnprepareResourcesRequest) (*NodeUnprepareResourcesResponse, error) {
var convertedReq v1beta1.NodeUnprepareResourcesRequest
if err := Convert_v1alpha4_NodeUnprepareResourcesRequest_To_v1beta1_NodeUnprepareResourcesRequest(req, &convertedReq, nil); err != nil {
return nil, fmt.Errorf("internal error converting NodeUnprepareResourcesRequest from v1alpha4 to v1beta1: %w", err)
}
resp, err := w.DRAPluginServer.NodeUnprepareResources(ctx, &convertedReq)
if err != nil {
return nil, err
}
var convertedResp NodeUnprepareResourcesResponse
if err := Convert_v1beta1_NodeUnprepareResourcesResponse_To_v1alpha4_NodeUnprepareResourcesResponse(resp, &convertedResp, nil); err != nil {
return nil, fmt.Errorf("internal error converting NodeUnprepareResourcesResponse from v1beta1 to v1alpha4: %w", err)
}
return &convertedResp, nil
}

// V1Alpha4ServerWrapper implements the [v1beta1.DRAPluginServer] interface by wrapping a [NodeServer].
type V1Alpha4ServerWrapper struct {
NodeServer
}

var _ v1beta1.DRAPluginServer = V1Alpha4ServerWrapper{}

func (w V1Alpha4ServerWrapper) NodePrepareResources(ctx context.Context, req *v1beta1.NodePrepareResourcesRequest) (*v1beta1.NodePrepareResourcesResponse, error) {
var convertedReq NodePrepareResourcesRequest
if err := Convert_v1beta1_NodePrepareResourcesRequest_To_v1alpha4_NodePrepareResourcesRequest(req, &convertedReq, nil); err != nil {
return nil, fmt.Errorf("internal error converting NodePrepareResourcesRequest from v1beta1 to v1alpha4: %w", err)
}
resp, err := w.NodeServer.NodePrepareResources(ctx, &convertedReq)
if err != nil {
return nil, err
}
var convertedResp v1beta1.NodePrepareResourcesResponse
if err := Convert_v1alpha4_NodePrepareResourcesResponse_To_v1beta1_NodePrepareResourcesResponse(resp, &convertedResp, nil); err != nil {
return nil, fmt.Errorf("internal error converting NodePrepareResourcesResponse from v1alpha4 to v1beta1: %w", err)
}
return &convertedResp, nil
}

func (w V1Alpha4ServerWrapper) NodeUnprepareResources(ctx context.Context, req *v1beta1.NodeUnprepareResourcesRequest) (*v1beta1.NodeUnprepareResourcesResponse, error) {
var convertedReq NodeUnprepareResourcesRequest
if err := Convert_v1beta1_NodeUnprepareResourcesRequest_To_v1alpha4_NodeUnprepareResourcesRequest(req, &convertedReq, nil); err != nil {
return nil, fmt.Errorf("internal error converting NodeUnprepareResourcesRequest from v1beta1 to v1alpha4: %w", err)
}
resp, err := w.NodeServer.NodeUnprepareResources(ctx, &convertedReq)
if err != nil {
return nil, err
}
var convertedResp v1beta1.NodeUnprepareResourcesResponse
if err := Convert_v1alpha4_NodeUnprepareResourcesResponse_To_v1beta1_NodeUnprepareResourcesResponse(resp, &convertedResp, nil); err != nil {
return nil, fmt.Errorf("internal error converting NodeUnprepareResourcesResponse from v1alpha4 to v1beta1: %w", err)
}
return &convertedResp, nil
}

// V1Beta1ClientWrapper implements the [NodeClient] interface by wrapping a [v1beta1.DRAPluginClient].
type V1Beta1ClientWrapper struct {
v1beta1.DRAPluginClient
}

var _ NodeClient = V1Beta1ClientWrapper{}

func (w V1Beta1ClientWrapper) NodePrepareResources(ctx context.Context, req *NodePrepareResourcesRequest, options ...grpc.CallOption) (*NodePrepareResourcesResponse, error) {
var convertedReq v1beta1.NodePrepareResourcesRequest
if err := Convert_v1alpha4_NodePrepareResourcesRequest_To_v1beta1_NodePrepareResourcesRequest(req, &convertedReq, nil); err != nil {
return nil, fmt.Errorf("internal error converting NodePrepareResourcesRequest from v1alpha4 to v1beta1: %w", err)
}
resp, err := w.DRAPluginClient.NodePrepareResources(ctx, &convertedReq, options...)
if err != nil {
return nil, err
}
var convertedResp NodePrepareResourcesResponse
if err := Convert_v1beta1_NodePrepareResourcesResponse_To_v1alpha4_NodePrepareResourcesResponse(resp, &convertedResp, nil); err != nil {
return nil, fmt.Errorf("internal error converting NodePrepareResourcesResponse from v1beta1 to v1alpha4: %w", err)
}
return &convertedResp, nil
}

func (w V1Beta1ClientWrapper) NodeUnprepareResources(ctx context.Context, req *NodeUnprepareResourcesRequest, options ...grpc.CallOption) (*NodeUnprepareResourcesResponse, error) {
var convertedReq v1beta1.NodeUnprepareResourcesRequest
if err := Convert_v1alpha4_NodeUnprepareResourcesRequest_To_v1beta1_NodeUnprepareResourcesRequest(req, &convertedReq, nil); err != nil {
return nil, fmt.Errorf("internal error converting NodeUnprepareResourcesRequest from v1alpha4 to v1beta1: %w", err)
}
resp, err := w.DRAPluginClient.NodeUnprepareResources(ctx, &convertedReq, options...)
if err != nil {
return nil, err
}
var convertedResp NodeUnprepareResourcesResponse
if err := Convert_v1beta1_NodeUnprepareResourcesResponse_To_v1alpha4_NodeUnprepareResourcesResponse(resp, &convertedResp, nil); err != nil {
return nil, fmt.Errorf("internal error converting NodeUnprepareResourcesResponse from v1beta1 to v1alpha4: %w", err)
}
return &convertedResp, nil
}

// V1Alpha4ClientWrapper implements the [v1beta1.DRAPluginClient] interface by wrapping a [NodeClient].
type V1Alpha4ClientWrapper struct {
NodeClient
}

var _ v1beta1.DRAPluginClient = V1Alpha4ClientWrapper{}

func (w V1Alpha4ClientWrapper) NodePrepareResources(ctx context.Context, req *v1beta1.NodePrepareResourcesRequest, options ...grpc.CallOption) (*v1beta1.NodePrepareResourcesResponse, error) {
var convertedReq NodePrepareResourcesRequest
if err := Convert_v1beta1_NodePrepareResourcesRequest_To_v1alpha4_NodePrepareResourcesRequest(req, &convertedReq, nil); err != nil {
return nil, fmt.Errorf("internal error converting NodePrepareResourcesRequest from v1beta1 to v1alpha4: %w", err)
}
resp, err := w.NodeClient.NodePrepareResources(ctx, &convertedReq, options...)
if err != nil {
return nil, err
}
var convertedResp v1beta1.NodePrepareResourcesResponse
if err := Convert_v1alpha4_NodePrepareResourcesResponse_To_v1beta1_NodePrepareResourcesResponse(resp, &convertedResp, nil); err != nil {
return nil, fmt.Errorf("internal error converting NodePrepareResourcesResponse from v1alpha4 to v1beta1: %w", err)
}
return &convertedResp, nil
}

func (w V1Alpha4ClientWrapper) NodeUnprepareResources(ctx context.Context, req *v1beta1.NodeUnprepareResourcesRequest, options ...grpc.CallOption) (*v1beta1.NodeUnprepareResourcesResponse, error) {
var convertedReq NodeUnprepareResourcesRequest
if err := Convert_v1beta1_NodeUnprepareResourcesRequest_To_v1alpha4_NodeUnprepareResourcesRequest(req, &convertedReq, nil); err != nil {
return nil, fmt.Errorf("internal error converting NodeUnprepareResourcesRequest from v1beta1 to v1alpha4: %w", err)
}
resp, err := w.NodeClient.NodeUnprepareResources(ctx, &convertedReq, options...)
if err != nil {
return nil, err
}
var convertedResp v1beta1.NodeUnprepareResourcesResponse
if err := Convert_v1alpha4_NodeUnprepareResourcesResponse_To_v1beta1_NodeUnprepareResourcesResponse(resp, &convertedResp, nil); err != nil {
return nil, fmt.Errorf("internal error converting NodeUnprepareResourcesResponse from v1alpha4 to v1beta1: %w", err)
}
return &convertedResp, nil
}
21 changes: 21 additions & 0 deletions pkg/apis/dra/v1alpha4/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
Copyright 2024 The Kubernetes Authors.
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 v1alpha4 contains a legacy implementation of the DRA gRPC
// interface. Support for it in kubelet is provided via conversion.
//
// +k8s:conversion-gen=k8s.io/kubelet/pkg/apis/dra/v1beta1
package v1alpha4
Loading

0 comments on commit 2466f75

Please sign in to comment.