Skip to content

Commit

Permalink
fix: added controller config validation (#2103)
Browse files Browse the repository at this point in the history
* fix: make webhook url optional

Signed-off-by: Daniel Soifer <[email protected]>
  • Loading branch information
daniel-codefresh authored and whynowy committed Sep 10, 2022
1 parent ea02369 commit 081ac2f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
7 changes: 6 additions & 1 deletion controllers/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,16 @@ const (
func Start(namespaced bool, managedNamespace string) {
logger := logging.NewArgoEventsLogger().Named(eventbus.ControllerName)
config, err := controllers.LoadConfig(func(err error) {
logger.Errorf("Failed to reload global configuration file", zap.Error(err))
logger.Errorw("Failed to reload global configuration file", zap.Error(err))
})
if err != nil {
logger.Fatalw("Failed to load global configuration file", zap.Error(err))
}

if err = controllers.ValidateConfig(config); err != nil {
logger.Fatalw("Global configuration file validation failed", zap.Error(err))
}

imageName, defined := os.LookupEnv(imageEnvVar)
if !defined {
logger.Fatalf("required environment variable '%s' not defined", imageEnvVar)
Expand Down
12 changes: 12 additions & 0 deletions controllers/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,15 @@ func LoadConfig(onErrorReloading func(error)) (*GlobalConfig, error) {
})
return r, nil
}

func ValidateConfig(config *GlobalConfig) error {
if len(config.supportedJetStreamVersions()) == 0 {
return fmt.Errorf("no jetstream versions were provided in the controller config")
}

if len(config.supportedSTANVersions()) == 0 {
return fmt.Errorf("no stan versions were provided in the controller config")
}

return nil
}

0 comments on commit 081ac2f

Please sign in to comment.