Skip to content

Commit cc1862e

Browse files
authored
Merge pull request #2418 from sbueringer/pr-mgr-deadlock-test
🌱 Add integration test to avoid manager.Start deadlocks
2 parents 52ce239 + 3ecb530 commit cc1862e

File tree

7 files changed

+598
-0
lines changed

7 files changed

+598
-0
lines changed

pkg/envtest/server.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,9 @@ func (te *Environment) Start() (*rest.Config, error) {
289289
}
290290

291291
log.V(1).Info("installing CRDs")
292+
if te.CRDInstallOptions.Scheme == nil {
293+
te.CRDInstallOptions.Scheme = te.Scheme
294+
}
292295
te.CRDInstallOptions.CRDs = mergeCRDs(te.CRDInstallOptions.CRDs, te.CRDs)
293296
te.CRDInstallOptions.Paths = mergePaths(te.CRDInstallOptions.Paths, te.CRDDirectoryPaths)
294297
te.CRDInstallOptions.ErrorIfPathMissing = te.ErrorIfCRDPathMissing
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*
2+
Copyright 2023 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1
18+
19+
import (
20+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21+
"k8s.io/apimachinery/pkg/runtime"
22+
)
23+
24+
// Driver is a test type.
25+
type Driver struct {
26+
metav1.TypeMeta `json:",inline"`
27+
metav1.ObjectMeta `json:"metadata,omitempty"`
28+
}
29+
30+
// DriverList is a list of Drivers.
31+
type DriverList struct {
32+
metav1.TypeMeta `json:",inline"`
33+
metav1.ListMeta `json:"metadata,omitempty"`
34+
Items []Driver `json:"items"`
35+
}
36+
37+
func init() {
38+
SchemeBuilder.Register(&Driver{}, &DriverList{})
39+
}
40+
41+
// DeepCopyInto deep copies into the given Driver.
42+
func (d *Driver) DeepCopyInto(out *Driver) {
43+
*out = *d
44+
out.TypeMeta = d.TypeMeta
45+
d.ObjectMeta.DeepCopyInto(&out.ObjectMeta)
46+
}
47+
48+
// DeepCopy returns a copy of Driver.
49+
func (d *Driver) DeepCopy() *Driver {
50+
if d == nil {
51+
return nil
52+
}
53+
out := new(Driver)
54+
d.DeepCopyInto(out)
55+
return out
56+
}
57+
58+
// DeepCopyObject returns a copy of Driver as runtime.Object.
59+
func (d *Driver) DeepCopyObject() runtime.Object {
60+
return d.DeepCopy()
61+
}
62+
63+
// DeepCopyInto deep copies into the given DriverList.
64+
func (in *DriverList) DeepCopyInto(out *DriverList) {
65+
*out = *in
66+
out.TypeMeta = in.TypeMeta
67+
in.ListMeta.DeepCopyInto(&out.ListMeta)
68+
if in.Items != nil {
69+
in, out := &in.Items, &out.Items
70+
*out = make([]Driver, len(*in))
71+
for i := range *in {
72+
(*in)[i].DeepCopyInto(&(*out)[i])
73+
}
74+
}
75+
}
76+
77+
// DeepCopy returns a copy of DriverList.
78+
func (in *DriverList) DeepCopy() *DriverList {
79+
if in == nil {
80+
return nil
81+
}
82+
out := new(DriverList)
83+
in.DeepCopyInto(out)
84+
return out
85+
}
86+
87+
// DeepCopyObject returns a copy of DriverList as runtime.Object.
88+
func (in *DriverList) DeepCopyObject() runtime.Object {
89+
return in.DeepCopy()
90+
}
91+
92+
// Hub marks Driver as a Hub for conversion.
93+
func (*Driver) Hub() {}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
Copyright 2023 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1
18+
19+
import (
20+
"k8s.io/apimachinery/pkg/runtime/schema"
21+
22+
"sigs.k8s.io/controller-runtime/pkg/scheme"
23+
)
24+
25+
var (
26+
// GroupVersion is group version used to register these objects.
27+
GroupVersion = schema.GroupVersion{Group: "crew.example.com", Version: "v1"}
28+
29+
// SchemeBuilder is used to add go types to the GroupVersionKind scheme.
30+
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}
31+
32+
// AddToScheme adds the types in this group-version to the given scheme.
33+
AddToScheme = SchemeBuilder.AddToScheme
34+
)
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
/*
2+
Copyright 2023 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v2
18+
19+
import (
20+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21+
"k8s.io/apimachinery/pkg/runtime"
22+
23+
"sigs.k8s.io/controller-runtime/pkg/conversion"
24+
v1 "sigs.k8s.io/controller-runtime/pkg/manager/internal/integration/api/v1"
25+
)
26+
27+
// Driver is a test type.
28+
type Driver struct {
29+
metav1.TypeMeta `json:",inline"`
30+
metav1.ObjectMeta `json:"metadata,omitempty"`
31+
}
32+
33+
// DriverList is a list of Drivers.
34+
type DriverList struct {
35+
metav1.TypeMeta `json:",inline"`
36+
metav1.ListMeta `json:"metadata,omitempty"`
37+
Items []Driver `json:"items"`
38+
}
39+
40+
func init() {
41+
SchemeBuilder.Register(&Driver{}, &DriverList{})
42+
}
43+
44+
// DeepCopyInto deep copies into the given Driver.
45+
func (d *Driver) DeepCopyInto(out *Driver) {
46+
*out = *d
47+
out.TypeMeta = d.TypeMeta
48+
d.ObjectMeta.DeepCopyInto(&out.ObjectMeta)
49+
}
50+
51+
// DeepCopy returns a copy of Driver.
52+
func (d *Driver) DeepCopy() *Driver {
53+
if d == nil {
54+
return nil
55+
}
56+
out := new(Driver)
57+
d.DeepCopyInto(out)
58+
return out
59+
}
60+
61+
// DeepCopyObject returns a copy of Driver as runtime.Object.
62+
func (d *Driver) DeepCopyObject() runtime.Object {
63+
return d.DeepCopy()
64+
}
65+
66+
// DeepCopyInto deep copies into the given DriverList.
67+
func (in *DriverList) DeepCopyInto(out *DriverList) {
68+
*out = *in
69+
out.TypeMeta = in.TypeMeta
70+
in.ListMeta.DeepCopyInto(&out.ListMeta)
71+
if in.Items != nil {
72+
in, out := &in.Items, &out.Items
73+
*out = make([]Driver, len(*in))
74+
for i := range *in {
75+
(*in)[i].DeepCopyInto(&(*out)[i])
76+
}
77+
}
78+
}
79+
80+
// DeepCopy returns a copy of DriverList.
81+
func (in *DriverList) DeepCopy() *DriverList {
82+
if in == nil {
83+
return nil
84+
}
85+
out := new(DriverList)
86+
in.DeepCopyInto(out)
87+
return out
88+
}
89+
90+
// DeepCopyObject returns a copy of DriverList as runtime.Object.
91+
func (in *DriverList) DeepCopyObject() runtime.Object {
92+
return in.DeepCopy()
93+
}
94+
95+
// ConvertTo converts Driver to the Hub version of driver.
96+
func (d *Driver) ConvertTo(dstRaw conversion.Hub) error {
97+
dst := dstRaw.(*v1.Driver)
98+
dst.Name = d.Name
99+
dst.Namespace = d.Namespace
100+
dst.UID = d.UID
101+
return nil
102+
}
103+
104+
// ConvertFrom converts Driver from the Hub version of driver.
105+
func (d *Driver) ConvertFrom(srcRaw conversion.Hub) error {
106+
src := srcRaw.(*v1.Driver)
107+
d.Name = src.Name
108+
d.Namespace = src.Namespace
109+
d.UID = src.UID
110+
return nil
111+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
Copyright 2023 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v2
18+
19+
import (
20+
"k8s.io/apimachinery/pkg/runtime/schema"
21+
22+
"sigs.k8s.io/controller-runtime/pkg/scheme"
23+
)
24+
25+
var (
26+
// GroupVersion is group version used to register these objects.
27+
GroupVersion = schema.GroupVersion{Group: "crew.example.com", Version: "v2"}
28+
29+
// SchemeBuilder is used to add go types to the GroupVersionKind scheme.
30+
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}
31+
32+
// AddToScheme adds the types in this group-version to the given scheme.
33+
AddToScheme = SchemeBuilder.AddToScheme
34+
)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
Copyright 2023 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package integration
18+
19+
import (
20+
"testing"
21+
22+
. "github.com/onsi/ginkgo/v2"
23+
. "github.com/onsi/gomega"
24+
)
25+
26+
func TestManager(t *testing.T) {
27+
RegisterFailHandler(Fail)
28+
RunSpecs(t, "Manager Integration Suite")
29+
}

0 commit comments

Comments
 (0)