@@ -21,13 +21,19 @@ import (
21
21
22
22
. "github.com/onsi/ginkgo"
23
23
. "github.com/onsi/gomega"
24
+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
25
+ "k8s.io/apimachinery/pkg/runtime"
26
+ "k8s.io/apimachinery/pkg/runtime/schema"
24
27
"k8s.io/client-go/kubernetes"
28
+ "k8s.io/client-go/kubernetes/scheme"
25
29
"k8s.io/client-go/rest"
30
+
26
31
"sigs.k8s.io/controller-runtime/pkg/envtest"
27
32
"sigs.k8s.io/controller-runtime/pkg/envtest/printer"
28
33
logf "sigs.k8s.io/controller-runtime/pkg/log"
29
34
"sigs.k8s.io/controller-runtime/pkg/log/zap"
30
35
"sigs.k8s.io/controller-runtime/pkg/metrics"
36
+ crscheme "sigs.k8s.io/controller-runtime/pkg/scheme"
31
37
)
32
38
33
39
func TestSource (t * testing.T ) {
@@ -42,9 +48,17 @@ var clientset *kubernetes.Clientset
42
48
var _ = BeforeSuite (func (done Done ) {
43
49
logf .SetLogger (zap .LoggerTo (GinkgoWriter , true ))
44
50
45
- testenv = & envtest.Environment {}
51
+ err := (& crscheme.Builder {
52
+ GroupVersion : schema.GroupVersion {Group : "chaosapps.metamagical.io" , Version : "v1" },
53
+ }).
54
+ Register (& UnconventionalListType {}, & UnconventionalListTypeList {}).
55
+ AddToScheme (scheme .Scheme )
56
+ Expect (err ).To (BeNil ())
57
+
58
+ testenv = & envtest.Environment {
59
+ CRDDirectoryPaths : []string {"testdata/crds" },
60
+ }
46
61
47
- var err error
48
62
cfg , err = testenv .Start ()
49
63
Expect (err ).NotTo (HaveOccurred ())
50
64
@@ -63,3 +77,53 @@ var _ = AfterSuite(func() {
63
77
// Put the DefaultBindAddress back
64
78
metrics .DefaultBindAddress = ":8080"
65
79
})
80
+
81
+ var _ runtime.Object = & UnconventionalListType {}
82
+ var _ runtime.Object = & UnconventionalListTypeList {}
83
+
84
+ // UnconventionalListType is used to test CRDs with List types that
85
+ // have a slice of pointers rather than a slice of literals.
86
+ type UnconventionalListType struct {
87
+ metav1.TypeMeta `json:",inline"`
88
+ metav1.ObjectMeta `json:"metadata,omitempty"`
89
+ Spec string `json:"spec,omitempty"`
90
+ }
91
+
92
+ // DeepCopyObject implements runtime.Object
93
+ // Handwritten for simplicity.
94
+ func (u * UnconventionalListType ) DeepCopyObject () runtime.Object {
95
+ return u .DeepCopy ()
96
+ }
97
+
98
+ func (u * UnconventionalListType ) DeepCopy () * UnconventionalListType {
99
+ return & UnconventionalListType {
100
+ TypeMeta : u .TypeMeta ,
101
+ ObjectMeta : * u .ObjectMeta .DeepCopy (),
102
+ Spec : u .Spec ,
103
+ }
104
+ }
105
+
106
+ // UnconventionalListTypeList is used to test CRDs with List types that
107
+ // have a slice of pointers rather than a slice of literals.
108
+ type UnconventionalListTypeList struct {
109
+ metav1.TypeMeta `json:",inline"`
110
+ metav1.ListMeta `json:"metadata,omitempty"`
111
+ Items []* UnconventionalListType `json:"items"`
112
+ }
113
+
114
+ // DeepCopyObject implements runtime.Object
115
+ // Handwritten for simplicity.
116
+ func (u * UnconventionalListTypeList ) DeepCopyObject () runtime.Object {
117
+ return u .DeepCopy ()
118
+ }
119
+
120
+ func (u * UnconventionalListTypeList ) DeepCopy () * UnconventionalListTypeList {
121
+ out := & UnconventionalListTypeList {
122
+ TypeMeta : u .TypeMeta ,
123
+ ListMeta : * u .ListMeta .DeepCopy (),
124
+ }
125
+ for _ , item := range u .Items {
126
+ out .Items = append (out .Items , item .DeepCopy ())
127
+ }
128
+ return out
129
+ }
0 commit comments