mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 20:24:09 +00:00
Merge pull request #53781 from sttts/sttts-kill-pkg-api-util
Automatic merge from submit-queue (batch tested with PRs 47039, 53681, 53303, 53181, 53781). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. Get rid of pkg/api/util Old helpers we can replace with apimachinery tools.
This commit is contained in:
commit
4548a07c0e
@ -69,7 +69,6 @@ pkg/api/testapi
|
|||||||
pkg/api/testing
|
pkg/api/testing
|
||||||
pkg/api/testing/compat
|
pkg/api/testing/compat
|
||||||
pkg/api/unversioned
|
pkg/api/unversioned
|
||||||
pkg/api/util
|
|
||||||
pkg/api/v1/endpoints
|
pkg/api/v1/endpoints
|
||||||
pkg/api/v1/helper
|
pkg/api/v1/helper
|
||||||
pkg/api/v1/helper/qos
|
pkg/api/v1/helper/qos
|
||||||
|
@ -63,7 +63,6 @@ filegroup(
|
|||||||
"//pkg/api/testapi:all-srcs",
|
"//pkg/api/testapi:all-srcs",
|
||||||
"//pkg/api/testing:all-srcs",
|
"//pkg/api/testing:all-srcs",
|
||||||
"//pkg/api/unversioned:all-srcs",
|
"//pkg/api/unversioned:all-srcs",
|
||||||
"//pkg/api/util:all-srcs",
|
|
||||||
"//pkg/api/v1:all-srcs",
|
"//pkg/api/v1:all-srcs",
|
||||||
"//pkg/api/validation:all-srcs",
|
"//pkg/api/validation:all-srcs",
|
||||||
],
|
],
|
||||||
|
@ -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"],
|
|
||||||
)
|
|
@ -1,3 +0,0 @@
|
|||||||
reviewers:
|
|
||||||
- caesarxuchao
|
|
||||||
- david-mcmahon
|
|
@ -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
|
|
||||||
}
|
|
@ -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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -16,7 +16,6 @@ go_library(
|
|||||||
"//pkg/api:go_default_library",
|
"//pkg/api:go_default_library",
|
||||||
"//pkg/api/helper:go_default_library",
|
"//pkg/api/helper:go_default_library",
|
||||||
"//pkg/api/service:go_default_library",
|
"//pkg/api/service:go_default_library",
|
||||||
"//pkg/api/util:go_default_library",
|
|
||||||
"//pkg/api/v1:go_default_library",
|
"//pkg/api/v1:go_default_library",
|
||||||
"//pkg/api/v1/helper:go_default_library",
|
"//pkg/api/v1/helper:go_default_library",
|
||||||
"//pkg/capabilities:go_default_library",
|
"//pkg/capabilities:go_default_library",
|
||||||
|
@ -25,7 +25,6 @@ import (
|
|||||||
"k8s.io/apimachinery/pkg/util/validation"
|
"k8s.io/apimachinery/pkg/util/validation"
|
||||||
"k8s.io/apimachinery/pkg/util/validation/field"
|
"k8s.io/apimachinery/pkg/util/validation/field"
|
||||||
"k8s.io/kubernetes/pkg/api"
|
"k8s.io/kubernetes/pkg/api"
|
||||||
apiutil "k8s.io/kubernetes/pkg/api/util"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// ValidateEvent makes sure that the event makes sense.
|
// 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
|
// Check whether the kind in groupVersion is scoped at the root of the api hierarchy
|
||||||
func isNamespacedKind(kind, groupVersion string) (bool, error) {
|
func isNamespacedKind(kind, groupVersion string) (bool, error) {
|
||||||
group := apiutil.GetGroup(groupVersion)
|
gv, err := schema.ParseGroupVersion(groupVersion)
|
||||||
g, err := api.Registry.Group(group)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
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 {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,6 @@ go_library(
|
|||||||
"validation.go",
|
"validation.go",
|
||||||
],
|
],
|
||||||
deps = [
|
deps = [
|
||||||
"//pkg/api/util:go_default_library",
|
|
||||||
"//pkg/kubectl/cmd/util/openapi: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/runtime/schema:go_default_library",
|
||||||
"//vendor/k8s.io/apimachinery/pkg/util/errors:go_default_library",
|
"//vendor/k8s.io/apimachinery/pkg/util/errors:go_default_library",
|
||||||
|
@ -24,7 +24,6 @@ import (
|
|||||||
utilerrors "k8s.io/apimachinery/pkg/util/errors"
|
utilerrors "k8s.io/apimachinery/pkg/util/errors"
|
||||||
"k8s.io/apimachinery/pkg/util/json"
|
"k8s.io/apimachinery/pkg/util/json"
|
||||||
"k8s.io/apimachinery/pkg/util/yaml"
|
"k8s.io/apimachinery/pkg/util/yaml"
|
||||||
apiutil "k8s.io/kubernetes/pkg/api/util"
|
|
||||||
"k8s.io/kubernetes/pkg/kubectl/cmd/util/openapi"
|
"k8s.io/kubernetes/pkg/kubectl/cmd/util/openapi"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -112,8 +111,10 @@ func getObjectKind(object interface{}) (schema.GroupVersionKind, error) {
|
|||||||
if _, ok := apiVersion.(string); !ok {
|
if _, ok := apiVersion.(string); !ok {
|
||||||
return schema.GroupVersionKind{}, errors.New("apiVersion isn't string type")
|
return schema.GroupVersionKind{}, errors.New("apiVersion isn't string type")
|
||||||
}
|
}
|
||||||
version := apiutil.GetVersion(apiVersion.(string))
|
gv, err := schema.ParseGroupVersion(apiVersion.(string))
|
||||||
group := apiutil.GetGroup(apiVersion.(string))
|
if err != nil {
|
||||||
|
return schema.GroupVersionKind{}, err
|
||||||
|
}
|
||||||
kind := fields["kind"]
|
kind := fields["kind"]
|
||||||
if kind == nil {
|
if kind == nil {
|
||||||
return schema.GroupVersionKind{}, errors.New("kind not set")
|
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{}, 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
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user