-
Notifications
You must be signed in to change notification settings - Fork 40.9k
Remove gogo from proto bindings (part 1: CRI) #128653
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Copyright 2017 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. | ||
|
||
# This script generates `*/api.pb.go` files from protobuf files `*/api.proto`. | ||
|
||
set -o errexit | ||
set -o nounset | ||
set -o pipefail | ||
|
||
KUBE_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../" && pwd -P)" | ||
|
||
source "${KUBE_ROOT}/hack/lib/init.sh" | ||
source "${KUBE_ROOT}/hack/lib/protoc.sh" | ||
source "${KUBE_ROOT}/hack/lib/util.sh" | ||
|
||
if [ "$#" == 0 ]; then | ||
echo "usage: $0 <api_dir>..." | ||
exit 1 | ||
fi | ||
|
||
kube::protoc::check_protoc | ||
|
||
for api; do | ||
# This can't use `git ls-files` because it runs in a container without the | ||
# .git dir synced. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. xref: #112862 |
||
protos=() | ||
kube::util::read-array protos < <( \ | ||
find "${api}" -type f -name "api.proto") | ||
|
||
if [ "${#protos[@]}" == 0 ]; then | ||
echo "ERROR: no 'api.proto' files under '${api}'" | ||
exit 1 | ||
fi | ||
|
||
for file in "${protos[@]}"; do | ||
dir="$(dirname "${file}")" | ||
kube::protoc::generate_proto_gogo "${dir}" | ||
done | ||
done |
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -32,7 +32,8 @@ PROTOC_VERSION=23.4 | |||
# $1: Full path to the directory where the api.proto file is | ||||
function kube::protoc::generate_proto() { | ||||
kube::golang::setup_env | ||||
GOPROXY=off go install k8s.io/code-generator/cmd/go-to-protobuf/protoc-gen-gogo | ||||
go -C "${KUBE_ROOT}/hack/tools" install google.golang.org/protobuf/cmd/protoc-gen-go | ||||
go -C "${KUBE_ROOT}/hack/tools" install google.golang.org/grpc/cmd/protoc-gen-go-grpc | ||||
|
||||
kube::protoc::check_protoc | ||||
|
||||
|
@@ -41,6 +42,20 @@ function kube::protoc::generate_proto() { | |||
kube::protoc::format "${package}" | ||||
} | ||||
|
||||
# Generates $1/api.pb.go from the protobuf file $1/api.proto | ||||
# and formats it correctly | ||||
# $1: Full path to the directory where the api.proto file is | ||||
function kube::protoc::generate_proto_gogo() { | ||||
kube::golang::setup_env | ||||
GOPROXY=off go install k8s.io/code-generator/cmd/go-to-protobuf/protoc-gen-gogo | ||||
|
||||
kube::protoc::check_protoc | ||||
|
||||
local package=${1} | ||||
kube::protoc::protoc_gogo "${package}" | ||||
kube::protoc::format "${package}" | ||||
} | ||||
|
||||
# Checks that the current protoc version matches the required version and | ||||
# exit 1 if it's not the case | ||||
function kube::protoc::check_protoc() { | ||||
|
@@ -55,7 +70,7 @@ function kube::protoc::check_protoc() { | |||
|
||||
# Generates $1/api.pb.go from the protobuf file $1/api.proto | ||||
# $1: Full path to the directory where the api.proto file is | ||||
function kube::protoc::protoc() { | ||||
function kube::protoc::protoc_gogo() { | ||||
local package=${1} | ||||
gogopath=$(dirname "$(kube::util::find-binary "protoc-gen-gogo")") | ||||
|
||||
|
@@ -76,17 +91,36 @@ function kube::protoc::protoc() { | |||
) | ||||
} | ||||
|
||||
# Generates $1/api.pb.go from the protobuf file $1/api.proto without using gogo | ||||
# $1: Full path to the directory where the api.proto file is | ||||
function kube::protoc::protoc() { | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we have a new pattern where functions not meant to be called directly have a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. like Line 416 in e933a30
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure if I understand that correctly. What we do here is trying to keep the same structure as existing but introducing a parallel implementation (gogo vs non gogo). Do you suggest that we need to refactor them into another location? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @BenTheElder do you have a suggestion how to refactor that or should I follow-up when other proto bindings move over to use non-gogo? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that could be a follow-up that transitions both the kube::protoc::protoc_gogo / kube::protoc::protoc function names to add |
||||
local package=${1} | ||||
|
||||
protoc \ | ||||
--proto_path="$(pwd -P)" \ | ||||
--proto_path="${KUBE_ROOT}/vendor" \ | ||||
--proto_path="${KUBE_ROOT}/staging/src" \ | ||||
--proto_path="${KUBE_ROOT}/third_party/protobuf" \ | ||||
--go_out=. \ | ||||
--go_opt=paths=source_relative \ | ||||
--go-grpc_out=. \ | ||||
--go-grpc_opt=paths=source_relative \ | ||||
"${package}"/api.proto | ||||
} | ||||
|
||||
# Formats $1/api.pb.go, adds the boilerplate comments and run gofmt on it | ||||
# $1: Full path to the directory where the api.proto file is | ||||
function kube::protoc::format() { | ||||
local package=${1} | ||||
|
||||
# Update boilerplate for the generated file. | ||||
cat hack/boilerplate/boilerplate.generatego.txt "${package}/api.pb.go" > tmpfile && mv tmpfile "${package}/api.pb.go" | ||||
|
||||
# Run gofmt to clean up the generated code. | ||||
kube::golang::setup_env | ||||
gofmt -s -w "${package}/api.pb.go" | ||||
|
||||
# Update boilerplate for the generated files. | ||||
for file in "${package}"/api*.pb.go ; do | ||||
saschagrunert marked this conversation as resolved.
Show resolved
Hide resolved
|
||||
cat hack/boilerplate/boilerplate.generatego.txt "${file}" > tmpfile && mv tmpfile "${file}" | ||||
gofmt -s -w "${file}" | ||||
done | ||||
} | ||||
|
||||
# Compares the contents of $1 and $2 | ||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,7 @@ import ( | |
"k8s.io/kubernetes/pkg/kubelet/types" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
"github.com/google/go-cmp/cmp/cmpopts" | ||
libcontainercgroups "github.com/opencontainers/cgroups" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
|
@@ -738,7 +739,11 @@ func TestGenerateLinuxContainerConfigNamespaces(t *testing.T) { | |
t.Run(tc.name, func(t *testing.T) { | ||
got, err := m.generateLinuxContainerConfig(&tc.pod.Spec.Containers[0], tc.pod, nil, "", tc.target, false) | ||
assert.NoError(t, err) | ||
if diff := cmp.Diff(tc.want, got.SecurityContext.NamespaceOptions); diff != "" { | ||
if diff := cmp.Diff( | ||
tc.want, | ||
got.SecurityContext.NamespaceOptions, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is the need for this change a sign that the generated types are changing in ways that will break consumers? |
||
cmpopts.IgnoreUnexported(runtimeapi.NamespaceOption{}), | ||
); diff != "" { | ||
t.Errorf("%v: diff (-want +got):\n%v", t.Name(), diff) | ||
} | ||
}) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -156,7 +156,9 @@ func makeFakePodSandbox(t *testing.T, m *kubeGenericRuntimeManager, template san | |
Ip: ip, | ||
}) | ||
} | ||
podSandBoxStatus.Network.AdditionalIps = additionalPodIPs | ||
if len(additionalPodIPs) > 0 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. curious why this change was required |
||
podSandBoxStatus.Network.AdditionalIps = additionalPodIPs | ||
} | ||
return podSandBoxStatus | ||
|
||
} | ||
|
@@ -3070,8 +3072,8 @@ func TestToKubeContainerImageVolumes(t *testing.T) { | |
"empty volumes": {}, | ||
"multiple volumes": { | ||
pullResults: imageVolumePulls{ | ||
volume1: imageVolumePullResult{spec: imageSpec1}, | ||
volume2: imageVolumePullResult{spec: imageSpec2}, | ||
volume1: imageVolumePullResult{spec: &imageSpec1}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. similar question about why a change from struct to pointer was required, and if that represents changes in the types that will break consumers as well |
||
volume2: imageVolumePullResult{spec: &imageSpec2}, | ||
}, | ||
container: &v1.Container{ | ||
VolumeMounts: []v1.VolumeMount{ | ||
|
@@ -3086,7 +3088,7 @@ func TestToKubeContainerImageVolumes(t *testing.T) { | |
}, | ||
"not matching volume": { | ||
pullResults: imageVolumePulls{ | ||
"different": imageVolumePullResult{spec: imageSpec1}, | ||
"different": imageVolumePullResult{spec: &imageSpec1}, | ||
}, | ||
container: &v1.Container{ | ||
VolumeMounts: []v1.VolumeMount{{Name: volume1}}, | ||
|
@@ -3145,8 +3147,8 @@ func TestGetImageVolumes(t *testing.T) { | |
{Name: volume2, VolumeSource: v1.VolumeSource{Image: &v1.ImageVolumeSource{Reference: image2, PullPolicy: v1.PullAlways}}}, | ||
}}}, | ||
expectedImageVolumePulls: imageVolumePulls{ | ||
volume1: imageVolumePullResult{spec: imageSpec1}, | ||
volume2: imageVolumePullResult{spec: imageSpec2}, | ||
volume1: imageVolumePullResult{spec: &imageSpec1}, | ||
volume2: imageVolumePullResult{spec: &imageSpec2}, | ||
}, | ||
}, | ||
"different than image volumes": { | ||
|
@@ -3161,7 +3163,7 @@ func TestGetImageVolumes(t *testing.T) { | |
{Name: volume2, VolumeSource: v1.VolumeSource{Image: &v1.ImageVolumeSource{Reference: "image", PullPolicy: v1.PullNever}}}, // fails | ||
}}}, | ||
expectedImageVolumePulls: imageVolumePulls{ | ||
volume1: imageVolumePullResult{spec: imageSpec1}, | ||
volume1: imageVolumePullResult{spec: &imageSpec1}, | ||
volume2: imageVolumePullResult{err: imagetypes.ErrImageNeverPull, msg: `Container image "image" is not present with pull policy of Never`}, | ||
}, | ||
}, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any chance we can avoid an entire new script that replicates everything but the
kube::protoc::generate_proto_gogo
call?we wouldn't need hack/_update-generated-proto-bindings-gogo-dockerized.sh if we require telling
_update-generated-proto-bindings-dockerized.sh
which generator to use, like this: