diff --git a/cmd/libs/go2idl/go-to-protobuf/protobuf/cmd.go b/cmd/libs/go2idl/go-to-protobuf/protobuf/cmd.go index daac979c1e6..aae64d2bdd8 100644 --- a/cmd/libs/go2idl/go-to-protobuf/protobuf/cmd.go +++ b/cmd/libs/go2idl/go-to-protobuf/protobuf/cmd.go @@ -138,9 +138,6 @@ func Run(g *Generator) { d = d[1:] outputPackage = false } - if strings.Contains(d, "-") { - log.Fatalf("Package names must be valid protobuf package identifiers, which allow only [a-z0-9_]: %s", d) - } name := protoSafePackage(d) parts := strings.SplitN(d, "=", 2) if len(parts) > 1 { diff --git a/cmd/libs/go2idl/go-to-protobuf/protobuf/namer.go b/cmd/libs/go2idl/go-to-protobuf/protobuf/namer.go index 7ae5c614e39..60060d4edf4 100644 --- a/cmd/libs/go2idl/go-to-protobuf/protobuf/namer.go +++ b/cmd/libs/go2idl/go-to-protobuf/protobuf/namer.go @@ -94,7 +94,8 @@ func (n *protobufNamer) GoNameToProtoName(name types.Name) types.Name { } func protoSafePackage(name string) string { - return strings.Replace(name, "/", ".", -1) + pkg := strings.Replace(name, "/", ".", -1) + return strings.Replace(pkg, "-", "_", -1) } type typeNameSet map[types.Name]*protobufPackage diff --git a/cmd/libs/go2idl/go-to-protobuf/protobuf/namer_test.go b/cmd/libs/go2idl/go-to-protobuf/protobuf/namer_test.go new file mode 100644 index 00000000000..0ee71f80beb --- /dev/null +++ b/cmd/libs/go2idl/go-to-protobuf/protobuf/namer_test.go @@ -0,0 +1,50 @@ +/* +Copyright 2016 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 protobuf + +import "testing" + +func TestProtoSafePackage(t *testing.T) { + tests := []struct { + pkg string + expected string + }{ + { + pkg: "foo", + expected: "foo", + }, + { + pkg: "foo/bar", + expected: "foo.bar", + }, + { + pkg: "foo/bar/baz", + expected: "foo.bar.baz", + }, + { + pkg: "foo/bar-baz/x/y-z/q", + expected: "foo.bar_baz.x.y_z.q", + }, + } + + for _, test := range tests { + actual := protoSafePackage(test.pkg) + if e, a := test.expected, actual; e != a { + t.Errorf("%s: expected %s, got %s", test.pkg, e, a) + } + } +} diff --git a/test/test_owners.csv b/test/test_owners.csv index 629b0810ed6..a382790252e 100644 --- a/test/test_owners.csv +++ b/test/test_owners.csv @@ -452,6 +452,7 @@ k8s.io/kubernetes/cmd/kubeadm/app/images,davidopp,1 k8s.io/kubernetes/cmd/kubeadm/app/util,krousey,1 k8s.io/kubernetes/cmd/kubelet/app,hurf,1 k8s.io/kubernetes/cmd/libs/go2idl/client-gen/testoutput/clientset_generated/test_internalclientset/typed/testgroup.k8s.io/unversioned,eparis,1 +k8s.io/kubernetes/cmd/libs/go2idl/go-to-protobuf/protobuf,smarterclayton,0 k8s.io/kubernetes/cmd/libs/go2idl/openapi-gen/generators,davidopp,1 k8s.io/kubernetes/cmd/mungedocs,mwielgus,1 k8s.io/kubernetes/examples,Random-Liu,0