Skip to content

Commit f9cff45

Browse files
committed
Add regression test
1 parent d5a6c49 commit f9cff45

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

pkg/manager/manager_options_test.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package manager
2+
3+
import (
4+
. "github.com/onsi/ginkgo"
5+
. "github.com/onsi/gomega"
6+
7+
"sigs.k8s.io/controller-runtime/pkg/config"
8+
9+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
10+
"k8s.io/apimachinery/pkg/runtime"
11+
configv1alpha1 "sigs.k8s.io/controller-runtime/pkg/config/v1alpha1"
12+
)
13+
14+
var _ = Describe("manager.Options", func() {
15+
Describe("AndFrom", func() {
16+
Describe("reading custom type using OfKind", func() {
17+
It("should not panic when leaderelection is not set", func() {
18+
s := runtime.NewScheme()
19+
o := Options{
20+
Scheme: s,
21+
LeaderElection: true,
22+
}
23+
c := customConfig{}
24+
_, err := o.AndFrom(config.File().AtPath("./testdata/custom-config.yaml").OfKind(&c))
25+
Expect(err).To(Succeed())
26+
})
27+
})
28+
})
29+
})
30+
31+
type customConfig struct {
32+
metav1.TypeMeta `json:",inline"`
33+
configv1alpha1.ControllerManagerConfigurationSpec `json:",inline"`
34+
}
35+
36+
func (in *customConfig) DeepCopyObject() runtime.Object {
37+
out := &customConfig{}
38+
*out = *in
39+
40+
in.ControllerManagerConfigurationSpec.DeepCopyInto(&out.ControllerManagerConfigurationSpec)
41+
42+
return out
43+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
apiVersion: controller-runtime.sigs.k8s.io/v1alpha1
2+
kind: CustomControllerManagerConfiguration
3+
customValue: foo

0 commit comments

Comments
 (0)