diff --git a/cmd/controller/main.go b/cmd/controller/main.go index 03a64c81dda2..d729db7bd2a5 100644 --- a/cmd/controller/main.go +++ b/cmd/controller/main.go @@ -102,7 +102,7 @@ func main() { // Build all of our controllers, with the clients constructed above. // Add new controllers to this array. - controllers := []*controller.Impl{ + controllers := [...]*controller.Impl{ configuration.NewController( opt, configurationInformer, @@ -147,9 +147,12 @@ func main() { endpointsInformer, ), } - if len(controllers) != numControllers { - logger.Fatalf("Number of controllers and QPS settings mismatch: %d != %d", len(controllers), numControllers) - } + // This line asserts at compile time that the length of controllers is equal to numControllers. + // It is based on https://go101.org/article/tips.html#assert-at-compile-time, which notes that + // var _ [N-M]int + // asserts at compile time that N >= M, which we can use to establish equality of N and M: + // (N >= M) && (M >= N) => (N == M) + var _ [numControllers - len(controllers)][len(controllers) - numControllers]int // Watch the logging config map and dynamically update logging levels. opt.ConfigMapWatcher.Watch(logging.ConfigMapName(), logging.UpdateLevelFromConfigMap(logger, atomicLevel, component)) @@ -181,7 +184,7 @@ func main() { // Start all of the controllers. logger.Info("Starting controllers.") - controller.StartAll(stopCh, controllers...) + controller.StartAll(stopCh, controllers[:]...) } func flush(logger *zap.SugaredLogger) {