mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-28 05:57:25 +00:00
remove apimachinery's dependency on k8s.io/api
This commit is contained in:
parent
40be152c95
commit
c6bfbaef23
@ -22,13 +22,13 @@ go_test(
|
|||||||
tags = ["automanaged"],
|
tags = ["automanaged"],
|
||||||
deps = [
|
deps = [
|
||||||
"//vendor/github.com/google/gofuzz:go_default_library",
|
"//vendor/github.com/google/gofuzz:go_default_library",
|
||||||
"//vendor/k8s.io/api/core/v1:go_default_library",
|
|
||||||
"//vendor/k8s.io/apimachinery/pkg/api/equality:go_default_library",
|
"//vendor/k8s.io/apimachinery/pkg/api/equality:go_default_library",
|
||||||
"//vendor/k8s.io/apimachinery/pkg/api/meta:go_default_library",
|
"//vendor/k8s.io/apimachinery/pkg/api/meta:go_default_library",
|
||||||
"//vendor/k8s.io/apimachinery/pkg/api/testing:go_default_library",
|
"//vendor/k8s.io/apimachinery/pkg/api/testing:go_default_library",
|
||||||
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
|
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
|
||||||
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1/unstructured:go_default_library",
|
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1/unstructured:go_default_library",
|
||||||
"//vendor/k8s.io/apimachinery/pkg/apis/testapigroup:go_default_library",
|
"//vendor/k8s.io/apimachinery/pkg/apis/testapigroup:go_default_library",
|
||||||
|
"//vendor/k8s.io/apimachinery/pkg/apis/testapigroup/v1:go_default_library",
|
||||||
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
|
"//vendor/k8s.io/apimachinery/pkg/runtime: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/runtime/serializer/protobuf:go_default_library",
|
"//vendor/k8s.io/apimachinery/pkg/runtime/serializer/protobuf:go_default_library",
|
||||||
|
@ -20,13 +20,13 @@ import (
|
|||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/google/gofuzz"
|
fuzz "github.com/google/gofuzz"
|
||||||
|
|
||||||
"k8s.io/api/core/v1"
|
|
||||||
"k8s.io/apimachinery/pkg/api/meta"
|
"k8s.io/apimachinery/pkg/api/meta"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||||
"k8s.io/apimachinery/pkg/apis/testapigroup"
|
"k8s.io/apimachinery/pkg/apis/testapigroup"
|
||||||
|
"k8s.io/apimachinery/pkg/apis/testapigroup/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/apimachinery/pkg/util/diff"
|
"k8s.io/apimachinery/pkg/util/diff"
|
||||||
@ -52,11 +52,11 @@ func TestExtractList(t *testing.T) {
|
|||||||
&testapigroup.Carp{ObjectMeta: metav1.ObjectMeta{Name: "1"}},
|
&testapigroup.Carp{ObjectMeta: metav1.ObjectMeta{Name: "1"}},
|
||||||
&testapigroup.Carp{ObjectMeta: metav1.ObjectMeta{Name: "2"}},
|
&testapigroup.Carp{ObjectMeta: metav1.ObjectMeta{Name: "2"}},
|
||||||
}
|
}
|
||||||
list2 := &v1.List{
|
list2 := &ListV1{
|
||||||
Items: []runtime.RawExtension{
|
Items: []runtime.RawExtension{
|
||||||
{Raw: []byte("foo")},
|
{Raw: []byte("foo")},
|
||||||
{Raw: []byte("bar")},
|
{Raw: []byte("bar")},
|
||||||
{Object: &v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "other"}}},
|
{Object: &v1.Carp{ObjectMeta: metav1.ObjectMeta{Name: "other"}}},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
list3 := &fakePtrValueList{
|
list3 := &fakePtrValueList{
|
||||||
@ -72,13 +72,6 @@ func TestExtractList(t *testing.T) {
|
|||||||
{ObjectMeta: metav1.ObjectMeta{Name: "3"}},
|
{ObjectMeta: metav1.ObjectMeta{Name: "3"}},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
list5 := &v1.PodList{
|
|
||||||
Items: []v1.Pod{
|
|
||||||
{ObjectMeta: metav1.ObjectMeta{Name: "1"}},
|
|
||||||
{ObjectMeta: metav1.ObjectMeta{Name: "2"}},
|
|
||||||
{ObjectMeta: metav1.ObjectMeta{Name: "3"}},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
in runtime.Object
|
in runtime.Object
|
||||||
@ -90,11 +83,7 @@ func TestExtractList(t *testing.T) {
|
|||||||
out: []interface{}{},
|
out: []interface{}{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
in: &v1.List{},
|
in: &ListV1{},
|
||||||
out: []interface{}{},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
in: &v1.PodList{},
|
|
||||||
out: []interface{}{},
|
out: []interface{}{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -114,10 +103,6 @@ func TestExtractList(t *testing.T) {
|
|||||||
in: list4,
|
in: list4,
|
||||||
out: []interface{}{&list4.Items[0], &list4.Items[1], &list4.Items[2]},
|
out: []interface{}{&list4.Items[0], &list4.Items[1], &list4.Items[2]},
|
||||||
},
|
},
|
||||||
{
|
|
||||||
in: list5,
|
|
||||||
out: []interface{}{&list5.Items[0], &list5.Items[1], &list5.Items[2]},
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
for i, test := range testCases {
|
for i, test := range testCases {
|
||||||
list, err := meta.ExtractList(test.in)
|
list, err := meta.ExtractList(test.in)
|
||||||
@ -145,11 +130,11 @@ func TestEachListItem(t *testing.T) {
|
|||||||
&testapigroup.Carp{ObjectMeta: metav1.ObjectMeta{Name: "1"}},
|
&testapigroup.Carp{ObjectMeta: metav1.ObjectMeta{Name: "1"}},
|
||||||
&testapigroup.Carp{ObjectMeta: metav1.ObjectMeta{Name: "2"}},
|
&testapigroup.Carp{ObjectMeta: metav1.ObjectMeta{Name: "2"}},
|
||||||
}
|
}
|
||||||
list2 := &v1.List{
|
list2 := &ListV1{
|
||||||
Items: []runtime.RawExtension{
|
Items: []runtime.RawExtension{
|
||||||
{Raw: []byte("foo")},
|
{Raw: []byte("foo")},
|
||||||
{Raw: []byte("bar")},
|
{Raw: []byte("bar")},
|
||||||
{Object: &v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "other"}}},
|
{Object: &v1.Carp{ObjectMeta: metav1.ObjectMeta{Name: "other"}}},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
list3 := &fakePtrValueList{
|
list3 := &fakePtrValueList{
|
||||||
@ -165,13 +150,6 @@ func TestEachListItem(t *testing.T) {
|
|||||||
{ObjectMeta: metav1.ObjectMeta{Name: "3"}},
|
{ObjectMeta: metav1.ObjectMeta{Name: "3"}},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
list5 := &v1.PodList{
|
|
||||||
Items: []v1.Pod{
|
|
||||||
{ObjectMeta: metav1.ObjectMeta{Name: "1"}},
|
|
||||||
{ObjectMeta: metav1.ObjectMeta{Name: "2"}},
|
|
||||||
{ObjectMeta: metav1.ObjectMeta{Name: "3"}},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
in runtime.Object
|
in runtime.Object
|
||||||
@ -182,11 +160,7 @@ func TestEachListItem(t *testing.T) {
|
|||||||
out: []interface{}{},
|
out: []interface{}{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
in: &v1.List{},
|
in: &ListV1{},
|
||||||
out: []interface{}{},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
in: &v1.PodList{},
|
|
||||||
out: []interface{}{},
|
out: []interface{}{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -205,10 +179,6 @@ func TestEachListItem(t *testing.T) {
|
|||||||
in: list4,
|
in: list4,
|
||||||
out: []interface{}{&list4.Items[0], &list4.Items[1], &list4.Items[2]},
|
out: []interface{}{&list4.Items[0], &list4.Items[1], &list4.Items[2]},
|
||||||
},
|
},
|
||||||
{
|
|
||||||
in: list5,
|
|
||||||
out: []interface{}{&list5.Items[0], &list5.Items[1], &list5.Items[2]},
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
for i, test := range testCases {
|
for i, test := range testCases {
|
||||||
list := []runtime.Object{}
|
list := []runtime.Object{}
|
||||||
|
@ -24,9 +24,9 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"k8s.io/api/core/v1"
|
|
||||||
apiequality "k8s.io/apimachinery/pkg/api/equality"
|
apiequality "k8s.io/apimachinery/pkg/api/equality"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
|
"k8s.io/apimachinery/pkg/apis/testapigroup/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/apimachinery/pkg/runtime/serializer/protobuf"
|
"k8s.io/apimachinery/pkg/runtime/serializer/protobuf"
|
||||||
@ -272,16 +272,12 @@ func TestProtobufDecode(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestDecodeObjects(t *testing.T) {
|
func TestDecodeObjects(t *testing.T) {
|
||||||
obj1 := &v1.Pod{
|
obj1 := &v1.Carp{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: "cool",
|
Name: "cool",
|
||||||
},
|
},
|
||||||
Spec: v1.PodSpec{
|
Spec: v1.CarpSpec{
|
||||||
Containers: []v1.Container{
|
Hostname: "coolhost",
|
||||||
{
|
|
||||||
Name: "test",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
obj1wire, err := obj1.Marshal()
|
obj1wire, err := obj1.Marshal()
|
||||||
@ -290,7 +286,7 @@ func TestDecodeObjects(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
wire1, err := (&runtime.Unknown{
|
wire1, err := (&runtime.Unknown{
|
||||||
TypeMeta: runtime.TypeMeta{Kind: "Pod", APIVersion: "v1"},
|
TypeMeta: runtime.TypeMeta{Kind: "Carp", APIVersion: "v1"},
|
||||||
Raw: obj1wire,
|
Raw: obj1wire,
|
||||||
}).Marshal()
|
}).Marshal()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -298,7 +294,7 @@ func TestDecodeObjects(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
unk2 := &runtime.Unknown{
|
unk2 := &runtime.Unknown{
|
||||||
TypeMeta: runtime.TypeMeta{Kind: "Pod", APIVersion: "v1"},
|
TypeMeta: runtime.TypeMeta{Kind: "Carp", APIVersion: "v1"},
|
||||||
}
|
}
|
||||||
wire2 := make([]byte, len(wire1)*2)
|
wire2 := make([]byte, len(wire1)*2)
|
||||||
n, err := unk2.NestedMarshalTo(wire2, obj1, uint64(obj1.Size()))
|
n, err := unk2.NestedMarshalTo(wire2, obj1, uint64(obj1.Size()))
|
||||||
@ -323,7 +319,7 @@ func TestDecodeObjects(t *testing.T) {
|
|||||||
}
|
}
|
||||||
scheme := runtime.NewScheme()
|
scheme := runtime.NewScheme()
|
||||||
for i, test := range testCases {
|
for i, test := range testCases {
|
||||||
scheme.AddKnownTypes(schema.GroupVersion{Version: "v1"}, &v1.Pod{})
|
scheme.AddKnownTypes(schema.GroupVersion{Version: "v1"}, &v1.Carp{})
|
||||||
v1.AddToScheme(scheme)
|
v1.AddToScheme(scheme)
|
||||||
s := protobuf.NewSerializer(scheme, scheme, "application/protobuf")
|
s := protobuf.NewSerializer(scheme, scheme, "application/protobuf")
|
||||||
obj, err := runtime.Decode(s, test.data)
|
obj, err := runtime.Decode(s, test.data)
|
||||||
|
@ -25,15 +25,22 @@ import (
|
|||||||
apiserializer "k8s.io/apimachinery/pkg/runtime/serializer"
|
apiserializer "k8s.io/apimachinery/pkg/runtime/serializer"
|
||||||
)
|
)
|
||||||
|
|
||||||
// List holds a list of objects, which may not be known by the server.
|
// List and ListV1 should be kept in sync with k8s.io/kubernetes/pkg/api#List
|
||||||
|
// and k8s.io/api/core/v1#List.
|
||||||
type List struct {
|
type List struct {
|
||||||
metav1.TypeMeta
|
metav1.TypeMeta
|
||||||
// +optional
|
|
||||||
metav1.ListMeta
|
metav1.ListMeta
|
||||||
|
|
||||||
Items []runtime.Object
|
Items []runtime.Object
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ListV1 struct {
|
||||||
|
metav1.TypeMeta `json:",inline"`
|
||||||
|
metav1.ListMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
|
||||||
|
|
||||||
|
Items []runtime.RawExtension `json:"items" protobuf:"bytes,2,rep,name=items"`
|
||||||
|
}
|
||||||
|
|
||||||
func TestScheme() (*runtime.Scheme, apiserializer.CodecFactory) {
|
func TestScheme() (*runtime.Scheme, apiserializer.CodecFactory) {
|
||||||
internalGV := schema.GroupVersion{Group: "", Version: runtime.APIVersionInternal}
|
internalGV := schema.GroupVersion{Group: "", Version: runtime.APIVersionInternal}
|
||||||
externalGV := schema.GroupVersion{Group: "", Version: "v1"}
|
externalGV := schema.GroupVersion{Group: "", Version: "v1"}
|
||||||
|
Loading…
Reference in New Issue
Block a user