mirror of https://github.com/k3s-io/k3s
remove apimachinery's dependency on k8s.io/api
parent
40be152c95
commit
c6bfbaef23
|
@ -22,13 +22,13 @@ go_test(
|
|||
tags = ["automanaged"],
|
||||
deps = [
|
||||
"//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/meta: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/unstructured: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/schema:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/runtime/serializer/protobuf:go_default_library",
|
||||
|
|
|
@ -20,13 +20,13 @@ import (
|
|||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/google/gofuzz"
|
||||
fuzz "github.com/google/gofuzz"
|
||||
|
||||
"k8s.io/api/core/v1"
|
||||
"k8s.io/apimachinery/pkg/api/meta"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||
"k8s.io/apimachinery/pkg/apis/testapigroup"
|
||||
"k8s.io/apimachinery/pkg/apis/testapigroup/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
"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: "2"}},
|
||||
}
|
||||
list2 := &v1.List{
|
||||
list2 := &ListV1{
|
||||
Items: []runtime.RawExtension{
|
||||
{Raw: []byte("foo")},
|
||||
{Raw: []byte("bar")},
|
||||
{Object: &v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "other"}}},
|
||||
{Object: &v1.Carp{ObjectMeta: metav1.ObjectMeta{Name: "other"}}},
|
||||
},
|
||||
}
|
||||
list3 := &fakePtrValueList{
|
||||
|
@ -72,13 +72,6 @@ func TestExtractList(t *testing.T) {
|
|||
{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 {
|
||||
in runtime.Object
|
||||
|
@ -90,11 +83,7 @@ func TestExtractList(t *testing.T) {
|
|||
out: []interface{}{},
|
||||
},
|
||||
{
|
||||
in: &v1.List{},
|
||||
out: []interface{}{},
|
||||
},
|
||||
{
|
||||
in: &v1.PodList{},
|
||||
in: &ListV1{},
|
||||
out: []interface{}{},
|
||||
},
|
||||
{
|
||||
|
@ -114,10 +103,6 @@ func TestExtractList(t *testing.T) {
|
|||
in: list4,
|
||||
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 {
|
||||
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: "2"}},
|
||||
}
|
||||
list2 := &v1.List{
|
||||
list2 := &ListV1{
|
||||
Items: []runtime.RawExtension{
|
||||
{Raw: []byte("foo")},
|
||||
{Raw: []byte("bar")},
|
||||
{Object: &v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "other"}}},
|
||||
{Object: &v1.Carp{ObjectMeta: metav1.ObjectMeta{Name: "other"}}},
|
||||
},
|
||||
}
|
||||
list3 := &fakePtrValueList{
|
||||
|
@ -165,13 +150,6 @@ func TestEachListItem(t *testing.T) {
|
|||
{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 {
|
||||
in runtime.Object
|
||||
|
@ -182,11 +160,7 @@ func TestEachListItem(t *testing.T) {
|
|||
out: []interface{}{},
|
||||
},
|
||||
{
|
||||
in: &v1.List{},
|
||||
out: []interface{}{},
|
||||
},
|
||||
{
|
||||
in: &v1.PodList{},
|
||||
in: &ListV1{},
|
||||
out: []interface{}{},
|
||||
},
|
||||
{
|
||||
|
@ -205,10 +179,6 @@ func TestEachListItem(t *testing.T) {
|
|||
in: list4,
|
||||
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 {
|
||||
list := []runtime.Object{}
|
||||
|
|
|
@ -24,9 +24,9 @@ import (
|
|||
"strings"
|
||||
"testing"
|
||||
|
||||
"k8s.io/api/core/v1"
|
||||
apiequality "k8s.io/apimachinery/pkg/api/equality"
|
||||
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/schema"
|
||||
"k8s.io/apimachinery/pkg/runtime/serializer/protobuf"
|
||||
|
@ -272,16 +272,12 @@ func TestProtobufDecode(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestDecodeObjects(t *testing.T) {
|
||||
obj1 := &v1.Pod{
|
||||
obj1 := &v1.Carp{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "cool",
|
||||
},
|
||||
Spec: v1.PodSpec{
|
||||
Containers: []v1.Container{
|
||||
{
|
||||
Name: "test",
|
||||
},
|
||||
},
|
||||
Spec: v1.CarpSpec{
|
||||
Hostname: "coolhost",
|
||||
},
|
||||
}
|
||||
obj1wire, err := obj1.Marshal()
|
||||
|
@ -290,7 +286,7 @@ func TestDecodeObjects(t *testing.T) {
|
|||
}
|
||||
|
||||
wire1, err := (&runtime.Unknown{
|
||||
TypeMeta: runtime.TypeMeta{Kind: "Pod", APIVersion: "v1"},
|
||||
TypeMeta: runtime.TypeMeta{Kind: "Carp", APIVersion: "v1"},
|
||||
Raw: obj1wire,
|
||||
}).Marshal()
|
||||
if err != nil {
|
||||
|
@ -298,7 +294,7 @@ func TestDecodeObjects(t *testing.T) {
|
|||
}
|
||||
|
||||
unk2 := &runtime.Unknown{
|
||||
TypeMeta: runtime.TypeMeta{Kind: "Pod", APIVersion: "v1"},
|
||||
TypeMeta: runtime.TypeMeta{Kind: "Carp", APIVersion: "v1"},
|
||||
}
|
||||
wire2 := make([]byte, len(wire1)*2)
|
||||
n, err := unk2.NestedMarshalTo(wire2, obj1, uint64(obj1.Size()))
|
||||
|
@ -323,7 +319,7 @@ func TestDecodeObjects(t *testing.T) {
|
|||
}
|
||||
scheme := runtime.NewScheme()
|
||||
for i, test := range testCases {
|
||||
scheme.AddKnownTypes(schema.GroupVersion{Version: "v1"}, &v1.Pod{})
|
||||
scheme.AddKnownTypes(schema.GroupVersion{Version: "v1"}, &v1.Carp{})
|
||||
v1.AddToScheme(scheme)
|
||||
s := protobuf.NewSerializer(scheme, scheme, "application/protobuf")
|
||||
obj, err := runtime.Decode(s, test.data)
|
||||
|
|
|
@ -25,15 +25,22 @@ import (
|
|||
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 {
|
||||
metav1.TypeMeta
|
||||
// +optional
|
||||
metav1.ListMeta
|
||||
|
||||
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) {
|
||||
internalGV := schema.GroupVersion{Group: "", Version: runtime.APIVersionInternal}
|
||||
externalGV := schema.GroupVersion{Group: "", Version: "v1"}
|
||||
|
|
Loading…
Reference in New Issue