You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When re-using the same name among multiple controllers, they will report
to the same metrics and use the same logger. This can be very confusing,
might not be obvious and can happen accidentally.
Validate controller names are unique at runtime to avoid all of this.
Copy file name to clipboardexpand all lines: pkg/builder/controller_test.go
+18-6
Original file line number
Diff line number
Diff line change
@@ -142,7 +142,7 @@ var _ = Describe("application", func() {
142
142
Expect(err).NotTo(HaveOccurred())
143
143
144
144
instance, err:=ControllerManagedBy(m).
145
-
Named("my_controller").
145
+
Named("my_new_controller").
146
146
Build(noop)
147
147
Expect(err).To(MatchError(ContainSubstring("there are no watches configured, controller will never get triggered. Use For(), Owns(), Watches() or WatchesRawSource() to set them up")))
148
148
Expect(instance).To(BeNil())
@@ -154,7 +154,7 @@ var _ = Describe("application", func() {
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 controller
18
+
19
+
import (
20
+
"fmt"
21
+
"sync"
22
+
23
+
"k8s.io/apimachinery/pkg/util/sets"
24
+
)
25
+
26
+
varnameLock sync.Mutex
27
+
varusedNamed sets.Set[string]
28
+
29
+
funccheckName(namestring) error {
30
+
nameLock.Lock()
31
+
defernameLock.Unlock()
32
+
ifusedNamed==nil {
33
+
usedNamed= sets.Set[string]{}
34
+
}
35
+
36
+
ifusedNamed.Has(name) {
37
+
returnfmt.Errorf("controller with name %s already exists. Controller names must be unique to avoid multiple controllers reporting to the same metric", name)
0 commit comments