Skip to content

Commit 09df984

Browse files
committed
Remove gogo-protobuf from CRI
Signed-off-by: Sascha Grunert <[email protected]>
1 parent c5b83f7 commit 09df984

28 files changed

+10090
-45179
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright 2017 The Kubernetes Authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
# This script generates `*/api.pb.go` files from protobuf files `*/api.proto`.
18+
19+
set -o errexit
20+
set -o nounset
21+
set -o pipefail
22+
23+
KUBE_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../" && pwd -P)"
24+
25+
source "${KUBE_ROOT}/hack/lib/init.sh"
26+
source "${KUBE_ROOT}/hack/lib/protoc.sh"
27+
source "${KUBE_ROOT}/hack/lib/util.sh"
28+
29+
if [ "$#" == 0 ]; then
30+
echo "usage: $0 <api_dir>..."
31+
exit 1
32+
fi
33+
34+
kube::protoc::check_protoc
35+
36+
for api; do
37+
# This can't use `git ls-files` because it runs in a container without the
38+
# .git dir synced.
39+
protos=()
40+
kube::util::read-array protos < <( \
41+
find "${api}" -type f -name "api.proto")
42+
43+
if [ "${#protos[@]}" == 0 ]; then
44+
echo "ERROR: no 'api.proto' files under '${api}'"
45+
exit 1
46+
fi
47+
48+
for file in "${protos[@]}"; do
49+
dir="$(dirname "${file}")"
50+
kube::protoc::generate_proto_gogo "${dir}"
51+
done
52+
done

