diff --git a/hack/.golint_failures b/hack/.golint_failures index 458555f2f07..dd074d20ef6 100644 --- a/hack/.golint_failures +++ b/hack/.golint_failures @@ -69,7 +69,6 @@ pkg/api/testapi pkg/api/testing pkg/api/testing/compat pkg/api/unversioned -pkg/api/util pkg/api/v1/endpoints pkg/api/v1/helper pkg/api/v1/helper/qos diff --git a/pkg/api/BUILD b/pkg/api/BUILD index 780b758ea4f..66e8a1da323 100644 --- a/pkg/api/BUILD +++ b/pkg/api/BUILD @@ -63,7 +63,6 @@ filegroup( "//pkg/api/testapi:all-srcs", "//pkg/api/testing:all-srcs", "//pkg/api/unversioned:all-srcs", - "//pkg/api/util:all-srcs", "//pkg/api/v1:all-srcs", "//pkg/api/validation:all-srcs", ], diff --git a/pkg/api/util/BUILD b/pkg/api/util/BUILD deleted file mode 100644 index ae59f2f0ea9..00000000000 --- a/pkg/api/util/BUILD +++ /dev/null @@ -1,31 +0,0 @@ -package(default_visibility = ["//visibility:public"]) - -load( - "@io_bazel_rules_go//go:def.bzl", - "go_library", - "go_test", -) - -go_library( - name = "go_default_library", - srcs = ["group_version.go"], -) - -go_test( - name = "go_default_test", - srcs = ["group_version_test.go"], - library = ":go_default_library", -) - -filegroup( - name = "package-srcs", - srcs = glob(["**"]), - tags = ["automanaged"], - visibility = ["//visibility:private"], -) - -filegroup( - name = "all-srcs", - srcs = [":package-srcs"], - tags = ["automanaged"], -) diff --git a/pkg/api/util/OWNERS b/pkg/api/util/OWNERS deleted file mode 100755 index 18cdb2005a9..00000000000 --- a/pkg/api/util/OWNERS +++ /dev/null @@ -1,3 +0,0 @@ -reviewers: -- caesarxuchao -- david-mcmahon diff --git a/pkg/api/util/group_version.go b/pkg/api/util/group_version.go deleted file mode 100644 index fea2f17f811..00000000000 --- a/pkg/api/util/group_version.go +++ /dev/null @@ -1,48 +0,0 @@ -/* -Copyright 2015 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. -*/ - -// TODO: This GetVersion/GetGroup arrangement is temporary and will be replaced -// with a GroupAndVersion type. -package util - -import "strings" - -func GetVersion(groupVersion string) string { - s := strings.Split(groupVersion, "/") - if len(s) != 2 { - // e.g. return "v1" for groupVersion="v1" - return s[len(s)-1] - } - return s[1] -} - -func GetGroup(groupVersion string) string { - s := strings.Split(groupVersion, "/") - if len(s) == 1 { - // e.g. return "" for groupVersion="v1" - return "" - } - return s[0] -} - -// GetGroupVersion returns the "group/version". It returns "version" is if group -// is empty. It returns "group/" if version is empty. -func GetGroupVersion(group, version string) string { - if len(group) == 0 { - return version - } - return group + "/" + version -} diff --git a/pkg/api/util/group_version_test.go b/pkg/api/util/group_version_test.go deleted file mode 100644 index 5975305a26a..00000000000 --- a/pkg/api/util/group_version_test.go +++ /dev/null @@ -1,93 +0,0 @@ -/* -Copyright 2014 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 util - -import "testing" - -func TestGetVersion(t *testing.T) { - testCases := []struct { - groupVersion string - output string - }{ - { - "v1", - "v1", - }, - { - "extensions/v1beta1", - "v1beta1", - }, - } - for _, test := range testCases { - actual := GetVersion(test.groupVersion) - if test.output != actual { - t.Errorf("expect version: %s, got: %s\n", test.output, actual) - } - } -} - -func TestGetGroup(t *testing.T) { - testCases := []struct { - groupVersion string - output string - }{ - { - "v1", - "", - }, - { - "extensions/v1beta1", - "extensions", - }, - } - for _, test := range testCases { - actual := GetGroup(test.groupVersion) - if test.output != actual { - t.Errorf("expect version: %s, got: %s\n", test.output, actual) - } - } -} - -func TestGetGroupVersion(t *testing.T) { - testCases := []struct { - group string - version string - output string - }{ - { - "", - "v1", - "v1", - }, - { - "extensions", - "", - "extensions/", - }, - { - "extensions", - "v1beta1", - "extensions/v1beta1", - }, - } - for _, test := range testCases { - actual := GetGroupVersion(test.group, test.version) - if test.output != actual { - t.Errorf("expect version: %s, got: %s\n", test.output, actual) - } - } -} diff --git a/pkg/api/validation/BUILD b/pkg/api/validation/BUILD index 8107e7f45d1..e0333f1a525 100644 --- a/pkg/api/validation/BUILD +++ b/pkg/api/validation/BUILD @@ -16,7 +16,6 @@ go_library( "//pkg/api:go_default_library", "//pkg/api/helper:go_default_library", "//pkg/api/service:go_default_library", - "//pkg/api/util:go_default_library", "//pkg/api/v1:go_default_library", "//pkg/api/v1/helper:go_default_library", "//pkg/capabilities:go_default_library", diff --git a/pkg/api/validation/events.go b/pkg/api/validation/events.go index a255f58e2b9..890a6cce4f7 100644 --- a/pkg/api/validation/events.go +++ b/pkg/api/validation/events.go @@ -25,7 +25,6 @@ import ( "k8s.io/apimachinery/pkg/util/validation" "k8s.io/apimachinery/pkg/util/validation/field" "k8s.io/kubernetes/pkg/api" - apiutil "k8s.io/kubernetes/pkg/api/util" ) // ValidateEvent makes sure that the event makes sense. @@ -63,12 +62,16 @@ func ValidateEvent(event *api.Event) field.ErrorList { // Check whether the kind in groupVersion is scoped at the root of the api hierarchy func isNamespacedKind(kind, groupVersion string) (bool, error) { - group := apiutil.GetGroup(groupVersion) - g, err := api.Registry.Group(group) + gv, err := schema.ParseGroupVersion(groupVersion) if err != nil { return false, err } - restMapping, err := g.RESTMapper.RESTMapping(schema.GroupKind{Group: group, Kind: kind}, apiutil.GetVersion(groupVersion)) + g, err := api.Registry.Group(gv.Group) + if err != nil { + return false, err + } + + restMapping, err := g.RESTMapper.RESTMapping(schema.GroupKind{Group: gv.Group, Kind: kind}, gv.Version) if err != nil { return false, err } diff --git a/pkg/kubectl/cmd/util/openapi/validation/BUILD b/pkg/kubectl/cmd/util/openapi/validation/BUILD index e59b56ed7fd..9c77065ecc1 100644 --- a/pkg/kubectl/cmd/util/openapi/validation/BUILD +++ b/pkg/kubectl/cmd/util/openapi/validation/BUILD @@ -14,7 +14,6 @@ go_library( "validation.go", ], deps = [ - "//pkg/api/util:go_default_library", "//pkg/kubectl/cmd/util/openapi:go_default_library", "//vendor/k8s.io/apimachinery/pkg/runtime/schema:go_default_library", "//vendor/k8s.io/apimachinery/pkg/util/errors:go_default_library", diff --git a/pkg/kubectl/cmd/util/openapi/validation/validation.go b/pkg/kubectl/cmd/util/openapi/validation/validation.go index c9e0be050ab..212012293fc 100644 --- a/pkg/kubectl/cmd/util/openapi/validation/validation.go +++ b/pkg/kubectl/cmd/util/openapi/validation/validation.go @@ -24,7 +24,6 @@ import ( utilerrors "k8s.io/apimachinery/pkg/util/errors" "k8s.io/apimachinery/pkg/util/json" "k8s.io/apimachinery/pkg/util/yaml" - apiutil "k8s.io/kubernetes/pkg/api/util" "k8s.io/kubernetes/pkg/kubectl/cmd/util/openapi" ) @@ -112,8 +111,10 @@ func getObjectKind(object interface{}) (schema.GroupVersionKind, error) { if _, ok := apiVersion.(string); !ok { return schema.GroupVersionKind{}, errors.New("apiVersion isn't string type") } - version := apiutil.GetVersion(apiVersion.(string)) - group := apiutil.GetGroup(apiVersion.(string)) + gv, err := schema.ParseGroupVersion(apiVersion.(string)) + if err != nil { + return schema.GroupVersionKind{}, err + } kind := fields["kind"] if kind == nil { return schema.GroupVersionKind{}, errors.New("kind not set") @@ -122,5 +123,5 @@ func getObjectKind(object interface{}) (schema.GroupVersionKind, error) { return schema.GroupVersionKind{}, errors.New("kind isn't string type") } - return schema.GroupVersionKind{Group: group, Version: version, Kind: kind.(string)}, nil + return schema.GroupVersionKind{Group: gv.Group, Version: gv.Version, Kind: kind.(string)}, nil }