Skip to content

Commit a3368ee

Browse files
committed
Convert k8s.io/kubelet/pkg/apis/dra from gogo to protoc
Use standard protoc for the dra instead of gogo. Part of #96564 Signed-off-by: Sascha Grunert <sgrunert@redhat.com>
1 parent 1e04b17 commit a3368ee

File tree

16 files changed

+1357
-4613
lines changed

16 files changed

+1357
-4613
lines changed

hack/unwanted-dependencies.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,6 @@
153153
"k8s.io/client-go",
154154
"k8s.io/code-generator",
155155
"k8s.io/kube-aggregator",
156-
"k8s.io/kubelet",
157156
"k8s.io/kubernetes",
158157
"k8s.io/metrics"
159158
],

hack/update-codegen.sh

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,10 +1020,8 @@ function codegen::protobindings() {
10201020

10211021
# Each element of this array is a directory containing subdirectories which
10221022
# eventually contain a file named "api.proto".
1023-
local apis_using_gogo=(
1023+
local apis=(
10241024
"staging/src/k8s.io/kubelet/pkg/apis/dra"
1025-
)
1026-
local apis_using_protoc=(
10271025
"staging/src/k8s.io/kubelet/pkg/apis/deviceplugin"
10281026
"staging/src/k8s.io/kubelet/pkg/apis/podresources"
10291027
"staging/src/k8s.io/kms/apis"
@@ -1034,7 +1032,6 @@ function codegen::protobindings() {
10341032
"staging/src/k8s.io/externaljwt/apis"
10351033
"staging/src/k8s.io/kubelet/pkg/apis/dra-health"
10361034
)
1037-
local apis=("${apis_using_gogo[@]}" "${apis_using_protoc[@]}")
10381035

10391036
kube::log::status "protobuf bindings: ${#apis[@]} targets"
10401037
if [[ "${DBG_CODEGEN}" == 1 ]]; then
@@ -1050,15 +1047,13 @@ function codegen::protobindings() {
10501047
done
10511048

10521049
if kube::protoc::check_protoc >/dev/null; then
1053-
hack/_update-generated-proto-bindings-dockerized.sh gogo "${apis_using_gogo[@]}"
1054-
hack/_update-generated-proto-bindings-dockerized.sh protoc "${apis_using_protoc[@]}"
1050+
hack/_update-generated-proto-bindings-dockerized.sh protoc "${apis[@]}"
10551051
else
10561052
kube::log::status "protoc ${PROTOC_VERSION} not found (can install with hack/install-protoc.sh); generating containerized..."
10571053
# NOTE: All output from this script needs to be copied back to the calling
10581054
# source tree. This is managed in kube::build::copy_output in build/common.sh.
10591055
# If the output set is changed update that function.
1060-
build/run.sh hack/_update-generated-proto-bindings-dockerized.sh gogo "${apis_using_gogo[@]}"
1061-
build/run.sh hack/_update-generated-proto-bindings-dockerized.sh protoc "${apis_using_protoc[@]}"
1056+
build/run.sh hack/_update-generated-proto-bindings-dockerized.sh protoc "${apis[@]}"
10621057
fi
10631058
}
10641059

pkg/kubelet/cm/dra/manager.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ func (m *Manager) prepareResources(ctx context.Context, pod *v1.Pod) error {
358358
// Loop through all drivers and prepare for calling NodePrepareResources.
359359
claim := &drapb.Claim{
360360
Namespace: claimInfo.Namespace,
361-
UID: string(claimInfo.ClaimUID),
361+
Uid: string(claimInfo.ClaimUID),
362362
Name: claimInfo.ClaimName,
363363
}
364364
for driverName := range claimInfo.DriverState {
@@ -403,7 +403,7 @@ func (m *Manager) prepareResources(ctx context.Context, pod *v1.Pod) error {
403403
return fmt.Errorf("internal error: unable to get claim info for ResourceClaim %s", claim.Name)
404404
}
405405
for _, device := range result.GetDevices() {
406-
info.addDevice(plugin.DriverName(), state.Device{PoolName: device.PoolName, DeviceName: device.DeviceName, RequestNames: device.RequestNames, CDIDeviceIDs: device.CDIDeviceIDs})
406+
info.addDevice(plugin.DriverName(), state.Device{PoolName: device.PoolName, DeviceName: device.DeviceName, RequestNames: device.RequestNames, CDIDeviceIDs: device.CdiDeviceIds})
407407
}
408408
return nil
409409
})
@@ -448,7 +448,7 @@ func (m *Manager) prepareResources(ctx context.Context, pod *v1.Pod) error {
448448

449449
func lookupClaimRequest(claims []*drapb.Claim, claimUID string) *drapb.Claim {
450450
for _, claim := range claims {
451-
if claim.UID == claimUID {
451+
if claim.Uid == claimUID {
452452
return claim
453453
}
454454
}
@@ -565,7 +565,7 @@ func (m *Manager) unprepareResources(ctx context.Context, podUID types.UID, name
565565
// Loop through all drivers and prepare for calling NodeUnprepareResources.
566566
claim := &drapb.Claim{
567567
Namespace: claimInfo.Namespace,
568-
UID: string(claimInfo.ClaimUID),
568+
Uid: string(claimInfo.ClaimUID),
569569
Name: claimInfo.ClaimName,
570570
}
571571
for driverName := range claimInfo.DriverState {

pkg/kubelet/cm/dra/manager_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,17 +79,17 @@ func (s *fakeDRADriverGRPCServer) NodePrepareResources(ctx context.Context, req
7979
}
8080

8181
if s.prepareResourcesResponse == nil {
82-
cdiDeviceName := "claim-" + req.Claims[0].UID
82+
cdiDeviceName := "claim-" + req.Claims[0].Uid
8383
cdiID := s.driverName + "/" + driverClassName + "=" + cdiDeviceName
8484
return &drapb.NodePrepareResourcesResponse{
8585
Claims: map[string]*drapb.NodePrepareResourceResponse{
86-
req.Claims[0].UID: {
86+
req.Claims[0].Uid: {
8787
Devices: []*drapb.Device{
8888
{
8989
PoolName: poolName,
9090
DeviceName: deviceName,
9191
RequestNames: []string{req.Claims[0].Name},
92-
CDIDeviceIDs: []string{cdiID},
92+
CdiDeviceIds: []string{cdiID},
9393
},
9494
},
9595
},
@@ -110,7 +110,7 @@ func (s *fakeDRADriverGRPCServer) NodeUnprepareResources(ctx context.Context, re
110110
if s.unprepareResourcesResponse == nil {
111111
return &drapb.NodeUnprepareResourcesResponse{
112112
Claims: map[string]*drapb.NodeUnprepareResourceResponse{
113-
req.Claims[0].UID: {},
113+
req.Claims[0].Uid: {},
114114
},
115115
}, nil
116116
}
@@ -567,7 +567,7 @@ func TestPrepareResources(t *testing.T) {
567567
PoolName: poolName,
568568
DeviceName: deviceName,
569569
RequestNames: []string{requestName},
570-
CDIDeviceIDs: []string{cdiID},
570+
CdiDeviceIds: []string{cdiID},
571571
},
572572
},
573573
},
@@ -587,7 +587,7 @@ func TestPrepareResources(t *testing.T) {
587587
PoolName: poolName,
588588
DeviceName: deviceName,
589589
RequestNames: []string{requestName},
590-
CDIDeviceIDs: []string{cdiID},
590+
CdiDeviceIds: []string{cdiID},
591591
},
592592
},
593593
},
@@ -615,7 +615,7 @@ func TestPrepareResources(t *testing.T) {
615615
PoolName: poolName,
616616
DeviceName: deviceName,
617617
RequestNames: []string{requestName},
618-
CDIDeviceIDs: []string{cdiID},
618+
CdiDeviceIds: []string{cdiID},
619619
},
620620
},
621621
},
@@ -636,7 +636,7 @@ func TestPrepareResources(t *testing.T) {
636636
PoolName: poolName,
637637
DeviceName: deviceName,
638638
RequestNames: []string{requestName},
639-
CDIDeviceIDs: []string{cdiID},
639+
CdiDeviceIds: []string{cdiID},
640640
},
641641
},
642642
},

pkg/kubelet/cm/dra/plugin/dra_plugin_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import (
4040
type fakeGRPCServer struct {
4141
drapbv1beta1.UnimplementedDRAPluginServer
4242
drahealthv1alpha1.UnimplementedDRAResourceHealthServer
43+
drapbv1.UnsafeDRAPluginServer
4344
}
4445

4546
var _ drapbv1.DRAPluginServer = &fakeGRPCServer{}
@@ -49,7 +50,7 @@ func (f *fakeGRPCServer) NodePrepareResources(ctx context.Context, in *drapbv1.N
4950
Devices: []*drapbv1.Device{
5051
{
5152
RequestNames: []string{"test-request"},
52-
CDIDeviceIDs: []string{"test-cdi-id"},
53+
CdiDeviceIds: []string{"test-cdi-id"},
5354
},
5455
},
5556
}}}, nil
@@ -162,7 +163,7 @@ func TestGRPCConnIsReused(t *testing.T) {
162163
Claims: []*drapbv1.Claim{
163164
{
164165
Namespace: "dummy-namespace",
165-
UID: "dummy-uid",
166+
Uid: "dummy-uid",
166167
Name: "dummy-claim",
167168
},
168169
},

staging/src/k8s.io/dynamic-resource-allocation/kubeletplugin/draplugin.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -838,6 +838,7 @@ func (d *Helper) serializeGRPCIfEnabled() (func(), error) {
838838
// It prevents polluting the public API with these implementation details.
839839
type nodePluginImplementation struct {
840840
*Helper
841+
drapbv1.UnsafeDRAPluginServer
841842
}
842843

843844
// NodePrepareResources implements [drapbv1.NodePrepareResources].
@@ -867,7 +868,7 @@ func (d *nodePluginImplementation) NodePrepareResources(ctx context.Context, req
867868
RequestNames: stripSubrequestNames(result.Requests),
868869
PoolName: result.PoolName,
869870
DeviceName: result.DeviceName,
870-
CDIDeviceIDs: result.CDIDeviceIDs,
871+
CdiDeviceIds: result.CDIDeviceIDs,
871872
}
872873
devices = append(devices, device)
873874
}
@@ -904,7 +905,7 @@ func (d *nodePluginImplementation) getResourceClaims(ctx context.Context, claims
904905
if claim.Status.Allocation == nil {
905906
return resourceClaims, fmt.Errorf("claim %s/%s not allocated", claimReq.Namespace, claimReq.Name)
906907
}
907-
if claim.UID != types.UID(claimReq.UID) {
908+
if claim.UID != types.UID(claimReq.Uid) {
908909
return resourceClaims, fmt.Errorf("claim %s/%s got replaced", claimReq.Namespace, claimReq.Name)
909910
}
910911
resourceClaims = append(resourceClaims, claim)
@@ -922,7 +923,7 @@ func (d *nodePluginImplementation) NodeUnprepareResources(ctx context.Context, r
922923

923924
claims := make([]NamespacedObject, 0, len(req.Claims))
924925
for _, claim := range req.Claims {
925-
claims = append(claims, NamespacedObject{UID: types.UID(claim.UID), NamespacedName: types.NamespacedName{Name: claim.Name, Namespace: claim.Namespace}})
926+
claims = append(claims, NamespacedObject{UID: types.UID(claim.Uid), NamespacedName: types.NamespacedName{Name: claim.Name, Namespace: claim.Namespace}})
926927
}
927928
result, err := d.plugin.UnprepareResourceClaims(ctx, claims)
928929
if err != nil {

staging/src/k8s.io/kubelet/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ godebug default=go1.24
88

99
require (
1010
github.com/emicklei/go-restful/v3 v3.12.2
11-
github.com/gogo/protobuf v1.3.2
1211
github.com/stretchr/testify v1.10.0
1312
go.uber.org/goleak v1.3.0
1413
google.golang.org/grpc v1.72.1
@@ -30,6 +29,7 @@ require (
3029
github.com/davecgh/go-spew v1.1.1 // indirect
3130
github.com/fxamacker/cbor/v2 v2.9.0 // indirect
3231
github.com/go-logr/logr v1.4.2 // indirect
32+
github.com/gogo/protobuf v1.3.2 // indirect
3333
github.com/google/go-cmp v0.7.0 // indirect
3434
github.com/gorilla/websocket v1.5.4-0.20250319132907-e064f32e3674 // indirect
3535
github.com/inconshreveable/mousetrap v1.1.0 // indirect

0 commit comments

Comments
 (0)