diff --git a/pkg/manager/manager_options_test.go b/pkg/manager/manager_options_test.go new file mode 100644 index 0000000000..5b97bb183d --- /dev/null +++ b/pkg/manager/manager_options_test.go @@ -0,0 +1,43 @@ +package manager + +import ( + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" + + "sigs.k8s.io/controller-runtime/pkg/config" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" + configv1alpha1 "sigs.k8s.io/controller-runtime/pkg/config/v1alpha1" +) + +var _ = Describe("manager.Options", func() { + Describe("AndFrom", func() { + Describe("reading custom type using OfKind", func() { + It("should not panic when leaderelection is not set", func() { + s := runtime.NewScheme() + o := Options{ + Scheme: s, + LeaderElection: true, + } + c := customConfig{} + _, err := o.AndFrom(config.File().AtPath("./testdata/custom-config.yaml").OfKind(&c)) + Expect(err).To(Succeed()) + }) + }) + }) +}) + +type customConfig struct { + metav1.TypeMeta `json:",inline"` + configv1alpha1.ControllerManagerConfigurationSpec `json:",inline"` +} + +func (in *customConfig) DeepCopyObject() runtime.Object { + out := &customConfig{} + *out = *in + + in.ControllerManagerConfigurationSpec.DeepCopyInto(&out.ControllerManagerConfigurationSpec) + + return out +} diff --git a/pkg/manager/testdata/custom-config.yaml b/pkg/manager/testdata/custom-config.yaml new file mode 100644 index 0000000000..a15c9f8e5c --- /dev/null +++ b/pkg/manager/testdata/custom-config.yaml @@ -0,0 +1,3 @@ +apiVersion: controller-runtime.sigs.k8s.io/v1alpha1 +kind: CustomControllerManagerConfiguration +customValue: foo