@@ -74,6 +74,54 @@ var _ = Describe("controller.Controller", func() {
7474 Expect (c2 ).To (BeNil ())
7575 })
7676
77+ It ("should return an error if two controllers are registered with the same name and SkipNameValidation is set to false on the manager" , func () {
78+ m , err := manager .New (cfg , manager.Options {
79+ Controller : config.Controller {
80+ SkipNameValidation : ptr .To (false ),
81+ },
82+ })
83+ Expect (err ).NotTo (HaveOccurred ())
84+
85+ c1 , err := controller .New ("c4" , m , controller.Options {Reconciler : rec })
86+ Expect (err ).NotTo (HaveOccurred ())
87+ Expect (c1 ).ToNot (BeNil ())
88+
89+ c2 , err := controller .New ("c4" , m , controller.Options {Reconciler : rec })
90+ Expect (err ).To (HaveOccurred ())
91+ Expect (err .Error ()).To (ContainSubstring ("controller with name c4 already exists" ))
92+ Expect (c2 ).To (BeNil ())
93+ })
94+
95+ It ("should not return an error if two controllers are registered with the same name and SkipNameValidation is set on the manager" , func () {
96+ m , err := manager .New (cfg , manager.Options {
97+ Controller : config.Controller {
98+ SkipNameValidation : ptr .To (true ),
99+ },
100+ })
101+ Expect (err ).NotTo (HaveOccurred ())
102+
103+ c1 , err := controller .New ("c5" , m , controller.Options {Reconciler : rec })
104+ Expect (err ).NotTo (HaveOccurred ())
105+ Expect (c1 ).ToNot (BeNil ())
106+
107+ c2 , err := controller .New ("c5" , m , controller.Options {Reconciler : rec })
108+ Expect (err ).NotTo (HaveOccurred ())
109+ Expect (c2 ).ToNot (BeNil ())
110+ })
111+
112+ It ("should not return an error if two controllers are registered with the same name and SkipNameValidation is set on the controller" , func () {
113+ m , err := manager .New (cfg , manager.Options {})
114+ Expect (err ).NotTo (HaveOccurred ())
115+
116+ c1 , err := controller .New ("c6" , m , controller.Options {Reconciler : rec })
117+ Expect (err ).NotTo (HaveOccurred ())
118+ Expect (c1 ).ToNot (BeNil ())
119+
120+ c2 , err := controller .New ("c6" , m , controller.Options {Reconciler : rec , SkipNameValidation : ptr .To (true )})
121+ Expect (err ).NotTo (HaveOccurred ())
122+ Expect (c2 ).ToNot (BeNil ())
123+ })
124+
77125 It ("should not return an error if two controllers are registered with different names" , func () {
78126 m , err := manager .New (cfg , manager.Options {})
79127 Expect (err ).NotTo (HaveOccurred ())
0 commit comments