Commit 70fa6975 authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

Merge pull request #48601 from sttts/sttts-separate-test-types

Automatic merge from submit-queue (batch tested with PRs 48583, 48605, 48601) apimachinery+apiserver: separate test types in their own packages Preparation for static deepcopy https://github.com/kubernetes/kubernetes/pull/48544 and its use of package-global deepcopy-gen tags for all runtime.Objects. - [x] wait for #48497
parents eab5e060 d358cb16
...@@ -25,12 +25,15 @@ go_test( ...@@ -25,12 +25,15 @@ go_test(
go_library( go_library(
name = "go_default_library", name = "go_default_library",
srcs = [ srcs = [
"doc.go",
"register.go", "register.go",
"types.go", "types.go",
"zz_generated.deepcopy.go",
], ],
tags = ["automanaged"], tags = ["automanaged"],
deps = [ deps = [
"//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/conversion: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",
], ],
......
/*
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.
*/
// +k8s:deepcopy-gen=package
package v1
// +build !ignore_autogenerated
/*
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.
*/
// This file was autogenerated by deepcopy-gen. Do not edit it manually!
package v1
import (
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
conversion "k8s.io/apimachinery/pkg/conversion"
reflect "reflect"
)
// GetGeneratedDeepCopyFuncs returns the generated funcs, since we aren't registering them.
func GetGeneratedDeepCopyFuncs() []conversion.GeneratedDeepCopyFunc {
return []conversion.GeneratedDeepCopyFunc{
{Fn: DeepCopy_v1_Example, InType: reflect.TypeOf(&Example{})},
{Fn: DeepCopy_v1_ExampleList, InType: reflect.TypeOf(&ExampleList{})},
{Fn: DeepCopy_v1_ExampleSpec, InType: reflect.TypeOf(&ExampleSpec{})},
{Fn: DeepCopy_v1_ExampleStatus, InType: reflect.TypeOf(&ExampleStatus{})},
}
}
// DeepCopy_v1_Example is an autogenerated deepcopy function.
func DeepCopy_v1_Example(in interface{}, out interface{}, c *conversion.Cloner) error {
{
in := in.(*Example)
out := out.(*Example)
*out = *in
if newVal, err := c.DeepCopy(&in.ObjectMeta); err != nil {
return err
} else {
out.ObjectMeta = *newVal.(*meta_v1.ObjectMeta)
}
return nil
}
}
// DeepCopy_v1_ExampleList is an autogenerated deepcopy function.
func DeepCopy_v1_ExampleList(in interface{}, out interface{}, c *conversion.Cloner) error {
{
in := in.(*ExampleList)
out := out.(*ExampleList)
*out = *in
if in.Items != nil {
in, out := &in.Items, &out.Items
*out = make([]Example, len(*in))
for i := range *in {
if newVal, err := c.DeepCopy(&(*in)[i]); err != nil {
return err
} else {
(*out)[i] = *newVal.(*Example)
}
}
}
return nil
}
}
// DeepCopy_v1_ExampleSpec is an autogenerated deepcopy function.
func DeepCopy_v1_ExampleSpec(in interface{}, out interface{}, c *conversion.Cloner) error {
{
in := in.(*ExampleSpec)
out := out.(*ExampleSpec)
*out = *in
return nil
}
}
// DeepCopy_v1_ExampleStatus is an autogenerated deepcopy function.
func DeepCopy_v1_ExampleStatus(in interface{}, out interface{}, c *conversion.Cloner) error {
{
in := in.(*ExampleStatus)
out := out.(*ExampleStatus)
*out = *in
return nil
}
}
...@@ -63,6 +63,7 @@ go_test( ...@@ -63,6 +63,7 @@ go_test(
"//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:go_default_library", "//vendor/k8s.io/apimachinery/pkg/runtime/serializer:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime/testing:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/diff:go_default_library", "//vendor/k8s.io/apimachinery/pkg/util/diff:go_default_library",
], ],
) )
...@@ -22,37 +22,17 @@ import ( ...@@ -22,37 +22,17 @@ import (
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/runtime/schema"
runtimetesting "k8s.io/apimachinery/pkg/runtime/testing"
) )
type InternalComplex struct {
runtime.TypeMeta
String string
Integer int
Integer64 int64
Int64 int64
Bool bool
}
type ExternalComplex struct {
runtime.TypeMeta `json:",inline"`
String string `json:"string" description:"testing"`
Integer int `json:"int"`
Integer64 int64 `json:",omitempty"`
Int64 int64
Bool bool `json:"bool"`
}
func (obj *InternalComplex) GetObjectKind() schema.ObjectKind { return &obj.TypeMeta }
func (obj *ExternalComplex) GetObjectKind() schema.ObjectKind { return &obj.TypeMeta }
func TestStringMapConversion(t *testing.T) { func TestStringMapConversion(t *testing.T) {
internalGV := schema.GroupVersion{Group: "test.group", Version: runtime.APIVersionInternal} internalGV := schema.GroupVersion{Group: "test.group", Version: runtime.APIVersionInternal}
externalGV := schema.GroupVersion{Group: "test.group", Version: "external"} externalGV := schema.GroupVersion{Group: "test.group", Version: "external"}
scheme := runtime.NewScheme() scheme := runtime.NewScheme()
scheme.Log(t) scheme.Log(t)
scheme.AddKnownTypeWithName(internalGV.WithKind("Complex"), &InternalComplex{}) scheme.AddKnownTypeWithName(internalGV.WithKind("Complex"), &runtimetesting.InternalComplex{})
scheme.AddKnownTypeWithName(externalGV.WithKind("Complex"), &ExternalComplex{}) scheme.AddKnownTypeWithName(externalGV.WithKind("Complex"), &runtimetesting.ExternalComplex{})
testCases := map[string]struct { testCases := map[string]struct {
input map[string][]string input map[string][]string
...@@ -66,62 +46,62 @@ func TestStringMapConversion(t *testing.T) { ...@@ -66,62 +46,62 @@ func TestStringMapConversion(t *testing.T) {
"int": {"1"}, "int": {"1"},
"Integer64": {"2"}, "Integer64": {"2"},
}, },
expected: &ExternalComplex{String: "value", Integer: 1}, expected: &runtimetesting.ExternalComplex{String: "value", Integer: 1},
}, },
"returns error on bad int": { "returns error on bad int": {
input: map[string][]string{ input: map[string][]string{
"int": {"a"}, "int": {"a"},
}, },
errFn: func(err error) bool { return err != nil }, errFn: func(err error) bool { return err != nil },
expected: &ExternalComplex{}, expected: &runtimetesting.ExternalComplex{},
}, },
"parses int64": { "parses int64": {
input: map[string][]string{ input: map[string][]string{
"Int64": {"-1"}, "Int64": {"-1"},
}, },
expected: &ExternalComplex{Int64: -1}, expected: &runtimetesting.ExternalComplex{Int64: -1},
}, },
"returns error on bad int64": { "returns error on bad int64": {
input: map[string][]string{ input: map[string][]string{
"Int64": {"a"}, "Int64": {"a"},
}, },
errFn: func(err error) bool { return err != nil }, errFn: func(err error) bool { return err != nil },
expected: &ExternalComplex{}, expected: &runtimetesting.ExternalComplex{},
}, },
"parses boolean true": { "parses boolean true": {
input: map[string][]string{ input: map[string][]string{
"bool": {"true"}, "bool": {"true"},
}, },
expected: &ExternalComplex{Bool: true}, expected: &runtimetesting.ExternalComplex{Bool: true},
}, },
"parses boolean any value": { "parses boolean any value": {
input: map[string][]string{ input: map[string][]string{
"bool": {"foo"}, "bool": {"foo"},
}, },
expected: &ExternalComplex{Bool: true}, expected: &runtimetesting.ExternalComplex{Bool: true},
}, },
"parses boolean false": { "parses boolean false": {
input: map[string][]string{ input: map[string][]string{
"bool": {"false"}, "bool": {"false"},
}, },
expected: &ExternalComplex{Bool: false}, expected: &runtimetesting.ExternalComplex{Bool: false},
}, },
"parses boolean empty value": { "parses boolean empty value": {
input: map[string][]string{ input: map[string][]string{
"bool": {""}, "bool": {""},
}, },
expected: &ExternalComplex{Bool: true}, expected: &runtimetesting.ExternalComplex{Bool: true},
}, },
"parses boolean no value": { "parses boolean no value": {
input: map[string][]string{ input: map[string][]string{
"bool": {}, "bool": {},
}, },
expected: &ExternalComplex{Bool: false}, expected: &runtimetesting.ExternalComplex{Bool: false},
}, },
} }
for k, tc := range testCases { for k, tc := range testCases {
out := &ExternalComplex{} out := &runtimetesting.ExternalComplex{}
if err := scheme.Convert(&tc.input, out, nil); (tc.errFn == nil && err != nil) || (tc.errFn != nil && !tc.errFn(err)) { if err := scheme.Convert(&tc.input, out, nil); (tc.errFn == nil && err != nil) || (tc.errFn != nil && !tc.errFn(err)) {
t.Errorf("%s: unexpected error: %v", k, err) t.Errorf("%s: unexpected error: %v", k, err)
continue continue
......
...@@ -25,50 +25,18 @@ import ( ...@@ -25,50 +25,18 @@ import (
"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" "k8s.io/apimachinery/pkg/runtime/serializer"
runtimetesting "k8s.io/apimachinery/pkg/runtime/testing"
"k8s.io/apimachinery/pkg/util/diff" "k8s.io/apimachinery/pkg/util/diff"
) )
type EmbeddedTest struct {
runtime.TypeMeta
ID string
Object runtime.Object
EmptyObject runtime.Object
}
type EmbeddedTestExternal struct {
runtime.TypeMeta `json:",inline"`
ID string `json:"id,omitempty"`
Object runtime.RawExtension `json:"object,omitempty"`
EmptyObject runtime.RawExtension `json:"emptyObject,omitempty"`
}
type ObjectTest struct {
runtime.TypeMeta
ID string
Items []runtime.Object
}
type ObjectTestExternal struct {
runtime.TypeMeta `yaml:",inline" json:",inline"`
ID string `json:"id,omitempty"`
Items []runtime.RawExtension `json:"items,omitempty"`
}
func (obj *ObjectTest) GetObjectKind() schema.ObjectKind { return &obj.TypeMeta }
func (obj *ObjectTestExternal) GetObjectKind() schema.ObjectKind { return &obj.TypeMeta }
func (obj *EmbeddedTest) GetObjectKind() schema.ObjectKind { return &obj.TypeMeta }
func (obj *EmbeddedTestExternal) GetObjectKind() schema.ObjectKind { return &obj.TypeMeta }
func TestDecodeEmptyRawExtensionAsObject(t *testing.T) { func TestDecodeEmptyRawExtensionAsObject(t *testing.T) {
internalGV := schema.GroupVersion{Group: "test.group", Version: runtime.APIVersionInternal} internalGV := schema.GroupVersion{Group: "test.group", Version: runtime.APIVersionInternal}
externalGV := schema.GroupVersion{Group: "test.group", Version: "v1test"} externalGV := schema.GroupVersion{Group: "test.group", Version: "v1test"}
externalGVK := externalGV.WithKind("ObjectTest") externalGVK := externalGV.WithKind("ObjectTest")
s := runtime.NewScheme() s := runtime.NewScheme()
s.AddKnownTypes(internalGV, &ObjectTest{}) s.AddKnownTypes(internalGV, &runtimetesting.ObjectTest{})
s.AddKnownTypeWithName(externalGVK, &ObjectTestExternal{}) s.AddKnownTypeWithName(externalGVK, &runtimetesting.ObjectTestExternal{})
codec := serializer.NewCodecFactory(s).LegacyCodec(externalGV) codec := serializer.NewCodecFactory(s).LegacyCodec(externalGV)
...@@ -76,7 +44,7 @@ func TestDecodeEmptyRawExtensionAsObject(t *testing.T) { ...@@ -76,7 +44,7 @@ func TestDecodeEmptyRawExtensionAsObject(t *testing.T) {
if err != nil { if err != nil {
t.Fatalf("unexpected error: %v", err) t.Fatalf("unexpected error: %v", err)
} }
test := obj.(*ObjectTest) test := obj.(*runtimetesting.ObjectTest)
if unk, ok := test.Items[0].(*runtime.Unknown); !ok || unk.Kind != "" || unk.APIVersion != "" || string(unk.Raw) != "{}" || unk.ContentType != runtime.ContentTypeJSON { if unk, ok := test.Items[0].(*runtime.Unknown); !ok || unk.Kind != "" || unk.APIVersion != "" || string(unk.Raw) != "{}" || unk.ContentType != runtime.ContentTypeJSON {
t.Fatalf("unexpected object: %#v", test.Items[0]) t.Fatalf("unexpected object: %#v", test.Items[0])
} }
...@@ -88,7 +56,7 @@ func TestDecodeEmptyRawExtensionAsObject(t *testing.T) { ...@@ -88,7 +56,7 @@ func TestDecodeEmptyRawExtensionAsObject(t *testing.T) {
if err != nil { if err != nil {
t.Fatalf("unexpected error: %v", err) t.Fatalf("unexpected error: %v", err)
} }
test = obj.(*ObjectTest) test = obj.(*runtimetesting.ObjectTest)
if unk, ok := test.Items[0].(*runtime.Unknown); !ok || unk.Kind != "" || unk.APIVersion != "" || string(unk.Raw) != `{"kind":"Other","apiVersion":"v1"}` || unk.ContentType != runtime.ContentTypeJSON { if unk, ok := test.Items[0].(*runtime.Unknown); !ok || unk.Kind != "" || unk.APIVersion != "" || string(unk.Raw) != `{"kind":"Other","apiVersion":"v1"}` || unk.ContentType != runtime.ContentTypeJSON {
t.Fatalf("unexpected object: %#v", test.Items[0]) t.Fatalf("unexpected object: %#v", test.Items[0])
} }
...@@ -102,29 +70,29 @@ func TestArrayOfRuntimeObject(t *testing.T) { ...@@ -102,29 +70,29 @@ func TestArrayOfRuntimeObject(t *testing.T) {
externalGV := schema.GroupVersion{Group: "test.group", Version: "v1test"} externalGV := schema.GroupVersion{Group: "test.group", Version: "v1test"}
s := runtime.NewScheme() s := runtime.NewScheme()
s.AddKnownTypes(internalGV, &EmbeddedTest{}) s.AddKnownTypes(internalGV, &runtimetesting.EmbeddedTest{})
s.AddKnownTypeWithName(externalGV.WithKind("EmbeddedTest"), &EmbeddedTestExternal{}) s.AddKnownTypeWithName(externalGV.WithKind("EmbeddedTest"), &runtimetesting.EmbeddedTestExternal{})
s.AddKnownTypes(internalGV, &ObjectTest{}) s.AddKnownTypes(internalGV, &runtimetesting.ObjectTest{})
s.AddKnownTypeWithName(externalGV.WithKind("ObjectTest"), &ObjectTestExternal{}) s.AddKnownTypeWithName(externalGV.WithKind("ObjectTest"), &runtimetesting.ObjectTestExternal{})
codec := serializer.NewCodecFactory(s).LegacyCodec(externalGV) codec := serializer.NewCodecFactory(s).LegacyCodec(externalGV)
innerItems := []runtime.Object{ innerItems := []runtime.Object{
&EmbeddedTest{ID: "baz"}, &runtimetesting.EmbeddedTest{ID: "baz"},
} }
items := []runtime.Object{ items := []runtime.Object{
&EmbeddedTest{ID: "foo"}, &runtimetesting.EmbeddedTest{ID: "foo"},
&EmbeddedTest{ID: "bar"}, &runtimetesting.EmbeddedTest{ID: "bar"},
// TODO: until YAML is removed, this JSON must be in ascending key order to ensure consistent roundtrip serialization // TODO: until YAML is removed, this JSON must be in ascending key order to ensure consistent roundtrip serialization
&runtime.Unknown{ &runtime.Unknown{
Raw: []byte(`{"apiVersion":"unknown.group/unknown","foo":"bar","kind":"OtherTest"}`), Raw: []byte(`{"apiVersion":"unknown.group/unknown","foo":"bar","kind":"OtherTest"}`),
ContentType: runtime.ContentTypeJSON, ContentType: runtime.ContentTypeJSON,
}, },
&ObjectTest{ &runtimetesting.ObjectTest{
Items: runtime.NewEncodableList(codec, innerItems), Items: runtime.NewEncodableList(codec, innerItems),
}, },
} }
internal := &ObjectTest{ internal := &runtimetesting.ObjectTest{
Items: runtime.NewEncodableList(codec, items), Items: runtime.NewEncodableList(codec, items),
} }
wire, err := runtime.Encode(codec, internal) wire, err := runtime.Encode(codec, internal)
...@@ -133,13 +101,13 @@ func TestArrayOfRuntimeObject(t *testing.T) { ...@@ -133,13 +101,13 @@ func TestArrayOfRuntimeObject(t *testing.T) {
} }
t.Logf("Wire format is:\n%s\n", string(wire)) t.Logf("Wire format is:\n%s\n", string(wire))
obj := &ObjectTestExternal{} obj := &runtimetesting.ObjectTestExternal{}
if err := json.Unmarshal(wire, obj); err != nil { if err := json.Unmarshal(wire, obj); err != nil {
t.Fatalf("unexpected error: %v", err) t.Fatalf("unexpected error: %v", err)
} }
t.Logf("exact wire is: %s", string(obj.Items[0].Raw)) t.Logf("exact wire is: %s", string(obj.Items[0].Raw))
items[3] = &ObjectTest{Items: innerItems} items[3] = &runtimetesting.ObjectTest{Items: innerItems}
internal.Items = items internal.Items = items
decoded, err := runtime.Decode(codec, wire) decoded, err := runtime.Decode(codec, wire)
...@@ -178,15 +146,15 @@ func TestNestedObject(t *testing.T) { ...@@ -178,15 +146,15 @@ func TestNestedObject(t *testing.T) {
embeddedTestExternalGVK := externalGV.WithKind("EmbeddedTest") embeddedTestExternalGVK := externalGV.WithKind("EmbeddedTest")
s := runtime.NewScheme() s := runtime.NewScheme()
s.AddKnownTypes(internalGV, &EmbeddedTest{}) s.AddKnownTypes(internalGV, &runtimetesting.EmbeddedTest{})
s.AddKnownTypeWithName(embeddedTestExternalGVK, &EmbeddedTestExternal{}) s.AddKnownTypeWithName(embeddedTestExternalGVK, &runtimetesting.EmbeddedTestExternal{})
codec := serializer.NewCodecFactory(s).LegacyCodec(externalGV) codec := serializer.NewCodecFactory(s).LegacyCodec(externalGV)
inner := &EmbeddedTest{ inner := &runtimetesting.EmbeddedTest{
ID: "inner", ID: "inner",
} }
outer := &EmbeddedTest{ outer := &runtimetesting.EmbeddedTest{
ID: "outer", ID: "outer",
Object: runtime.NewEncodable(codec, inner), Object: runtime.NewEncodable(codec, inner),
} }
...@@ -210,18 +178,18 @@ func TestNestedObject(t *testing.T) { ...@@ -210,18 +178,18 @@ func TestNestedObject(t *testing.T) {
t.Errorf("Expected unequal %#v %#v", e, a) t.Errorf("Expected unequal %#v %#v", e, a)
} }
obj, err := runtime.Decode(codec, decoded.(*EmbeddedTest).Object.(*runtime.Unknown).Raw) obj, err := runtime.Decode(codec, decoded.(*runtimetesting.EmbeddedTest).Object.(*runtime.Unknown).Raw)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
decoded.(*EmbeddedTest).Object = obj decoded.(*runtimetesting.EmbeddedTest).Object = obj
if e, a := outer, decoded; !reflect.DeepEqual(e, a) { if e, a := outer, decoded; !reflect.DeepEqual(e, a) {
t.Errorf("Expected equal %#v %#v", e, a) t.Errorf("Expected equal %#v %#v", e, a)
} }
// test JSON decoding of the external object, which should preserve // test JSON decoding of the external object, which should preserve
// raw bytes // raw bytes
var externalViaJSON EmbeddedTestExternal var externalViaJSON runtimetesting.EmbeddedTestExternal
err = json.Unmarshal(wire, &externalViaJSON) err = json.Unmarshal(wire, &externalViaJSON)
if err != nil { if err != nil {
t.Fatalf("Unexpected decode error %v", err) t.Fatalf("Unexpected decode error %v", err)
...@@ -237,7 +205,7 @@ func TestNestedObject(t *testing.T) { ...@@ -237,7 +205,7 @@ func TestNestedObject(t *testing.T) {
// Generic Unmarshalling of JSON cannot load the nested objects because there is // Generic Unmarshalling of JSON cannot load the nested objects because there is
// no default schema set. Consumers wishing to get direct JSON decoding must use // no default schema set. Consumers wishing to get direct JSON decoding must use
// the external representation // the external representation
var decodedViaJSON EmbeddedTest var decodedViaJSON runtimetesting.EmbeddedTest
err = json.Unmarshal(wire, &decodedViaJSON) err = json.Unmarshal(wire, &decodedViaJSON)
if err == nil { if err == nil {
t.Fatal("Expeceted decode error") t.Fatal("Expeceted decode error")
...@@ -257,12 +225,12 @@ func TestDeepCopyOfRuntimeObject(t *testing.T) { ...@@ -257,12 +225,12 @@ func TestDeepCopyOfRuntimeObject(t *testing.T) {
embeddedTestExternalGVK := externalGV.WithKind("EmbeddedTest") embeddedTestExternalGVK := externalGV.WithKind("EmbeddedTest")
s := runtime.NewScheme() s := runtime.NewScheme()
s.AddKnownTypes(internalGV, &EmbeddedTest{}) s.AddKnownTypes(internalGV, &runtimetesting.EmbeddedTest{})
s.AddKnownTypeWithName(embeddedTestExternalGVK, &EmbeddedTestExternal{}) s.AddKnownTypeWithName(embeddedTestExternalGVK, &runtimetesting.EmbeddedTestExternal{})
original := &EmbeddedTest{ original := &runtimetesting.EmbeddedTest{
ID: "outer", ID: "outer",
Object: &EmbeddedTest{ Object: &runtimetesting.EmbeddedTest{
ID: "inner", ID: "inner",
}, },
} }
......
...@@ -21,6 +21,7 @@ go_test( ...@@ -21,6 +21,7 @@ go_test(
"//vendor/k8s.io/apimachinery/pkg/conversion:go_default_library", "//vendor/k8s.io/apimachinery/pkg/conversion: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/testing:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/diff:go_default_library", "//vendor/k8s.io/apimachinery/pkg/util/diff:go_default_library",
], ],
) )
......
package(default_visibility = ["//visibility:public"])
licenses(["notice"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
)
go_library(
name = "go_default_library",
srcs = [
"doc.go",
"types.go",
"zz_generated.deepcopy.go",
],
tags = ["automanaged"],
deps = [
"//vendor/k8s.io/apimachinery/pkg/conversion:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
],
)
/*
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.
*/
// +k8s:deepcopy-gen=package
package testing
/*
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 testing
import (
"k8s.io/apimachinery/pkg/runtime/schema"
)
// Test a weird version/kind embedding format.
// +k8s:deepcopy-gen=false
type MyWeirdCustomEmbeddedVersionKindField struct {
ID string `json:"ID,omitempty"`
APIVersion string `json:"myVersionKey,omitempty"`
ObjectKind string `json:"myKindKey,omitempty"`
Z string `json:"Z,omitempty"`
Y uint64 `json:"Y,omitempty"`
}
type TestType1 struct {
MyWeirdCustomEmbeddedVersionKindField `json:",inline"`
A string `json:"A,omitempty"`
B int `json:"B,omitempty"`
C int8 `json:"C,omitempty"`
D int16 `json:"D,omitempty"`
E int32 `json:"E,omitempty"`
F int64 `json:"F,omitempty"`
G uint `json:"G,omitempty"`
H uint8 `json:"H,omitempty"`
I uint16 `json:"I,omitempty"`
J uint32 `json:"J,omitempty"`
K uint64 `json:"K,omitempty"`
L bool `json:"L,omitempty"`
M map[string]int `json:"M,omitempty"`
N map[string]TestType2 `json:"N,omitempty"`
O *TestType2 `json:"O,omitempty"`
P []TestType2 `json:"Q,omitempty"`
}
type TestType2 struct {
A string `json:"A,omitempty"`
B int `json:"B,omitempty"`
}
type ExternalTestType2 struct {
A string `json:"A,omitempty"`
B int `json:"B,omitempty"`
}
type ExternalTestType1 struct {
MyWeirdCustomEmbeddedVersionKindField `json:",inline"`
A string `json:"A,omitempty"`
B int `json:"B,omitempty"`
C int8 `json:"C,omitempty"`
D int16 `json:"D,omitempty"`
E int32 `json:"E,omitempty"`
F int64 `json:"F,omitempty"`
G uint `json:"G,omitempty"`
H uint8 `json:"H,omitempty"`
I uint16 `json:"I,omitempty"`
J uint32 `json:"J,omitempty"`
K uint64 `json:"K,omitempty"`
L bool `json:"L,omitempty"`
M map[string]int `json:"M,omitempty"`
N map[string]ExternalTestType2 `json:"N,omitempty"`
O *ExternalTestType2 `json:"O,omitempty"`
P []ExternalTestType2 `json:"Q,omitempty"`
}
type ExternalInternalSame struct {
MyWeirdCustomEmbeddedVersionKindField `json:",inline"`
A TestType2 `json:"A,omitempty"`
}
func (obj *MyWeirdCustomEmbeddedVersionKindField) GetObjectKind() schema.ObjectKind { return obj }
func (obj *MyWeirdCustomEmbeddedVersionKindField) SetGroupVersionKind(gvk schema.GroupVersionKind) {
obj.APIVersion, obj.ObjectKind = gvk.ToAPIVersionAndKind()
}
func (obj *MyWeirdCustomEmbeddedVersionKindField) GroupVersionKind() schema.GroupVersionKind {
return schema.FromAPIVersionAndKind(obj.APIVersion, obj.ObjectKind)
}
func (obj *ExternalInternalSame) GetObjectKind() schema.ObjectKind {
return &obj.MyWeirdCustomEmbeddedVersionKindField
}
func (obj *TestType1) GetObjectKind() schema.ObjectKind {
return &obj.MyWeirdCustomEmbeddedVersionKindField
}
func (obj *ExternalTestType1) GetObjectKind() schema.ObjectKind {
return &obj.MyWeirdCustomEmbeddedVersionKindField
}
func (obj *TestType2) GetObjectKind() schema.ObjectKind { return schema.EmptyObjectKind }
func (obj *ExternalTestType2) GetObjectKind() schema.ObjectKind { return schema.EmptyObjectKind }
// +build !ignore_autogenerated
/*
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.
*/
// This file was autogenerated by deepcopy-gen. Do not edit it manually!
package testing
import (
conversion "k8s.io/apimachinery/pkg/conversion"
reflect "reflect"
)
// GetGeneratedDeepCopyFuncs returns the generated funcs, since we aren't registering them.
func GetGeneratedDeepCopyFuncs() []conversion.GeneratedDeepCopyFunc {
return []conversion.GeneratedDeepCopyFunc{
{Fn: DeepCopy_testing_ExternalInternalSame, InType: reflect.TypeOf(&ExternalInternalSame{})},
{Fn: DeepCopy_testing_ExternalTestType1, InType: reflect.TypeOf(&ExternalTestType1{})},
{Fn: DeepCopy_testing_ExternalTestType2, InType: reflect.TypeOf(&ExternalTestType2{})},
{Fn: DeepCopy_testing_TestType1, InType: reflect.TypeOf(&TestType1{})},
{Fn: DeepCopy_testing_TestType2, InType: reflect.TypeOf(&TestType2{})},
}
}
// DeepCopy_testing_ExternalInternalSame is an autogenerated deepcopy function.
func DeepCopy_testing_ExternalInternalSame(in interface{}, out interface{}, c *conversion.Cloner) error {
{
in := in.(*ExternalInternalSame)
out := out.(*ExternalInternalSame)
*out = *in
return nil
}
}
// DeepCopy_testing_ExternalTestType1 is an autogenerated deepcopy function.
func DeepCopy_testing_ExternalTestType1(in interface{}, out interface{}, c *conversion.Cloner) error {
{
in := in.(*ExternalTestType1)
out := out.(*ExternalTestType1)
*out = *in
if in.M != nil {
in, out := &in.M, &out.M
*out = make(map[string]int)
for key, val := range *in {
(*out)[key] = val
}
}
if in.N != nil {
in, out := &in.N, &out.N
*out = make(map[string]ExternalTestType2)
for key, val := range *in {
(*out)[key] = val
}
}
if in.O != nil {
in, out := &in.O, &out.O
*out = new(ExternalTestType2)
**out = **in
}
if in.P != nil {
in, out := &in.P, &out.P
*out = make([]ExternalTestType2, len(*in))
copy(*out, *in)
}
return nil
}
}
// DeepCopy_testing_ExternalTestType2 is an autogenerated deepcopy function.
func DeepCopy_testing_ExternalTestType2(in interface{}, out interface{}, c *conversion.Cloner) error {
{
in := in.(*ExternalTestType2)
out := out.(*ExternalTestType2)
*out = *in
return nil
}
}
// DeepCopy_testing_TestType1 is an autogenerated deepcopy function.
func DeepCopy_testing_TestType1(in interface{}, out interface{}, c *conversion.Cloner) error {
{
in := in.(*TestType1)
out := out.(*TestType1)
*out = *in
if in.M != nil {
in, out := &in.M, &out.M
*out = make(map[string]int)
for key, val := range *in {
(*out)[key] = val
}
}
if in.N != nil {
in, out := &in.N, &out.N
*out = make(map[string]TestType2)
for key, val := range *in {
(*out)[key] = val
}
}
if in.O != nil {
in, out := &in.O, &out.O
*out = new(TestType2)
**out = **in
}
if in.P != nil {
in, out := &in.P, &out.P
*out = make([]TestType2, len(*in))
copy(*out, *in)
}
return nil
}
}
// DeepCopy_testing_TestType2 is an autogenerated deepcopy function.
func DeepCopy_testing_TestType2(in interface{}, out interface{}, c *conversion.Cloner) error {
{
in := in.(*TestType2)
out := out.(*TestType2)
*out = *in
return nil
}
}
package(default_visibility = ["//visibility:public"])
licenses(["notice"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
)
go_library(
name = "go_default_library",
srcs = [
"doc.go",
"types.go",
"zz_generated.deepcopy.go",
],
tags = ["automanaged"],
deps = [
"//vendor/k8s.io/apimachinery/pkg/conversion:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
],
)
/*
Copyright 2016 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.
*/
// +k8s:deepcopy-gen=package
package testing
/*
Copyright 2016 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 testing
import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
)
type EmbeddedTest struct {
runtime.TypeMeta
ID string
Object runtime.Object
EmptyObject runtime.Object
}
type EmbeddedTestExternal struct {
runtime.TypeMeta `json:",inline"`
ID string `json:"id,omitempty"`
Object runtime.RawExtension `json:"object,omitempty"`
EmptyObject runtime.RawExtension `json:"emptyObject,omitempty"`
}
type ObjectTest struct {
runtime.TypeMeta
ID string
Items []runtime.Object
}
type ObjectTestExternal struct {
runtime.TypeMeta `yaml:",inline" json:",inline"`
ID string `json:"id,omitempty"`
Items []runtime.RawExtension `json:"items,omitempty"`
}
type InternalSimple struct {
runtime.TypeMeta `json:",inline"`
TestString string `json:"testString"`
}
type ExternalSimple struct {
runtime.TypeMeta `json:",inline"`
TestString string `json:"testString"`
}
type ExtensionA struct {
runtime.TypeMeta `json:",inline"`
TestString string `json:"testString"`
}
type ExtensionB struct {
runtime.TypeMeta `json:",inline"`
TestString string `json:"testString"`
}
type ExternalExtensionType struct {
runtime.TypeMeta `json:",inline"`
Extension runtime.RawExtension `json:"extension"`
}
type InternalExtensionType struct {
runtime.TypeMeta `json:",inline"`
Extension runtime.Object `json:"extension"`
}
type ExternalOptionalExtensionType struct {
runtime.TypeMeta `json:",inline"`
Extension runtime.RawExtension `json:"extension,omitempty"`
}
type InternalOptionalExtensionType struct {
runtime.TypeMeta `json:",inline"`
Extension runtime.Object `json:"extension,omitempty"`
}
type InternalComplex struct {
runtime.TypeMeta
String string
Integer int
Integer64 int64
Int64 int64
Bool bool
}
type ExternalComplex struct {
runtime.TypeMeta `json:",inline"`
String string `json:"string" description:"testing"`
Integer int `json:"int"`
Integer64 int64 `json:",omitempty"`
Int64 int64
Bool bool `json:"bool"`
}
// Test a weird version/kind embedding format.
// +k8s:deepcopy-gen=false
type MyWeirdCustomEmbeddedVersionKindField struct {
ID string `json:"ID,omitempty"`
APIVersion string `json:"myVersionKey,omitempty"`
ObjectKind string `json:"myKindKey,omitempty"`
Z string `json:"Z,omitempty"`
Y uint64 `json:"Y,omitempty"`
}
type TestType1 struct {
MyWeirdCustomEmbeddedVersionKindField `json:",inline"`
A string `json:"A,omitempty"`
B int `json:"B,omitempty"`
C int8 `json:"C,omitempty"`
D int16 `json:"D,omitempty"`
E int32 `json:"E,omitempty"`
F int64 `json:"F,omitempty"`
G uint `json:"G,omitempty"`
H uint8 `json:"H,omitempty"`
I uint16 `json:"I,omitempty"`
J uint32 `json:"J,omitempty"`
K uint64 `json:"K,omitempty"`
L bool `json:"L,omitempty"`
M map[string]int `json:"M,omitempty"`
N map[string]TestType2 `json:"N,omitempty"`
O *TestType2 `json:"O,omitempty"`
P []TestType2 `json:"Q,omitempty"`
}
type TestType2 struct {
A string `json:"A,omitempty"`
B int `json:"B,omitempty"`
}
type ExternalTestType2 struct {
A string `json:"A,omitempty"`
B int `json:"B,omitempty"`
}
type ExternalTestType1 struct {
MyWeirdCustomEmbeddedVersionKindField `json:",inline"`
A string `json:"A,omitempty"`
B int `json:"B,omitempty"`
C int8 `json:"C,omitempty"`
D int16 `json:"D,omitempty"`
E int32 `json:"E,omitempty"`
F int64 `json:"F,omitempty"`
G uint `json:"G,omitempty"`
H uint8 `json:"H,omitempty"`
I uint16 `json:"I,omitempty"`
J uint32 `json:"J,omitempty"`
K uint64 `json:"K,omitempty"`
L bool `json:"L,omitempty"`
M map[string]int `json:"M,omitempty"`
N map[string]ExternalTestType2 `json:"N,omitempty"`
O *ExternalTestType2 `json:"O,omitempty"`
P []ExternalTestType2 `json:"Q,omitempty"`
}
type ExternalInternalSame struct {
MyWeirdCustomEmbeddedVersionKindField `json:",inline"`
A TestType2 `json:"A,omitempty"`
}
type UnversionedType struct {
MyWeirdCustomEmbeddedVersionKindField `json:",inline"`
A string `json:"A,omitempty"`
}
type UnknownType struct {
MyWeirdCustomEmbeddedVersionKindField `json:",inline"`
A string `json:"A,omitempty"`
}
func (obj *MyWeirdCustomEmbeddedVersionKindField) GetObjectKind() schema.ObjectKind { return obj }
func (obj *MyWeirdCustomEmbeddedVersionKindField) SetGroupVersionKind(gvk schema.GroupVersionKind) {
obj.APIVersion, obj.ObjectKind = gvk.ToAPIVersionAndKind()
}
func (obj *MyWeirdCustomEmbeddedVersionKindField) GroupVersionKind() schema.GroupVersionKind {
return schema.FromAPIVersionAndKind(obj.APIVersion, obj.ObjectKind)
}
func (obj *TestType2) GetObjectKind() schema.ObjectKind { return schema.EmptyObjectKind }
func (obj *ExternalTestType2) GetObjectKind() schema.ObjectKind { return schema.EmptyObjectKind }
func (obj *InternalComplex) GetObjectKind() schema.ObjectKind { return &obj.TypeMeta }
func (obj *ExternalComplex) GetObjectKind() schema.ObjectKind { return &obj.TypeMeta }
func (obj *EmbeddedTest) GetObjectKind() schema.ObjectKind { return &obj.TypeMeta }
func (obj *EmbeddedTestExternal) GetObjectKind() schema.ObjectKind { return &obj.TypeMeta }
func (obj *InternalSimple) GetObjectKind() schema.ObjectKind { return &obj.TypeMeta }
func (obj *ExternalSimple) GetObjectKind() schema.ObjectKind { return &obj.TypeMeta }
func (obj *InternalOptionalExtensionType) GetObjectKind() schema.ObjectKind {
return &obj.TypeMeta
}
func (obj *ObjectTestExternal) GetObjectKind() schema.ObjectKind { return &obj.TypeMeta }
func (obj *ObjectTest) GetObjectKind() schema.ObjectKind { return &obj.TypeMeta }
func (obj *ExternalOptionalExtensionType) GetObjectKind() schema.ObjectKind {
return &obj.TypeMeta
}
func (obj *InternalExtensionType) GetObjectKind() schema.ObjectKind { return &obj.TypeMeta }
func (obj *ExternalExtensionType) GetObjectKind() schema.ObjectKind { return &obj.TypeMeta }
func (obj *ExtensionA) GetObjectKind() schema.ObjectKind { return &obj.TypeMeta }
func (obj *ExtensionB) GetObjectKind() schema.ObjectKind { return &obj.TypeMeta }
...@@ -174,30 +174,21 @@ func addGrouplessTypes() { ...@@ -174,30 +174,21 @@ func addGrouplessTypes() {
} }
func addTestTypes() { func addTestTypes() {
type ListOptions struct {
Object runtime.Object
metav1.TypeMeta `json:",inline"`
LabelSelector string `json:"labelSelector,omitempty"`
FieldSelector string `json:"fieldSelector,omitempty"`
Watch bool `json:"watch,omitempty"`
ResourceVersion string `json:"resourceVersion,omitempty"`
TimeoutSeconds *int64 `json:"timeoutSeconds,omitempty"`
}
scheme.AddKnownTypes(testGroupVersion, scheme.AddKnownTypes(testGroupVersion,
&genericapitesting.Simple{}, &genericapitesting.SimpleList{}, &metav1.ExportOptions{}, &genericapitesting.Simple{}, &genericapitesting.SimpleList{}, &metav1.ExportOptions{},
&metav1.DeleteOptions{}, &genericapitesting.SimpleGetOptions{}, &genericapitesting.SimpleRoot{}, &metav1.DeleteOptions{}, &genericapitesting.SimpleGetOptions{}, &genericapitesting.SimpleRoot{},
&SimpleXGSubresource{}) &genericapitesting.SimpleXGSubresource{})
scheme.AddKnownTypes(testGroupVersion, &examplev1.Pod{}) scheme.AddKnownTypes(testGroupVersion, &examplev1.Pod{})
scheme.AddKnownTypes(testInternalGroupVersion, scheme.AddKnownTypes(testInternalGroupVersion,
&genericapitesting.Simple{}, &genericapitesting.SimpleList{}, &metav1.ExportOptions{}, &genericapitesting.Simple{}, &genericapitesting.SimpleList{}, &metav1.ExportOptions{},
&genericapitesting.SimpleGetOptions{}, &genericapitesting.SimpleRoot{}, &genericapitesting.SimpleGetOptions{}, &genericapitesting.SimpleRoot{},
&SimpleXGSubresource{}) &genericapitesting.SimpleXGSubresource{})
scheme.AddKnownTypes(testInternalGroupVersion, &example.Pod{}) scheme.AddKnownTypes(testInternalGroupVersion, &example.Pod{})
// Register SimpleXGSubresource in both testGroupVersion and testGroup2Version, and also their // Register SimpleXGSubresource in both testGroupVersion and testGroup2Version, and also their
// their corresponding internal versions, to verify that the desired group version object is // their corresponding internal versions, to verify that the desired group version object is
// served in the tests. // served in the tests.
scheme.AddKnownTypes(testGroup2Version, &SimpleXGSubresource{}, &metav1.ExportOptions{}) scheme.AddKnownTypes(testGroup2Version, &genericapitesting.SimpleXGSubresource{}, &metav1.ExportOptions{})
scheme.AddKnownTypes(testInternalGroup2Version, &SimpleXGSubresource{}, &metav1.ExportOptions{}) scheme.AddKnownTypes(testInternalGroup2Version, &genericapitesting.SimpleXGSubresource{}, &metav1.ExportOptions{})
metav1.AddToGroupVersion(scheme, testGroupVersion) metav1.AddToGroupVersion(scheme, testGroupVersion)
} }
...@@ -1153,10 +1144,10 @@ func TestList(t *testing.T) { ...@@ -1153,10 +1144,10 @@ func TestList(t *testing.T) {
t.Errorf("%d: %q unexpected resource namespace: %s", i, testCase.url, simpleStorage.actualNamespace) t.Errorf("%d: %q unexpected resource namespace: %s", i, testCase.url, simpleStorage.actualNamespace)
} }
if simpleStorage.requestedLabelSelector == nil || simpleStorage.requestedLabelSelector.String() != testCase.label { if simpleStorage.requestedLabelSelector == nil || simpleStorage.requestedLabelSelector.String() != testCase.label {
t.Errorf("%d: unexpected label selector: %v", i, simpleStorage.requestedLabelSelector) t.Errorf("%d: unexpected label selector: expected=%v got=%v", i, testCase.label, simpleStorage.requestedLabelSelector)
} }
if simpleStorage.requestedFieldSelector == nil || simpleStorage.requestedFieldSelector.String() != testCase.field { if simpleStorage.requestedFieldSelector == nil || simpleStorage.requestedFieldSelector.String() != testCase.field {
t.Errorf("%d: unexpected field selector: %v", i, simpleStorage.requestedFieldSelector) t.Errorf("%d: unexpected field selector: expected=%v got=%v", i, testCase.field, simpleStorage.requestedFieldSelector)
} }
} }
} }
...@@ -3935,23 +3926,12 @@ func TestUpdateChecksAPIVersion(t *testing.T) { ...@@ -3935,23 +3926,12 @@ func TestUpdateChecksAPIVersion(t *testing.T) {
} }
} }
// SimpleXGSubresource is a cross group subresource, i.e. the subresource does not belong to the
// same group as its parent resource.
type SimpleXGSubresource struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata"`
SubresourceInfo string `json:"subresourceInfo,omitempty"`
Labels map[string]string `json:"labels,omitempty"`
}
func (obj *SimpleXGSubresource) GetObjectKind() schema.ObjectKind { return &obj.TypeMeta }
type SimpleXGSubresourceRESTStorage struct { type SimpleXGSubresourceRESTStorage struct {
item SimpleXGSubresource item genericapitesting.SimpleXGSubresource
} }
func (storage *SimpleXGSubresourceRESTStorage) New() runtime.Object { func (storage *SimpleXGSubresourceRESTStorage) New() runtime.Object {
return &SimpleXGSubresource{} return &genericapitesting.SimpleXGSubresource{}
} }
func (storage *SimpleXGSubresourceRESTStorage) Get(ctx request.Context, id string, options *metav1.GetOptions) (runtime.Object, error) { func (storage *SimpleXGSubresourceRESTStorage) Get(ctx request.Context, id string, options *metav1.GetOptions) (runtime.Object, error) {
...@@ -3969,7 +3949,7 @@ func TestXGSubresource(t *testing.T) { ...@@ -3969,7 +3949,7 @@ func TestXGSubresource(t *testing.T) {
itemID := "theID" itemID := "theID"
subresourceStorage := &SimpleXGSubresourceRESTStorage{ subresourceStorage := &SimpleXGSubresourceRESTStorage{
item: SimpleXGSubresource{ item: genericapitesting.SimpleXGSubresource{
SubresourceInfo: "foo", SubresourceInfo: "foo",
}, },
} }
...@@ -4018,7 +3998,7 @@ func TestXGSubresource(t *testing.T) { ...@@ -4018,7 +3998,7 @@ func TestXGSubresource(t *testing.T) {
if resp.StatusCode != http.StatusOK { if resp.StatusCode != http.StatusOK {
t.Fatalf("unexpected response: %#v", resp) t.Fatalf("unexpected response: %#v", resp)
} }
var itemOut SimpleXGSubresource var itemOut genericapitesting.SimpleXGSubresource
body, err := extractBody(resp, &itemOut) body, err := extractBody(resp, &itemOut)
if err != nil { if err != nil {
t.Errorf("unexpected error: %v", err) t.Errorf("unexpected error: %v", err)
...@@ -4030,7 +4010,7 @@ func TestXGSubresource(t *testing.T) { ...@@ -4030,7 +4010,7 @@ func TestXGSubresource(t *testing.T) {
// conversion type list in API scheme and hence cannot be converted from input type object // conversion type list in API scheme and hence cannot be converted from input type object
// to output type object. So it's values don't appear in the decoded output object. // to output type object. So it's values don't appear in the decoded output object.
decoder := json.NewDecoder(strings.NewReader(body)) decoder := json.NewDecoder(strings.NewReader(body))
var itemFromBody SimpleXGSubresource var itemFromBody genericapitesting.SimpleXGSubresource
err = decoder.Decode(&itemFromBody) err = decoder.Decode(&itemFromBody)
if err != nil { if err != nil {
t.Errorf("unexpected JSON decoding error: %v", err) t.Errorf("unexpected JSON decoding error: %v", err)
......
...@@ -17,7 +17,7 @@ go_test( ...@@ -17,7 +17,7 @@ go_test(
"//vendor/github.com/go-openapi/spec:go_default_library", "//vendor/github.com/go-openapi/spec: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/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/apiserver/pkg/endpoints/openapi/testing:go_default_library",
], ],
) )
......
...@@ -25,27 +25,9 @@ import ( ...@@ -25,27 +25,9 @@ import (
"k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema" openapitesting "k8s.io/apiserver/pkg/endpoints/openapi/testing"
) )
type TestType struct {
}
func (t TestType) GetObjectKind() schema.ObjectKind {
return t
}
func (t TestType) SetGroupVersionKind(kind schema.GroupVersionKind) {
}
func (t TestType) GroupVersionKind() schema.GroupVersionKind {
return schema.GroupVersionKind{
Group: "test",
Version: "v1",
Kind: "TestType",
}
}
func assertEqual(t *testing.T, expected, actual interface{}) { func assertEqual(t *testing.T, expected, actual interface{}) {
var equal bool var equal bool
if expected == nil || actual == nil { if expected == nil || actual == nil {
...@@ -59,17 +41,17 @@ func assertEqual(t *testing.T, expected, actual interface{}) { ...@@ -59,17 +41,17 @@ func assertEqual(t *testing.T, expected, actual interface{}) {
} }
func TestGetDefinitionName(t *testing.T) { func TestGetDefinitionName(t *testing.T) {
testType := TestType{} testType := openapitesting.TestType{}
// in production, the name is stripped of ".*vendor/" prefix before passed // in production, the name is stripped of ".*vendor/" prefix before passed
// to GetDefinitionName, so here typePkgName does not have the // to GetDefinitionName, so here typePkgName does not have the
// "k8s.io/kubernetes/vendor" prefix. // "k8s.io/kubernetes/vendor" prefix.
typePkgName := "k8s.io/apiserver/pkg/endpoints/openapi.TestType" typePkgName := "k8s.io/apiserver/pkg/endpoints/openapi/testing.TestType"
typeFriendlyName := "io.k8s.apiserver.pkg.endpoints.openapi.TestType" typeFriendlyName := "io.k8s.apiserver.pkg.endpoints.openapi.testing.TestType"
if strings.HasSuffix(reflect.TypeOf(testType).PkgPath(), "go_default_test") { if strings.HasSuffix(reflect.TypeOf(testType).PkgPath(), "go_default_test") {
// the test is running inside bazel where the package name is changed and // the test is running inside bazel where the package name is changed and
// "go_default_test" will add to package path. // "go_default_test" will add to package path.
typePkgName = "k8s.io/apiserver/pkg/endpoints/openapi/go_default_test.TestType" typePkgName = "k8s.io/apiserver/pkg/endpoints/openapi/testing/go_default_test.TestType"
typeFriendlyName = "io.k8s.apiserver.pkg.endpoints.openapi.go_default_test.TestType" typeFriendlyName = "io.k8s.apiserver.pkg.endpoints.openapi.testing.go_default_test.TestType"
} }
s := runtime.NewScheme() s := runtime.NewScheme()
s.AddKnownTypeWithName(testType.GroupVersionKind(), &testType) s.AddKnownTypeWithName(testType.GroupVersionKind(), &testType)
......
package(default_visibility = ["//visibility:public"])
licenses(["notice"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
)
go_library(
name = "go_default_library",
srcs = [
"types.go",
"zz_generated.deepcopy.go",
],
tags = ["automanaged"],
deps = [
"//vendor/k8s.io/apimachinery/pkg/conversion:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
],
)
/*
Copyright 2016 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 testing
import (
"k8s.io/apimachinery/pkg/runtime/schema"
)
// +k8s:deepcopy-gen=true
type TestType struct {
}
func (t TestType) GetObjectKind() schema.ObjectKind {
return t
}
func (t TestType) SetGroupVersionKind(kind schema.GroupVersionKind) {
}
func (t TestType) GroupVersionKind() schema.GroupVersionKind {
return schema.GroupVersionKind{
Group: "test",
Version: "v1",
Kind: "TestType",
}
}
// +build !ignore_autogenerated
/*
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.
*/
// This file was autogenerated by deepcopy-gen. Do not edit it manually!
package testing
import (
conversion "k8s.io/apimachinery/pkg/conversion"
reflect "reflect"
)
// GetGeneratedDeepCopyFuncs returns the generated funcs, since we aren't registering them.
func GetGeneratedDeepCopyFuncs() []conversion.GeneratedDeepCopyFunc {
return []conversion.GeneratedDeepCopyFunc{
{Fn: DeepCopy_testing_TestType, InType: reflect.TypeOf(&TestType{})},
}
}
// DeepCopy_testing_TestType is an autogenerated deepcopy function.
func DeepCopy_testing_TestType(in interface{}, out interface{}, c *conversion.Cloner) error {
{
in := in.(*TestType)
out := out.(*TestType)
*out = *in
return nil
}
}
...@@ -10,13 +10,16 @@ load( ...@@ -10,13 +10,16 @@ load(
go_library( go_library(
name = "go_default_library", name = "go_default_library",
srcs = [ srcs = [
"doc.go",
"types.generated.go", "types.generated.go",
"types.go", "types.go",
"zz_generated.deepcopy.go",
], ],
tags = ["automanaged"], tags = ["automanaged"],
deps = [ deps = [
"//vendor/github.com/ugorji/go/codec:go_default_library", "//vendor/github.com/ugorji/go/codec: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/conversion: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/types:go_default_library", "//vendor/k8s.io/apimachinery/pkg/types:go_default_library",
], ],
......
/*
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.
*/
// +k8s:deepcopy-gen=package
package testing // import "k8s.io/apiserver/pkg/endpoints/testing"
...@@ -67,3 +67,14 @@ type SimpleList struct { ...@@ -67,3 +67,14 @@ type SimpleList struct {
} }
func (obj *SimpleList) GetObjectKind() schema.ObjectKind { return &obj.TypeMeta } func (obj *SimpleList) GetObjectKind() schema.ObjectKind { return &obj.TypeMeta }
// SimpleXGSubresource is a cross group subresource, i.e. the subresource does not belong to the
// same group as its parent resource.
type SimpleXGSubresource struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata"`
SubresourceInfo string `json:"subresourceInfo,omitempty"`
Labels map[string]string `json:"labels,omitempty"`
}
func (obj *SimpleXGSubresource) GetObjectKind() schema.ObjectKind { return &obj.TypeMeta }
// +build !ignore_autogenerated
/*
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.
*/
// This file was autogenerated by deepcopy-gen. Do not edit it manually!
package testing
import (
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
conversion "k8s.io/apimachinery/pkg/conversion"
reflect "reflect"
)
// GetGeneratedDeepCopyFuncs returns the generated funcs, since we aren't registering them.
func GetGeneratedDeepCopyFuncs() []conversion.GeneratedDeepCopyFunc {
return []conversion.GeneratedDeepCopyFunc{
{Fn: DeepCopy_testing_Simple, InType: reflect.TypeOf(&Simple{})},
{Fn: DeepCopy_testing_SimpleGetOptions, InType: reflect.TypeOf(&SimpleGetOptions{})},
{Fn: DeepCopy_testing_SimpleList, InType: reflect.TypeOf(&SimpleList{})},
{Fn: DeepCopy_testing_SimpleRoot, InType: reflect.TypeOf(&SimpleRoot{})},
{Fn: DeepCopy_testing_SimpleXGSubresource, InType: reflect.TypeOf(&SimpleXGSubresource{})},
}
}
// DeepCopy_testing_Simple is an autogenerated deepcopy function.
func DeepCopy_testing_Simple(in interface{}, out interface{}, c *conversion.Cloner) error {
{
in := in.(*Simple)
out := out.(*Simple)
*out = *in
if newVal, err := c.DeepCopy(&in.ObjectMeta); err != nil {
return err
} else {
out.ObjectMeta = *newVal.(*v1.ObjectMeta)
}
if in.Labels != nil {
in, out := &in.Labels, &out.Labels
*out = make(map[string]string)
for key, val := range *in {
(*out)[key] = val
}
}
return nil
}
}
// DeepCopy_testing_SimpleGetOptions is an autogenerated deepcopy function.
func DeepCopy_testing_SimpleGetOptions(in interface{}, out interface{}, c *conversion.Cloner) error {
{
in := in.(*SimpleGetOptions)
out := out.(*SimpleGetOptions)
*out = *in
return nil
}
}
// DeepCopy_testing_SimpleList is an autogenerated deepcopy function.
func DeepCopy_testing_SimpleList(in interface{}, out interface{}, c *conversion.Cloner) error {
{
in := in.(*SimpleList)
out := out.(*SimpleList)
*out = *in
if in.Items != nil {
in, out := &in.Items, &out.Items
*out = make([]Simple, len(*in))
for i := range *in {
if newVal, err := c.DeepCopy(&(*in)[i]); err != nil {
return err
} else {
(*out)[i] = *newVal.(*Simple)
}
}
}
return nil
}
}
// DeepCopy_testing_SimpleRoot is an autogenerated deepcopy function.
func DeepCopy_testing_SimpleRoot(in interface{}, out interface{}, c *conversion.Cloner) error {
{
in := in.(*SimpleRoot)
out := out.(*SimpleRoot)
*out = *in
if newVal, err := c.DeepCopy(&in.ObjectMeta); err != nil {
return err
} else {
out.ObjectMeta = *newVal.(*v1.ObjectMeta)
}
if in.Labels != nil {
in, out := &in.Labels, &out.Labels
*out = make(map[string]string)
for key, val := range *in {
(*out)[key] = val
}
}
return nil
}
}
// DeepCopy_testing_SimpleXGSubresource is an autogenerated deepcopy function.
func DeepCopy_testing_SimpleXGSubresource(in interface{}, out interface{}, c *conversion.Cloner) error {
{
in := in.(*SimpleXGSubresource)
out := out.(*SimpleXGSubresource)
*out = *in
if newVal, err := c.DeepCopy(&in.ObjectMeta); err != nil {
return err
} else {
out.ObjectMeta = *newVal.(*v1.ObjectMeta)
}
if in.Labels != nil {
in, out := &in.Labels, &out.Labels
*out = make(map[string]string)
for key, val := range *in {
(*out)[key] = val
}
}
return nil
}
}
...@@ -10,9 +10,11 @@ load( ...@@ -10,9 +10,11 @@ load(
go_library( go_library(
name = "go_default_library", name = "go_default_library",
srcs = [ srcs = [
"doc.go",
"types.generated.go", "types.generated.go",
"types.go", "types.go",
"utils.go", "utils.go",
"zz_generated.deepcopy.go",
], ],
tags = ["automanaged"], tags = ["automanaged"],
deps = [ deps = [
...@@ -20,6 +22,7 @@ go_library( ...@@ -20,6 +22,7 @@ go_library(
"//vendor/golang.org/x/net/context:go_default_library", "//vendor/golang.org/x/net/context: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/apis/meta/v1:go_default_library", "//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/conversion: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/types:go_default_library", "//vendor/k8s.io/apimachinery/pkg/types:go_default_library",
......
/*
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.
*/
// +k8s:deepcopy-gen=package
package testing
// +build !ignore_autogenerated
/*
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.
*/
// This file was autogenerated by deepcopy-gen. Do not edit it manually!
package testing
import (
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
conversion "k8s.io/apimachinery/pkg/conversion"
reflect "reflect"
)
// GetGeneratedDeepCopyFuncs returns the generated funcs, since we aren't registering them.
func GetGeneratedDeepCopyFuncs() []conversion.GeneratedDeepCopyFunc {
return []conversion.GeneratedDeepCopyFunc{
{Fn: DeepCopy_testing_TestResource, InType: reflect.TypeOf(&TestResource{})},
}
}
// DeepCopy_testing_TestResource is an autogenerated deepcopy function.
func DeepCopy_testing_TestResource(in interface{}, out interface{}, c *conversion.Cloner) error {
{
in := in.(*TestResource)
out := out.(*TestResource)
*out = *in
if newVal, err := c.DeepCopy(&in.ObjectMeta); err != nil {
return err
} else {
out.ObjectMeta = *newVal.(*v1.ObjectMeta)
}
return nil
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment