Skip to content

Commit

Permalink
Merge pull request #2418 from sbueringer/pr-mgr-deadlock-test
Browse files Browse the repository at this point in the history
馃尡 Add integration test to avoid manager.Start deadlocks
  • Loading branch information
k8s-ci-robot committed Jul 25, 2023
2 parents 52ce239 + 3ecb530 commit cc1862e
Show file tree
Hide file tree
Showing 7 changed files with 598 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pkg/envtest/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,9 @@ func (te *Environment) Start() (*rest.Config, error) {
}

log.V(1).Info("installing CRDs")
if te.CRDInstallOptions.Scheme == nil {
te.CRDInstallOptions.Scheme = te.Scheme
}
te.CRDInstallOptions.CRDs = mergeCRDs(te.CRDInstallOptions.CRDs, te.CRDs)
te.CRDInstallOptions.Paths = mergePaths(te.CRDInstallOptions.Paths, te.CRDDirectoryPaths)
te.CRDInstallOptions.ErrorIfPathMissing = te.ErrorIfCRDPathMissing
Expand Down
93 changes: 93 additions & 0 deletions pkg/manager/internal/integration/api/v1/driver_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
Copyright 2023 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 v1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
)

// Driver is a test type.
type Driver struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
}

// DriverList is a list of Drivers.
type DriverList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []Driver `json:"items"`
}

func init() {
SchemeBuilder.Register(&Driver{}, &DriverList{})
}

// DeepCopyInto deep copies into the given Driver.
func (d *Driver) DeepCopyInto(out *Driver) {
*out = *d
out.TypeMeta = d.TypeMeta
d.ObjectMeta.DeepCopyInto(&out.ObjectMeta)
}

// DeepCopy returns a copy of Driver.
func (d *Driver) DeepCopy() *Driver {
if d == nil {
return nil
}
out := new(Driver)
d.DeepCopyInto(out)
return out
}

// DeepCopyObject returns a copy of Driver as runtime.Object.
func (d *Driver) DeepCopyObject() runtime.Object {
return d.DeepCopy()
}

// DeepCopyInto deep copies into the given DriverList.
func (in *DriverList) DeepCopyInto(out *DriverList) {
*out = *in
out.TypeMeta = in.TypeMeta
in.ListMeta.DeepCopyInto(&out.ListMeta)
if in.Items != nil {
in, out := &in.Items, &out.Items
*out = make([]Driver, len(*in))
for i := range *in {
(*in)[i].DeepCopyInto(&(*out)[i])
}
}
}

// DeepCopy returns a copy of DriverList.
func (in *DriverList) DeepCopy() *DriverList {
if in == nil {
return nil
}
out := new(DriverList)
in.DeepCopyInto(out)
return out
}

// DeepCopyObject returns a copy of DriverList as runtime.Object.
func (in *DriverList) DeepCopyObject() runtime.Object {
return in.DeepCopy()
}

// Hub marks Driver as a Hub for conversion.
func (*Driver) Hub() {}
34 changes: 34 additions & 0 deletions pkg/manager/internal/integration/api/v1/groupversion_info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
Copyright 2023 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 v1

import (
"k8s.io/apimachinery/pkg/runtime/schema"

"sigs.k8s.io/controller-runtime/pkg/scheme"
)

var (
// GroupVersion is group version used to register these objects.
GroupVersion = schema.GroupVersion{Group: "crew.example.com", Version: "v1"}

// SchemeBuilder is used to add go types to the GroupVersionKind scheme.
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}

// AddToScheme adds the types in this group-version to the given scheme.
AddToScheme = SchemeBuilder.AddToScheme
)
111 changes: 111 additions & 0 deletions pkg/manager/internal/integration/api/v2/driver_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/*
Copyright 2023 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 v2

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"

"sigs.k8s.io/controller-runtime/pkg/conversion"
v1 "sigs.k8s.io/controller-runtime/pkg/manager/internal/integration/api/v1"
)

// Driver is a test type.
type Driver struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
}

// DriverList is a list of Drivers.
type DriverList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []Driver `json:"items"`
}

func init() {
SchemeBuilder.Register(&Driver{}, &DriverList{})
}

// DeepCopyInto deep copies into the given Driver.
func (d *Driver) DeepCopyInto(out *Driver) {
*out = *d
out.TypeMeta = d.TypeMeta
d.ObjectMeta.DeepCopyInto(&out.ObjectMeta)
}

// DeepCopy returns a copy of Driver.
func (d *Driver) DeepCopy() *Driver {
if d == nil {
return nil
}
out := new(Driver)
d.DeepCopyInto(out)
return out
}

// DeepCopyObject returns a copy of Driver as runtime.Object.
func (d *Driver) DeepCopyObject() runtime.Object {
return d.DeepCopy()
}

// DeepCopyInto deep copies into the given DriverList.
func (in *DriverList) DeepCopyInto(out *DriverList) {
*out = *in
out.TypeMeta = in.TypeMeta
in.ListMeta.DeepCopyInto(&out.ListMeta)
if in.Items != nil {
in, out := &in.Items, &out.Items
*out = make([]Driver, len(*in))
for i := range *in {
(*in)[i].DeepCopyInto(&(*out)[i])
}
}
}

// DeepCopy returns a copy of DriverList.
func (in *DriverList) DeepCopy() *DriverList {
if in == nil {
return nil
}
out := new(DriverList)
in.DeepCopyInto(out)
return out
}

// DeepCopyObject returns a copy of DriverList as runtime.Object.
func (in *DriverList) DeepCopyObject() runtime.Object {
return in.DeepCopy()
}

// ConvertTo converts Driver to the Hub version of driver.
func (d *Driver) ConvertTo(dstRaw conversion.Hub) error {
dst := dstRaw.(*v1.Driver)
dst.Name = d.Name
dst.Namespace = d.Namespace
dst.UID = d.UID
return nil
}

// ConvertFrom converts Driver from the Hub version of driver.
func (d *Driver) ConvertFrom(srcRaw conversion.Hub) error {
src := srcRaw.(*v1.Driver)
d.Name = src.Name
d.Namespace = src.Namespace
d.UID = src.UID
return nil
}
34 changes: 34 additions & 0 deletions pkg/manager/internal/integration/api/v2/groupversion_info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
Copyright 2023 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 v2

import (
"k8s.io/apimachinery/pkg/runtime/schema"

"sigs.k8s.io/controller-runtime/pkg/scheme"
)

var (
// GroupVersion is group version used to register these objects.
GroupVersion = schema.GroupVersion{Group: "crew.example.com", Version: "v2"}

// SchemeBuilder is used to add go types to the GroupVersionKind scheme.
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}

// AddToScheme adds the types in this group-version to the given scheme.
AddToScheme = SchemeBuilder.AddToScheme
)
29 changes: 29 additions & 0 deletions pkg/manager/internal/integration/manager_suite_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
Copyright 2023 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 integration

import (
"testing"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)

func TestManager(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Manager Integration Suite")
}
Loading

0 comments on commit cc1862e

Please sign in to comment.