hack/lib/protoc.sh

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ PROTOC_VERSION=23.4
3232
# $1: Full path to the directory where the api.proto file is
3333
function kube::protoc::generate_proto() {
3434
kube::golang::setup_env
35-
GOPROXY=off go install k8s.io/code-generator/cmd/go-to-protobuf/protoc-gen-gogo
35+
go -C "${KUBE_ROOT}/hack/tools" install google.golang.org/protobuf/cmd/protoc-gen-go
36+
go -C "${KUBE_ROOT}/hack/tools" install google.golang.org/grpc/cmd/protoc-gen-go-grpc
3637

3738
kube::protoc::check_protoc
3839

@@ -41,6 +42,20 @@ function kube::protoc::generate_proto() {
4142
kube::protoc::format "${package}"
4243
}
4344

45+
# Generates $1/api.pb.go from the protobuf file $1/api.proto
46+
# and formats it correctly
47+
# $1: Full path to the directory where the api.proto file is
48+
function kube::protoc::generate_proto_gogo() {
49+
kube::golang::setup_env
50+
GOPROXY=off go install k8s.io/code-generator/cmd/go-to-protobuf/protoc-gen-gogo
51+
52+
kube::protoc::check_protoc
53+
54+
local package=${1}
55+
kube::protoc::protoc_gogo "${package}"
56+
kube::protoc::format "${package}"
57+
}
58+
4459
# Checks that the current protoc version matches the required version and
4560
# exit 1 if it's not the case
4661
function kube::protoc::check_protoc() {
@@ -55,7 +70,7 @@ function kube::protoc::check_protoc() {
5570

5671
# Generates $1/api.pb.go from the protobuf file $1/api.proto
5772
# $1: Full path to the directory where the api.proto file is
58-
function kube::protoc::protoc() {
73+
function kube::protoc::protoc_gogo() {
5974
local package=${1}
6075
gogopath=$(dirname "$(kube::util::find-binary "protoc-gen-gogo")")
6176

@@ -76,17 +91,36 @@ function kube::protoc::protoc() {
7691
)
7792
}
7893

94+
# Generates $1/api.pb.go from the protobuf file $1/api.proto without using gogo
95+
# $1: Full path to the directory where the api.proto file is
96+
function kube::protoc::protoc() {
97+
local package=${1}
98+
99+
protoc \
100+
--proto_path="$(pwd -P)" \
101+
--proto_path="${KUBE_ROOT}/vendor" \
102+
--proto_path="${KUBE_ROOT}/staging/src" \
103+
--proto_path="${KUBE_ROOT}/third_party/protobuf" \
104+
--go_out=. \
105+
--go_opt=paths=source_relative \
106+
--go-grpc_out=. \
107+
--go-grpc_opt=paths=source_relative \
108+
"${package}"/api.proto
109+
}
110+
79111
# Formats $1/api.pb.go, adds the boilerplate comments and run gofmt on it
80112
# $1: Full path to the directory where the api.proto file is
81113
function kube::protoc::format() {
82114
local package=${1}
83115

84-
# Update boilerplate for the generated file.
85-
cat hack/boilerplate/boilerplate.generatego.txt "${package}/api.pb.go" > tmpfile && mv tmpfile "${package}/api.pb.go"
86-
87116
# Run gofmt to clean up the generated code.
88117
kube::golang::setup_env
89-
gofmt -s -w "${package}/api.pb.go"
118+
119+
# Update boilerplate for the generated files.
120+
for file in "${package}"/api*.pb.go ; do
121+
cat hack/boilerplate/boilerplate.generatego.txt "${file}" > tmpfile && mv tmpfile "${file}"
122+
gofmt -s -w "${file}"
123+
done
90124
}
91125

92126
# Compares the contents of $1 and $2

hack/tools/go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ require (
1313
github.com/vektra/mockery/v2 v2.40.3
1414
go.uber.org/automaxprocs v1.6.0
1515
golang.org/x/mod v0.23.0
16+
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.5.1
17+
google.golang.org/protobuf v1.36.4
1618
gotest.tools/gotestsum v1.12.0
1719
honnef.co/go/tools v0.6.0
1820
k8s.io/publishing-bot v0.5.0
@@ -205,7 +207,6 @@ require (
205207
golang.org/x/term v0.18.0 // indirect
206208
golang.org/x/text v0.22.0 // indirect
207209
golang.org/x/tools v0.30.0 // indirect
208-
google.golang.org/protobuf v1.36.4 // indirect
209210
gopkg.in/ini.v1 v1.67.0 // indirect
210211
gopkg.in/yaml.v2 v2.4.0 // indirect
211212
gopkg.in/yaml.v3 v3.0.1 // indirect

hack/tools/go.sum

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -984,6 +984,9 @@ google.golang.org/genproto v0.0.0-20200618031413-b414f8b61790/go.mod h1:jDfRM7Fc
984984
google.golang.org/genproto v0.0.0-20200729003335-053ba62fc06f/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
985985
google.golang.org/genproto v0.0.0-20200804131852-c06518451d9c/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
986986
google.golang.org/genproto v0.0.0-20200825200019-8632dd797987/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
987+
google.golang.org/genproto v0.0.0-20241118233622-e639e219e697 h1:ToEetK57OidYuqD4Q5w+vfEnPvPpuTwedCNVohYJfNk=
988+
google.golang.org/genproto/googleapis/rpc v0.0.0-20250127172529-29210b9bc287 h1:J1H9f+LEdWAfHcez/4cvaVBox7cOYT+IU6rgqj5x++8=
989+
google.golang.org/genproto/googleapis/rpc v0.0.0-20250127172529-29210b9bc287/go.mod h1:8BS3B93F/U1juMFq9+EDk+qOT5CO1R9IzXxG3PTqiRk=
987990
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
988991
google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38=
989992
google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM=
@@ -996,6 +999,10 @@ google.golang.org/grpc v1.28.0/go.mod h1:rpkK4SK4GF4Ach/+MFLZUBavHOvF2JJB5uozKKa
996999
google.golang.org/grpc v1.29.1/go.mod h1:itym6AZVZYACWQqET3MqgPpjcuV5QH3BxFS3IjizoKk=
9971000
google.golang.org/grpc v1.30.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak=
9981001
google.golang.org/grpc v1.31.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak=
1002+
google.golang.org/grpc v1.70.0 h1:pWFv03aZoHzlRKHWicjsZytKAiYCtNS0dHbXnIdq7jQ=
1003+
google.golang.org/grpc v1.70.0/go.mod h1:ofIJqVKDXx/JiXrwr2IG4/zwdH9txy3IlF40RmcJSQw=
1004+
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.5.1 h1:F29+wU6Ee6qgu9TddPgooOdaqsxTMunOoj8KA5yuS5A=
1005+
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.5.1/go.mod h1:5KF+wpkbTSbGcR9zteSqZV6fqFOWBl4Yde8En8MryZA=
9991006
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
10001007
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
10011008
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=

hack/tools/tools.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,8 @@ import (
4040
// for publishing bot
4141
_ "golang.org/x/mod/modfile"
4242
_ "k8s.io/publishing-bot/cmd/publishing-bot/config"
43+
44+
// protobuf generation
45+
_ "google.golang.org/grpc/cmd/protoc-gen-go-grpc"
46+
_ "google.golang.org/protobuf/cmd/protoc-gen-go"
4347
)

hack/unwanted-dependencies.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,6 @@
154154
"k8s.io/apiserver",
155155
"k8s.io/client-go",
156156
"k8s.io/code-generator",
157-
"k8s.io/cri-api",
158157
"k8s.io/externaljwt",
159158
"k8s.io/kms",
160159
"k8s.io/kube-aggregator",

hack/update-codegen.sh

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -825,9 +825,7 @@ function codegen::subprojects() {
825825
function codegen::protobindings() {
826826
# Each element of this array is a directory containing subdirectories which
827827
# eventually contain a file named "api.proto".
828-
local apis=(
829-
"staging/src/k8s.io/cri-api/pkg/apis/runtime"
830-
828+
local apis_using_gogo=(
831829
"staging/src/k8s.io/kubelet/pkg/apis/podresources"
832830

833831
"staging/src/k8s.io/kubelet/pkg/apis/deviceplugin"
@@ -842,6 +840,10 @@ function codegen::protobindings() {
842840

843841
"staging/src/k8s.io/externaljwt/apis"
844842
)
843+
local apis_using_protoc=(
844+
"staging/src/k8s.io/cri-api/pkg/apis/runtime"
845+
)
846+
local apis=("${apis_using_gogo[@]}" "${apis_using_protoc[@]}")
845847

846848
kube::log::status "Generating protobuf bindings for ${#apis[@]} targets"
847849
if [[ "${DBG_CODEGEN}" == 1 ]]; then
@@ -852,18 +854,20 @@ function codegen::protobindings() {
852854
fi
853855

854856
for api in "${apis[@]}"; do
855-
git_find -z ":(glob)${api}"/'**/api.pb.go' \
857+
git_find -z ":(glob)${api}"/'**/api*.pb.go' \
856858
| xargs -0 rm -f
857859
done
858860

859861
if kube::protoc::check_protoc >/dev/null; then
860-
hack/_update-generated-proto-bindings-dockerized.sh "${apis[@]}"
862+
hack/_update-generated-proto-bindings-gogo-dockerized.sh "${apis_using_gogo[@]}"
863+
hack/_update-generated-proto-bindings-dockerized.sh "${apis_using_protoc[@]}"
861864
else
862865
kube::log::status "protoc ${PROTOC_VERSION} not found (can install with hack/install-protoc.sh); generating containerized..."
863866
# NOTE: All output from this script needs to be copied back to the calling
864867
# source tree. This is managed in kube::build::copy_output in build/common.sh.
865868
# If the output set is changed update that function.
866-
build/run.sh hack/_update-generated-proto-bindings-dockerized.sh "${apis[@]}"
869+
build/run.sh hack/_update-generated-proto-bindings-gogo-dockerized.sh "${apis_using_gogo[@]}"
870+
build/run.sh hack/_update-generated-proto-bindings-dockerized.sh "${apis_using_protoc[@]}"
867871
fi
868872
}
869873

pkg/kubelet/kuberuntime/kuberuntime_container_linux_test.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
"k8s.io/kubernetes/pkg/kubelet/types"
3333

3434
"github.com/google/go-cmp/cmp"
35+
"github.com/google/go-cmp/cmp/cmpopts"
3536
libcontainercgroups "github.com/opencontainers/runc/libcontainer/cgroups"
3637
"github.com/stretchr/testify/assert"
3738
v1 "k8s.io/api/core/v1"
@@ -736,7 +737,11 @@ func TestGenerateLinuxContainerConfigNamespaces(t *testing.T) {
736737
t.Run(tc.name, func(t *testing.T) {
737738
got, err := m.generateLinuxContainerConfig(&tc.pod.Spec.Containers[0], tc.pod, nil, "", tc.target, false)
738739
assert.NoError(t, err)
739-
if diff := cmp.Diff(tc.want, got.SecurityContext.NamespaceOptions); diff != "" {
740+
if diff := cmp.Diff(
741+
tc.want,
742+
got.SecurityContext.NamespaceOptions,
743+
cmpopts.IgnoreUnexported(runtimeapi.NamespaceOption{}),
744+
); diff != "" {
740745
t.Errorf("%v: diff (-want +got):\n%v", t.Name(), diff)
741746
}
742747
})

pkg/kubelet/kuberuntime/kuberuntime_image.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func (m *kubeGenericRuntimeManager) GetImageSize(ctx context.Context, image kube
105105
if resp.Image == nil {
106106
return 0, nil
107107
}
108-
return resp.Image.Size_, nil
108+
return resp.Image.GetSize(), nil
109109
}
110110

111111
// ListImages gets all images currently on the machine.
@@ -132,7 +132,7 @@ func (m *kubeGenericRuntimeManager) ListImages(ctx context.Context) ([]kubeconta
132132

133133
images = append(images, kubecontainer.Image{
134134
ID: img.Id,
135-
Size: int64(img.Size_),
135+
Size: int64(img.GetSize()),
136136
RepoTags: img.RepoTags,
137137
RepoDigests: img.RepoDigests,
138138
Spec: toKubeContainerImageSpec(img),
@@ -166,7 +166,7 @@ func (m *kubeGenericRuntimeManager) ImageStats(ctx context.Context) (*kubecontai
166166
}
167167
stats := &kubecontainer.ImageStats{}
168168
for _, img := range allImages {
169-
stats.TotalStorageBytes += img.Size_
169+
stats.TotalStorageBytes += img.GetSize()
170170
}
171171
return stats, nil
172172
}

pkg/kubelet/kuberuntime/kuberuntime_manager.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1434,7 +1434,7 @@ type imageVolumePulls = map[string]imageVolumePullResult
14341434
// If spec is nil, then err and msg should be set.
14351435
// If err is nil, then spec should be set.
14361436
type imageVolumePullResult struct {
1437-
spec runtimeapi.ImageSpec
1437+
spec *runtimeapi.ImageSpec
14381438
err error
14391439
msg string
14401440
}
@@ -1463,7 +1463,7 @@ func (m *kubeGenericRuntimeManager) toKubeContainerImageVolumes(imageVolumePullR
14631463
continue
14641464
}
14651465

1466-
imageVolumes[v.Name] = &res.spec
1466+
imageVolumes[v.Name] = res.spec
14671467
}
14681468

14691469
if lastErr != nil {
@@ -1502,7 +1502,7 @@ func (m *kubeGenericRuntimeManager) getImageVolumes(ctx context.Context, pod *v1
15021502
}
15031503

15041504
klog.V(4).InfoS("Pulled image", "ref", ref, "pod", klog.KObj(pod))
1505-
res[volume.Name] = imageVolumePullResult{spec: runtimeapi.ImageSpec{
1505+
res[volume.Name] = imageVolumePullResult{spec: &runtimeapi.ImageSpec{
15061506
Image: ref,
15071507
UserSpecifiedImage: volume.Image.Reference,
15081508
RuntimeHandler: podRuntimeHandler,

pkg/kubelet/kuberuntime/kuberuntime_manager_test.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,9 @@ func makeFakePodSandbox(t *testing.T, m *kubeGenericRuntimeManager, template san
158158
Ip: ip,
159159
})
160160
}
161-
podSandBoxStatus.Network.AdditionalIps = additionalPodIPs
161+
if len(additionalPodIPs) > 0 {
162+
podSandBoxStatus.Network.AdditionalIps = additionalPodIPs
163+
}
162164
return podSandBoxStatus
163165

164166
}
@@ -3096,8 +3098,8 @@ func TestToKubeContainerImageVolumes(t *testing.T) {
30963098
"empty volumes": {},
30973099
"multiple volumes": {
30983100
pullResults: imageVolumePulls{
3099-
volume1: imageVolumePullResult{spec: imageSpec1},
3100-
volume2: imageVolumePullResult{spec: imageSpec2},
3101+
volume1: imageVolumePullResult{spec: &imageSpec1},
3102+
volume2: imageVolumePullResult{spec: &imageSpec2},
31013103
},
31023104
container: &v1.Container{
31033105
VolumeMounts: []v1.VolumeMount{
@@ -3112,7 +3114,7 @@ func TestToKubeContainerImageVolumes(t *testing.T) {
31123114
},
31133115
"not matching volume": {
31143116
pullResults: imageVolumePulls{
3115-
"different": imageVolumePullResult{spec: imageSpec1},
3117+
"different": imageVolumePullResult{spec: &imageSpec1},
31163118
},
31173119
container: &v1.Container{
31183120
VolumeMounts: []v1.VolumeMount{{Name: volume1}},
@@ -3171,8 +3173,8 @@ func TestGetImageVolumes(t *testing.T) {
31713173
{Name: volume2, VolumeSource: v1.VolumeSource{Image: &v1.ImageVolumeSource{Reference: image2, PullPolicy: v1.PullAlways}}},
31723174
}}},
31733175
expectedImageVolumePulls: imageVolumePulls{
3174-
volume1: imageVolumePullResult{spec: imageSpec1},
3175-
volume2: imageVolumePullResult{spec: imageSpec2},
3176+
volume1: imageVolumePullResult{spec: &imageSpec1},
3177+
volume2: imageVolumePullResult{spec: &imageSpec2},
31763178
},
31773179
},
31783180
"different than image volumes": {
@@ -3187,7 +3189,7 @@ func TestGetImageVolumes(t *testing.T) {
31873189
{Name: volume2, VolumeSource: v1.VolumeSource{Image: &v1.ImageVolumeSource{Reference: "image", PullPolicy: v1.PullNever}}}, // fails
31883190
}}},
31893191
expectedImageVolumePulls: imageVolumePulls{
3190-
volume1: imageVolumePullResult{spec: imageSpec1},
3192+
volume1: imageVolumePullResult{spec: &imageSpec1},
31913193
volume2: imageVolumePullResult{err: imagetypes.ErrImageNeverPull, msg: `Container image "image" is not present with pull policy of Never`},
31923194
},
31933195
},

0 commit comments

Comments
 (0)