mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-29 14:37:00 +00:00
Merge pull request #44299 from caesarxuchao/move-ref.go
Automatic merge from submit-queue (batch tested with PRs 44406, 41543, 44071, 44374, 44299)
Move pkg/api/ref.go to a subpackage
First commit is #44296. (unfortunately, removing that commit results in conflicts)
This PR moves the pkg/api/ref.go to its own subpackage. It's mostly a mechanic move.
I'll send a few more PRs to make the k8s.io/kubernetes/pkg/api package only contains the code we want in the k8s.io/api repo, then we can run a [script](a0015fd1be (diff-7a2fbb4371972350ee414c6b88aee1c8)
) to cut the new repo.
This commit is contained in:
commit
ab22baf94d
@ -16,16 +16,16 @@ go_library(
|
|||||||
"doc.go",
|
"doc.go",
|
||||||
"field_constants.go",
|
"field_constants.go",
|
||||||
"json.go",
|
"json.go",
|
||||||
"methods.go",
|
"objectreference.go",
|
||||||
"ref.go",
|
|
||||||
"register.go",
|
"register.go",
|
||||||
"resource_helpers.go",
|
"resource_helpers.go",
|
||||||
|
"taint.go",
|
||||||
|
"toleration.go",
|
||||||
"types.go",
|
"types.go",
|
||||||
"zz_generated.deepcopy.go",
|
"zz_generated.deepcopy.go",
|
||||||
],
|
],
|
||||||
tags = ["automanaged"],
|
tags = ["automanaged"],
|
||||||
deps = [
|
deps = [
|
||||||
"//vendor:k8s.io/apimachinery/pkg/api/meta",
|
|
||||||
"//vendor:k8s.io/apimachinery/pkg/api/resource",
|
"//vendor:k8s.io/apimachinery/pkg/api/resource",
|
||||||
"//vendor:k8s.io/apimachinery/pkg/apimachinery/announced",
|
"//vendor:k8s.io/apimachinery/pkg/apimachinery/announced",
|
||||||
"//vendor:k8s.io/apimachinery/pkg/apimachinery/registered",
|
"//vendor:k8s.io/apimachinery/pkg/apimachinery/registered",
|
||||||
@ -44,17 +44,14 @@ go_library(
|
|||||||
go_test(
|
go_test(
|
||||||
name = "go_default_test",
|
name = "go_default_test",
|
||||||
srcs = [
|
srcs = [
|
||||||
"methods_test.go",
|
|
||||||
"ref_test.go",
|
|
||||||
"resource_helpers_test.go",
|
"resource_helpers_test.go",
|
||||||
|
"taint_test.go",
|
||||||
],
|
],
|
||||||
library = ":go_default_library",
|
library = ":go_default_library",
|
||||||
tags = ["automanaged"],
|
tags = ["automanaged"],
|
||||||
deps = [
|
deps = [
|
||||||
"//vendor:k8s.io/apimachinery/pkg/api/resource",
|
"//vendor:k8s.io/apimachinery/pkg/api/resource",
|
||||||
"//vendor:k8s.io/apimachinery/pkg/apis/meta/v1",
|
"//vendor:k8s.io/apimachinery/pkg/apis/meta/v1",
|
||||||
"//vendor:k8s.io/apimachinery/pkg/runtime",
|
|
||||||
"//vendor:k8s.io/apimachinery/pkg/runtime/schema",
|
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -120,6 +117,7 @@ filegroup(
|
|||||||
"//pkg/api/install:all-srcs",
|
"//pkg/api/install:all-srcs",
|
||||||
"//pkg/api/meta:all-srcs",
|
"//pkg/api/meta:all-srcs",
|
||||||
"//pkg/api/pod:all-srcs",
|
"//pkg/api/pod:all-srcs",
|
||||||
|
"//pkg/api/ref:all-srcs",
|
||||||
"//pkg/api/resource:all-srcs",
|
"//pkg/api/resource:all-srcs",
|
||||||
"//pkg/api/service:all-srcs",
|
"//pkg/api/service:all-srcs",
|
||||||
"//pkg/api/testapi:all-srcs",
|
"//pkg/api/testapi:all-srcs",
|
||||||
|
34
pkg/api/objectreference.go
Normal file
34
pkg/api/objectreference.go
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
/*
|
||||||
|
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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
//TODO: consider making these methods functions, because we don't want helper
|
||||||
|
//functions in the k8s.io/api repo.
|
||||||
|
|
||||||
|
package api
|
||||||
|
|
||||||
|
import (
|
||||||
|
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (obj *ObjectReference) SetGroupVersionKind(gvk schema.GroupVersionKind) {
|
||||||
|
obj.APIVersion, obj.Kind = gvk.ToAPIVersionAndKind()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (obj *ObjectReference) GroupVersionKind() schema.GroupVersionKind {
|
||||||
|
return schema.FromAPIVersionAndKind(obj.APIVersion, obj.Kind)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (obj *ObjectReference) GetObjectKind() schema.ObjectKind { return obj }
|
46
pkg/api/ref/BUILD
Normal file
46
pkg/api/ref/BUILD
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
package(default_visibility = ["//visibility:public"])
|
||||||
|
|
||||||
|
licenses(["notice"])
|
||||||
|
|
||||||
|
load(
|
||||||
|
"@io_bazel_rules_go//go:def.bzl",
|
||||||
|
"go_library",
|
||||||
|
"go_test",
|
||||||
|
)
|
||||||
|
|
||||||
|
go_test(
|
||||||
|
name = "go_default_test",
|
||||||
|
srcs = ["ref_test.go"],
|
||||||
|
library = ":go_default_library",
|
||||||
|
tags = ["automanaged"],
|
||||||
|
deps = [
|
||||||
|
"//pkg/api:go_default_library",
|
||||||
|
"//vendor:k8s.io/apimachinery/pkg/apis/meta/v1",
|
||||||
|
"//vendor:k8s.io/apimachinery/pkg/runtime",
|
||||||
|
"//vendor:k8s.io/apimachinery/pkg/runtime/schema",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
go_library(
|
||||||
|
name = "go_default_library",
|
||||||
|
srcs = ["ref.go"],
|
||||||
|
tags = ["automanaged"],
|
||||||
|
deps = [
|
||||||
|
"//pkg/api:go_default_library",
|
||||||
|
"//vendor:k8s.io/apimachinery/pkg/api/meta",
|
||||||
|
"//vendor:k8s.io/apimachinery/pkg/runtime",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
filegroup(
|
||||||
|
name = "package-srcs",
|
||||||
|
srcs = glob(["**"]),
|
||||||
|
tags = ["automanaged"],
|
||||||
|
visibility = ["//visibility:private"],
|
||||||
|
)
|
||||||
|
|
||||||
|
filegroup(
|
||||||
|
name = "all-srcs",
|
||||||
|
srcs = [":package-srcs"],
|
||||||
|
tags = ["automanaged"],
|
||||||
|
)
|
@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package api
|
package ref
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
@ -24,7 +24,7 @@ import (
|
|||||||
|
|
||||||
"k8s.io/apimachinery/pkg/api/meta"
|
"k8s.io/apimachinery/pkg/api/meta"
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
"k8s.io/kubernetes/pkg/api"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -37,11 +37,11 @@ var (
|
|||||||
// object, or an error if the object doesn't follow the conventions
|
// object, or an error if the object doesn't follow the conventions
|
||||||
// that would allow this.
|
// that would allow this.
|
||||||
// TODO: should take a meta.Interface see http://issue.k8s.io/7127
|
// TODO: should take a meta.Interface see http://issue.k8s.io/7127
|
||||||
func GetReference(scheme *runtime.Scheme, obj runtime.Object) (*ObjectReference, error) {
|
func GetReference(scheme *runtime.Scheme, obj runtime.Object) (*api.ObjectReference, error) {
|
||||||
if obj == nil {
|
if obj == nil {
|
||||||
return nil, ErrNilObject
|
return nil, ErrNilObject
|
||||||
}
|
}
|
||||||
if ref, ok := obj.(*ObjectReference); ok {
|
if ref, ok := obj.(*api.ObjectReference); ok {
|
||||||
// Don't make a reference to a reference.
|
// Don't make a reference to a reference.
|
||||||
return ref, nil
|
return ref, nil
|
||||||
}
|
}
|
||||||
@ -93,14 +93,14 @@ func GetReference(scheme *runtime.Scheme, obj runtime.Object) (*ObjectReference,
|
|||||||
|
|
||||||
// only has list metadata
|
// only has list metadata
|
||||||
if objectMeta == nil {
|
if objectMeta == nil {
|
||||||
return &ObjectReference{
|
return &api.ObjectReference{
|
||||||
Kind: kind,
|
Kind: kind,
|
||||||
APIVersion: version,
|
APIVersion: version,
|
||||||
ResourceVersion: listMeta.GetResourceVersion(),
|
ResourceVersion: listMeta.GetResourceVersion(),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return &ObjectReference{
|
return &api.ObjectReference{
|
||||||
Kind: kind,
|
Kind: kind,
|
||||||
APIVersion: version,
|
APIVersion: version,
|
||||||
Name: objectMeta.GetName(),
|
Name: objectMeta.GetName(),
|
||||||
@ -111,7 +111,7 @@ func GetReference(scheme *runtime.Scheme, obj runtime.Object) (*ObjectReference,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetPartialReference is exactly like GetReference, but allows you to set the FieldPath.
|
// GetPartialReference is exactly like GetReference, but allows you to set the FieldPath.
|
||||||
func GetPartialReference(scheme *runtime.Scheme, obj runtime.Object, fieldPath string) (*ObjectReference, error) {
|
func GetPartialReference(scheme *runtime.Scheme, obj runtime.Object, fieldPath string) (*api.ObjectReference, error) {
|
||||||
ref, err := GetReference(scheme, obj)
|
ref, err := GetReference(scheme, obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -119,14 +119,3 @@ func GetPartialReference(scheme *runtime.Scheme, obj runtime.Object, fieldPath s
|
|||||||
ref.FieldPath = fieldPath
|
ref.FieldPath = fieldPath
|
||||||
return ref, nil
|
return ref, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsAnAPIObject allows clients to preemptively get a reference to an API object and pass it to places that
|
|
||||||
// intend only to get a reference to that object. This simplifies the event recording interface.
|
|
||||||
func (obj *ObjectReference) SetGroupVersionKind(gvk schema.GroupVersionKind) {
|
|
||||||
obj.APIVersion, obj.Kind = gvk.ToAPIVersionAndKind()
|
|
||||||
}
|
|
||||||
func (obj *ObjectReference) GroupVersionKind() schema.GroupVersionKind {
|
|
||||||
return schema.FromAPIVersionAndKind(obj.APIVersion, obj.Kind)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (obj *ObjectReference) GetObjectKind() schema.ObjectKind { return obj }
|
|
@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package api
|
package ref
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"reflect"
|
"reflect"
|
||||||
@ -23,6 +23,7 @@ import (
|
|||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||||
|
"k8s.io/kubernetes/pkg/api"
|
||||||
)
|
)
|
||||||
|
|
||||||
type FakeAPIObject struct{}
|
type FakeAPIObject struct{}
|
||||||
@ -41,18 +42,18 @@ func TestGetReference(t *testing.T) {
|
|||||||
// when vendoring kube, if you don't force the set of registered versions (like make test does)
|
// when vendoring kube, if you don't force the set of registered versions (like make test does)
|
||||||
// then you run into trouble because the types aren't registered in the scheme by anything. This does the
|
// then you run into trouble because the types aren't registered in the scheme by anything. This does the
|
||||||
// register manually to allow unit test execution
|
// register manually to allow unit test execution
|
||||||
if _, _, err := Scheme.ObjectKinds(&Pod{}); err != nil {
|
if _, _, err := api.Scheme.ObjectKinds(&api.Pod{}); err != nil {
|
||||||
AddToScheme(Scheme)
|
api.AddToScheme(api.Scheme)
|
||||||
}
|
}
|
||||||
|
|
||||||
table := map[string]struct {
|
table := map[string]struct {
|
||||||
obj runtime.Object
|
obj runtime.Object
|
||||||
ref *ObjectReference
|
ref *api.ObjectReference
|
||||||
fieldPath string
|
fieldPath string
|
||||||
shouldErr bool
|
shouldErr bool
|
||||||
}{
|
}{
|
||||||
"pod": {
|
"pod": {
|
||||||
obj: &Pod{
|
obj: &api.Pod{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: "foo",
|
Name: "foo",
|
||||||
UID: "bar",
|
UID: "bar",
|
||||||
@ -61,7 +62,7 @@ func TestGetReference(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
fieldPath: ".desiredState.containers[0]",
|
fieldPath: ".desiredState.containers[0]",
|
||||||
ref: &ObjectReference{
|
ref: &api.ObjectReference{
|
||||||
Kind: "Pod",
|
Kind: "Pod",
|
||||||
APIVersion: "version1",
|
APIVersion: "version1",
|
||||||
Name: "foo",
|
Name: "foo",
|
||||||
@ -71,13 +72,13 @@ func TestGetReference(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
"serviceList": {
|
"serviceList": {
|
||||||
obj: &ServiceList{
|
obj: &api.ServiceList{
|
||||||
ListMeta: metav1.ListMeta{
|
ListMeta: metav1.ListMeta{
|
||||||
ResourceVersion: "42",
|
ResourceVersion: "42",
|
||||||
SelfLink: "/api/version2/services",
|
SelfLink: "/api/version2/services",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
ref: &ObjectReference{
|
ref: &api.ObjectReference{
|
||||||
Kind: "ServiceList",
|
Kind: "ServiceList",
|
||||||
APIVersion: "version2",
|
APIVersion: "version2",
|
||||||
ResourceVersion: "42",
|
ResourceVersion: "42",
|
||||||
@ -95,7 +96,7 @@ func TestGetReference(t *testing.T) {
|
|||||||
SelfLink: "/custom_prefix/version1/extensions/foo",
|
SelfLink: "/custom_prefix/version1/extensions/foo",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
ref: &ObjectReference{
|
ref: &api.ObjectReference{
|
||||||
Kind: "ExtensionAPIObject",
|
Kind: "ExtensionAPIObject",
|
||||||
APIVersion: "version1",
|
APIVersion: "version1",
|
||||||
Name: "foo",
|
Name: "foo",
|
||||||
@ -104,7 +105,7 @@ func TestGetReference(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
"badSelfLink": {
|
"badSelfLink": {
|
||||||
obj: &ServiceList{
|
obj: &api.ServiceList{
|
||||||
ListMeta: metav1.ListMeta{
|
ListMeta: metav1.ListMeta{
|
||||||
ResourceVersion: "42",
|
ResourceVersion: "42",
|
||||||
SelfLink: "version2/services",
|
SelfLink: "version2/services",
|
||||||
@ -125,7 +126,7 @@ func TestGetReference(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for name, item := range table {
|
for name, item := range table {
|
||||||
ref, err := GetPartialReference(Scheme, item.obj, item.fieldPath)
|
ref, err := GetPartialReference(api.Scheme, item.obj, item.fieldPath)
|
||||||
if e, a := item.shouldErr, (err != nil); e != a {
|
if e, a := item.shouldErr, (err != nil); e != a {
|
||||||
t.Errorf("%v: expected %v, got %v, err %v", name, e, a, err)
|
t.Errorf("%v: expected %v, got %v, err %v", name, e, a, err)
|
||||||
continue
|
continue
|
@ -21,16 +21,6 @@ package api
|
|||||||
|
|
||||||
import "fmt"
|
import "fmt"
|
||||||
|
|
||||||
// MatchToleration checks if the toleration matches tolerationToMatch. Tolerations are unique by <key,effect,operator,value>,
|
|
||||||
// if the two tolerations have same <key,effect,operator,value> combination, regard as they match.
|
|
||||||
// TODO: uniqueness check for tolerations in api validations.
|
|
||||||
func (t *Toleration) MatchToleration(tolerationToMatch *Toleration) bool {
|
|
||||||
return t.Key == tolerationToMatch.Key &&
|
|
||||||
t.Effect == tolerationToMatch.Effect &&
|
|
||||||
t.Operator == tolerationToMatch.Operator &&
|
|
||||||
t.Value == tolerationToMatch.Value
|
|
||||||
}
|
|
||||||
|
|
||||||
// MatchTaint checks if the taint matches taintToMatch. Taints are unique by key:effect,
|
// MatchTaint checks if the taint matches taintToMatch. Taints are unique by key:effect,
|
||||||
// if the two taints have same key:effect, regard as they match.
|
// if the two taints have same key:effect, regard as they match.
|
||||||
func (t *Taint) MatchTaint(taintToMatch Taint) bool {
|
func (t *Taint) MatchTaint(taintToMatch Taint) bool {
|
30
pkg/api/toleration.go
Normal file
30
pkg/api/toleration.go
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
/*
|
||||||
|
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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
//TODO: consider making these methods functions, because we don't want helper
|
||||||
|
//functions in the k8s.io/api repo.
|
||||||
|
|
||||||
|
package api
|
||||||
|
|
||||||
|
// MatchToleration checks if the toleration matches tolerationToMatch. Tolerations are unique by <key,effect,operator,value>,
|
||||||
|
// if the two tolerations have same <key,effect,operator,value> combination, regard as they match.
|
||||||
|
// TODO: uniqueness check for tolerations in api validations.
|
||||||
|
func (t *Toleration) MatchToleration(tolerationToMatch *Toleration) bool {
|
||||||
|
return t.Key == tolerationToMatch.Key &&
|
||||||
|
t.Effect == tolerationToMatch.Effect &&
|
||||||
|
t.Operator == tolerationToMatch.Operator &&
|
||||||
|
t.Value == tolerationToMatch.Value
|
||||||
|
}
|
@ -38,6 +38,7 @@ go_library(
|
|||||||
tags = ["automanaged"],
|
tags = ["automanaged"],
|
||||||
deps = [
|
deps = [
|
||||||
"//pkg/api:go_default_library",
|
"//pkg/api:go_default_library",
|
||||||
|
"//pkg/api/ref:go_default_library",
|
||||||
"//pkg/api/v1:go_default_library",
|
"//pkg/api/v1:go_default_library",
|
||||||
"//pkg/client/clientset_generated/internalclientset/scheme:go_default_library",
|
"//pkg/client/clientset_generated/internalclientset/scheme:go_default_library",
|
||||||
"//vendor:k8s.io/apimachinery/pkg/apis/meta/v1",
|
"//vendor:k8s.io/apimachinery/pkg/apis/meta/v1",
|
||||||
|
@ -24,6 +24,7 @@ import (
|
|||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
"k8s.io/apimachinery/pkg/types"
|
"k8s.io/apimachinery/pkg/types"
|
||||||
"k8s.io/kubernetes/pkg/api"
|
"k8s.io/kubernetes/pkg/api"
|
||||||
|
"k8s.io/kubernetes/pkg/api/ref"
|
||||||
"k8s.io/kubernetes/pkg/api/v1"
|
"k8s.io/kubernetes/pkg/api/v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -100,7 +101,7 @@ func (e *events) PatchWithEventNamespace(incompleteEvent *api.Event, data []byte
|
|||||||
// object must match this event's client namespace unless the event client
|
// object must match this event's client namespace unless the event client
|
||||||
// was made with the "" namespace.
|
// was made with the "" namespace.
|
||||||
func (e *events) Search(scheme *runtime.Scheme, objOrRef runtime.Object) (*api.EventList, error) {
|
func (e *events) Search(scheme *runtime.Scheme, objOrRef runtime.Object) (*api.EventList, error) {
|
||||||
ref, err := api.GetReference(scheme, objOrRef)
|
ref, err := ref.GetReference(scheme, objOrRef)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -195,6 +195,7 @@ go_test(
|
|||||||
deps = [
|
deps = [
|
||||||
"//pkg/api:go_default_library",
|
"//pkg/api:go_default_library",
|
||||||
"//pkg/api/annotations:go_default_library",
|
"//pkg/api/annotations:go_default_library",
|
||||||
|
"//pkg/api/ref:go_default_library",
|
||||||
"//pkg/api/testapi:go_default_library",
|
"//pkg/api/testapi:go_default_library",
|
||||||
"//pkg/api/testing:go_default_library",
|
"//pkg/api/testing:go_default_library",
|
||||||
"//pkg/api/unversioned:go_default_library",
|
"//pkg/api/unversioned:go_default_library",
|
||||||
|
@ -41,6 +41,7 @@ import (
|
|||||||
"k8s.io/apimachinery/pkg/util/wait"
|
"k8s.io/apimachinery/pkg/util/wait"
|
||||||
"k8s.io/client-go/rest/fake"
|
"k8s.io/client-go/rest/fake"
|
||||||
"k8s.io/kubernetes/pkg/api"
|
"k8s.io/kubernetes/pkg/api"
|
||||||
|
"k8s.io/kubernetes/pkg/api/ref"
|
||||||
"k8s.io/kubernetes/pkg/api/testapi"
|
"k8s.io/kubernetes/pkg/api/testapi"
|
||||||
"k8s.io/kubernetes/pkg/apis/batch"
|
"k8s.io/kubernetes/pkg/apis/batch"
|
||||||
"k8s.io/kubernetes/pkg/apis/extensions"
|
"k8s.io/kubernetes/pkg/apis/extensions"
|
||||||
@ -795,7 +796,7 @@ func (m *MyReq) isFor(method string, path string) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func refJson(t *testing.T, o runtime.Object) string {
|
func refJson(t *testing.T, o runtime.Object) string {
|
||||||
ref, err := api.GetReference(api.Scheme, o)
|
ref, err := ref.GetReference(api.Scheme, o)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -63,6 +63,7 @@ go_library(
|
|||||||
"//pkg/api/annotations:go_default_library",
|
"//pkg/api/annotations:go_default_library",
|
||||||
"//pkg/api/events:go_default_library",
|
"//pkg/api/events:go_default_library",
|
||||||
"//pkg/api/helper:go_default_library",
|
"//pkg/api/helper:go_default_library",
|
||||||
|
"//pkg/api/ref:go_default_library",
|
||||||
"//pkg/apis/apps:go_default_library",
|
"//pkg/apis/apps:go_default_library",
|
||||||
"//pkg/apis/autoscaling:go_default_library",
|
"//pkg/apis/autoscaling:go_default_library",
|
||||||
"//pkg/apis/batch:go_default_library",
|
"//pkg/apis/batch:go_default_library",
|
||||||
|
@ -48,6 +48,7 @@ import (
|
|||||||
"k8s.io/kubernetes/pkg/api/annotations"
|
"k8s.io/kubernetes/pkg/api/annotations"
|
||||||
"k8s.io/kubernetes/pkg/api/events"
|
"k8s.io/kubernetes/pkg/api/events"
|
||||||
"k8s.io/kubernetes/pkg/api/helper"
|
"k8s.io/kubernetes/pkg/api/helper"
|
||||||
|
"k8s.io/kubernetes/pkg/api/ref"
|
||||||
"k8s.io/kubernetes/pkg/apis/apps"
|
"k8s.io/kubernetes/pkg/apis/apps"
|
||||||
"k8s.io/kubernetes/pkg/apis/autoscaling"
|
"k8s.io/kubernetes/pkg/apis/autoscaling"
|
||||||
"k8s.io/kubernetes/pkg/apis/batch"
|
"k8s.io/kubernetes/pkg/apis/batch"
|
||||||
@ -521,7 +522,7 @@ func (d *PodDescriber) Describe(namespace, name string, describerSettings printe
|
|||||||
|
|
||||||
var events *api.EventList
|
var events *api.EventList
|
||||||
if describerSettings.ShowEvents {
|
if describerSettings.ShowEvents {
|
||||||
if ref, err := api.GetReference(api.Scheme, pod); err != nil {
|
if ref, err := ref.GetReference(api.Scheme, pod); err != nil {
|
||||||
glog.Errorf("Unable to construct reference to '%#v': %v", pod, err)
|
glog.Errorf("Unable to construct reference to '%#v': %v", pod, err)
|
||||||
} else {
|
} else {
|
||||||
ref.Kind = ""
|
ref.Kind = ""
|
||||||
@ -2033,7 +2034,7 @@ func (d *NodeDescriber) Describe(namespace, name string, describerSettings print
|
|||||||
|
|
||||||
var events *api.EventList
|
var events *api.EventList
|
||||||
if describerSettings.ShowEvents {
|
if describerSettings.ShowEvents {
|
||||||
if ref, err := api.GetReference(api.Scheme, node); err != nil {
|
if ref, err := ref.GetReference(api.Scheme, node); err != nil {
|
||||||
glog.Errorf("Unable to construct reference to '%#v': %v", node, err)
|
glog.Errorf("Unable to construct reference to '%#v': %v", node, err)
|
||||||
} else {
|
} else {
|
||||||
// TODO: We haven't decided the namespace for Node object yet.
|
// TODO: We haven't decided the namespace for Node object yet.
|
||||||
|
@ -411,7 +411,7 @@ func (proxier *Proxier) OnServiceUpdate(services []*api.Service) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: should this just be api.GetReference?
|
// TODO: should this just be ref.GetReference?
|
||||||
svcGVK := service.GetObjectKind().GroupVersionKind()
|
svcGVK := service.GetObjectKind().GroupVersionKind()
|
||||||
svcRef := api.ObjectReference{
|
svcRef := api.ObjectReference{
|
||||||
Kind: svcGVK.Kind,
|
Kind: svcGVK.Kind,
|
||||||
|
@ -33,6 +33,7 @@ go_library(
|
|||||||
tags = ["automanaged"],
|
tags = ["automanaged"],
|
||||||
deps = [
|
deps = [
|
||||||
"//pkg/api:go_default_library",
|
"//pkg/api:go_default_library",
|
||||||
|
"//pkg/api/ref:go_default_library",
|
||||||
"//pkg/apis/settings:go_default_library",
|
"//pkg/apis/settings:go_default_library",
|
||||||
"//pkg/client/clientset_generated/internalclientset:go_default_library",
|
"//pkg/client/clientset_generated/internalclientset:go_default_library",
|
||||||
"//pkg/client/informers/informers_generated/internalversion:go_default_library",
|
"//pkg/client/informers/informers_generated/internalversion:go_default_library",
|
||||||
|
@ -28,6 +28,7 @@ import (
|
|||||||
"k8s.io/apimachinery/pkg/labels"
|
"k8s.io/apimachinery/pkg/labels"
|
||||||
"k8s.io/apiserver/pkg/admission"
|
"k8s.io/apiserver/pkg/admission"
|
||||||
"k8s.io/kubernetes/pkg/api"
|
"k8s.io/kubernetes/pkg/api"
|
||||||
|
"k8s.io/kubernetes/pkg/api/ref"
|
||||||
"k8s.io/kubernetes/pkg/apis/settings"
|
"k8s.io/kubernetes/pkg/apis/settings"
|
||||||
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
|
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
|
||||||
informers "k8s.io/kubernetes/pkg/client/informers/informers_generated/internalversion"
|
informers "k8s.io/kubernetes/pkg/client/informers/informers_generated/internalversion"
|
||||||
@ -298,7 +299,7 @@ func mergeVolumes(pip *settings.PodPreset, original []api.Volume) ([]api.Volume,
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *podPresetPlugin) addEvent(pod *api.Pod, pip *settings.PodPreset, message string) {
|
func (c *podPresetPlugin) addEvent(pod *api.Pod, pip *settings.PodPreset, message string) {
|
||||||
ref, err := api.GetReference(api.Scheme, pod)
|
ref, err := ref.GetReference(api.Scheme, pod)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Errorf("pip %s: get reference for pod %s failed: %v", pip.GetName(), pod.GetName(), err)
|
glog.Errorf("pip %s: get reference for pod %s failed: %v", pip.GetName(), pod.GetName(), err)
|
||||||
return
|
return
|
||||||
|
34
staging/src/k8s.io/client-go/pkg/api/objectreference.go
Normal file
34
staging/src/k8s.io/client-go/pkg/api/objectreference.go
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
/*
|
||||||
|
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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
//TODO: consider making these methods functions, because we don't want helper
|
||||||
|
//functions in the k8s.io/api repo.
|
||||||
|
|
||||||
|
package api
|
||||||
|
|
||||||
|
import (
|
||||||
|
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (obj *ObjectReference) SetGroupVersionKind(gvk schema.GroupVersionKind) {
|
||||||
|
obj.APIVersion, obj.Kind = gvk.ToAPIVersionAndKind()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (obj *ObjectReference) GroupVersionKind() schema.GroupVersionKind {
|
||||||
|
return schema.FromAPIVersionAndKind(obj.APIVersion, obj.Kind)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (obj *ObjectReference) GetObjectKind() schema.ObjectKind { return obj }
|
@ -1,132 +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 api
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
"net/url"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"k8s.io/apimachinery/pkg/api/meta"
|
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
|
||||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
// Errors that could be returned by GetReference.
|
|
||||||
ErrNilObject = errors.New("can't reference a nil object")
|
|
||||||
ErrNoSelfLink = errors.New("selfLink was empty, can't make reference")
|
|
||||||
)
|
|
||||||
|
|
||||||
// GetReference returns an ObjectReference which refers to the given
|
|
||||||
// object, or an error if the object doesn't follow the conventions
|
|
||||||
// that would allow this.
|
|
||||||
// TODO: should take a meta.Interface see http://issue.k8s.io/7127
|
|
||||||
func GetReference(scheme *runtime.Scheme, obj runtime.Object) (*ObjectReference, error) {
|
|
||||||
if obj == nil {
|
|
||||||
return nil, ErrNilObject
|
|
||||||
}
|
|
||||||
if ref, ok := obj.(*ObjectReference); ok {
|
|
||||||
// Don't make a reference to a reference.
|
|
||||||
return ref, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
gvk := obj.GetObjectKind().GroupVersionKind()
|
|
||||||
|
|
||||||
// if the object referenced is actually persisted, we can just get kind from meta
|
|
||||||
// if we are building an object reference to something not yet persisted, we should fallback to scheme
|
|
||||||
kind := gvk.Kind
|
|
||||||
if len(kind) == 0 {
|
|
||||||
// TODO: this is wrong
|
|
||||||
gvks, _, err := scheme.ObjectKinds(obj)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
kind = gvks[0].Kind
|
|
||||||
}
|
|
||||||
|
|
||||||
// An object that implements only List has enough metadata to build a reference
|
|
||||||
var listMeta meta.List
|
|
||||||
objectMeta, err := meta.Accessor(obj)
|
|
||||||
if err != nil {
|
|
||||||
listMeta, err = meta.ListAccessor(obj)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
listMeta = objectMeta
|
|
||||||
}
|
|
||||||
|
|
||||||
// if the object referenced is actually persisted, we can also get version from meta
|
|
||||||
version := gvk.GroupVersion().String()
|
|
||||||
if len(version) == 0 {
|
|
||||||
selfLink := listMeta.GetSelfLink()
|
|
||||||
if len(selfLink) == 0 {
|
|
||||||
return nil, ErrNoSelfLink
|
|
||||||
}
|
|
||||||
selfLinkUrl, err := url.Parse(selfLink)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
// example paths: /<prefix>/<version>/*
|
|
||||||
parts := strings.Split(selfLinkUrl.Path, "/")
|
|
||||||
if len(parts) < 3 {
|
|
||||||
return nil, fmt.Errorf("unexpected self link format: '%v'; got version '%v'", selfLink, version)
|
|
||||||
}
|
|
||||||
version = parts[2]
|
|
||||||
}
|
|
||||||
|
|
||||||
// only has list metadata
|
|
||||||
if objectMeta == nil {
|
|
||||||
return &ObjectReference{
|
|
||||||
Kind: kind,
|
|
||||||
APIVersion: version,
|
|
||||||
ResourceVersion: listMeta.GetResourceVersion(),
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return &ObjectReference{
|
|
||||||
Kind: kind,
|
|
||||||
APIVersion: version,
|
|
||||||
Name: objectMeta.GetName(),
|
|
||||||
Namespace: objectMeta.GetNamespace(),
|
|
||||||
UID: objectMeta.GetUID(),
|
|
||||||
ResourceVersion: objectMeta.GetResourceVersion(),
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetPartialReference is exactly like GetReference, but allows you to set the FieldPath.
|
|
||||||
func GetPartialReference(scheme *runtime.Scheme, obj runtime.Object, fieldPath string) (*ObjectReference, error) {
|
|
||||||
ref, err := GetReference(scheme, obj)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
ref.FieldPath = fieldPath
|
|
||||||
return ref, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// IsAnAPIObject allows clients to preemptively get a reference to an API object and pass it to places that
|
|
||||||
// intend only to get a reference to that object. This simplifies the event recording interface.
|
|
||||||
func (obj *ObjectReference) SetGroupVersionKind(gvk schema.GroupVersionKind) {
|
|
||||||
obj.APIVersion, obj.Kind = gvk.ToAPIVersionAndKind()
|
|
||||||
}
|
|
||||||
func (obj *ObjectReference) GroupVersionKind() schema.GroupVersionKind {
|
|
||||||
return schema.FromAPIVersionAndKind(obj.APIVersion, obj.Kind)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (obj *ObjectReference) GetObjectKind() schema.ObjectKind { return obj }
|
|
@ -21,16 +21,6 @@ package api
|
|||||||
|
|
||||||
import "fmt"
|
import "fmt"
|
||||||
|
|
||||||
// MatchToleration checks if the toleration matches tolerationToMatch. Tolerations are unique by <key,effect,operator,value>,
|
|
||||||
// if the two tolerations have same <key,effect,operator,value> combination, regard as they match.
|
|
||||||
// TODO: uniqueness check for tolerations in api validations.
|
|
||||||
func (t *Toleration) MatchToleration(tolerationToMatch *Toleration) bool {
|
|
||||||
return t.Key == tolerationToMatch.Key &&
|
|
||||||
t.Effect == tolerationToMatch.Effect &&
|
|
||||||
t.Operator == tolerationToMatch.Operator &&
|
|
||||||
t.Value == tolerationToMatch.Value
|
|
||||||
}
|
|
||||||
|
|
||||||
// MatchTaint checks if the taint matches taintToMatch. Taints are unique by key:effect,
|
// MatchTaint checks if the taint matches taintToMatch. Taints are unique by key:effect,
|
||||||
// if the two taints have same key:effect, regard as they match.
|
// if the two taints have same key:effect, regard as they match.
|
||||||
func (t *Taint) MatchTaint(taintToMatch Taint) bool {
|
func (t *Taint) MatchTaint(taintToMatch Taint) bool {
|
30
staging/src/k8s.io/client-go/pkg/api/toleration.go
Normal file
30
staging/src/k8s.io/client-go/pkg/api/toleration.go
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
/*
|
||||||
|
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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
//TODO: consider making these methods functions, because we don't want helper
|
||||||
|
//functions in the k8s.io/api repo.
|
||||||
|
|
||||||
|
package api
|
||||||
|
|
||||||
|
// MatchToleration checks if the toleration matches tolerationToMatch. Tolerations are unique by <key,effect,operator,value>,
|
||||||
|
// if the two tolerations have same <key,effect,operator,value> combination, regard as they match.
|
||||||
|
// TODO: uniqueness check for tolerations in api validations.
|
||||||
|
func (t *Toleration) MatchToleration(tolerationToMatch *Toleration) bool {
|
||||||
|
return t.Key == tolerationToMatch.Key &&
|
||||||
|
t.Effect == tolerationToMatch.Effect &&
|
||||||
|
t.Operator == tolerationToMatch.Operator &&
|
||||||
|
t.Value == tolerationToMatch.Value
|
||||||
|
}
|
6
vendor/BUILD
vendored
6
vendor/BUILD
vendored
@ -13903,16 +13903,16 @@ go_library(
|
|||||||
"k8s.io/client-go/pkg/api/doc.go",
|
"k8s.io/client-go/pkg/api/doc.go",
|
||||||
"k8s.io/client-go/pkg/api/field_constants.go",
|
"k8s.io/client-go/pkg/api/field_constants.go",
|
||||||
"k8s.io/client-go/pkg/api/json.go",
|
"k8s.io/client-go/pkg/api/json.go",
|
||||||
"k8s.io/client-go/pkg/api/methods.go",
|
"k8s.io/client-go/pkg/api/objectreference.go",
|
||||||
"k8s.io/client-go/pkg/api/ref.go",
|
|
||||||
"k8s.io/client-go/pkg/api/register.go",
|
"k8s.io/client-go/pkg/api/register.go",
|
||||||
"k8s.io/client-go/pkg/api/resource_helpers.go",
|
"k8s.io/client-go/pkg/api/resource_helpers.go",
|
||||||
|
"k8s.io/client-go/pkg/api/taint.go",
|
||||||
|
"k8s.io/client-go/pkg/api/toleration.go",
|
||||||
"k8s.io/client-go/pkg/api/types.go",
|
"k8s.io/client-go/pkg/api/types.go",
|
||||||
"k8s.io/client-go/pkg/api/zz_generated.deepcopy.go",
|
"k8s.io/client-go/pkg/api/zz_generated.deepcopy.go",
|
||||||
],
|
],
|
||||||
tags = ["automanaged"],
|
tags = ["automanaged"],
|
||||||
deps = [
|
deps = [
|
||||||
"//vendor:k8s.io/apimachinery/pkg/api/meta",
|
|
||||||
"//vendor:k8s.io/apimachinery/pkg/api/resource",
|
"//vendor:k8s.io/apimachinery/pkg/api/resource",
|
||||||
"//vendor:k8s.io/apimachinery/pkg/apimachinery/announced",
|
"//vendor:k8s.io/apimachinery/pkg/apimachinery/announced",
|
||||||
"//vendor:k8s.io/apimachinery/pkg/apimachinery/registered",
|
"//vendor:k8s.io/apimachinery/pkg/apimachinery/registered",
|
||||||
|
Loading…
Reference in New Issue
Block a user