From 8314d174be0d5cc41bc628f0c4c217b304cce784 Mon Sep 17 00:00:00 2001 From: Daniel Soifer Date: Sun, 24 Jul 2022 13:21:45 +0300 Subject: [PATCH 1/2] fix: make webhook url optional Signed-off-by: Daniel Soifer --- pkg/apis/eventsource/v1alpha1/webhook_context.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pkg/apis/eventsource/v1alpha1/webhook_context.go b/pkg/apis/eventsource/v1alpha1/webhook_context.go index d261ded9ef..db8710144b 100644 --- a/pkg/apis/eventsource/v1alpha1/webhook_context.go +++ b/pkg/apis/eventsource/v1alpha1/webhook_context.go @@ -16,10 +16,13 @@ type WebhookContext struct { // Port on which HTTP server is listening for incoming events. Port string `json:"port" protobuf:"bytes,3,opt,name=port"` // URL is the url of the server. - URL string `json:"url" protobuf:"bytes,4,opt,name=url"` + // +optional + URL string `json:"url,omitempty" protobuf:"bytes,4,opt,name=url"` // ServerCertPath refers the file that contains the cert. + // +optional ServerCertSecret *corev1.SecretKeySelector `json:"serverCertSecret,omitempty" protobuf:"bytes,5,opt,name=serverCertSecret"` // ServerKeyPath refers the file that contains private key + // +optional ServerKeySecret *corev1.SecretKeySelector `json:"serverKeySecret,omitempty" protobuf:"bytes,6,opt,name=serverKeySecret"` // Metadata holds the user defined metadata which will passed along the event payload. // +optional From 29346df27d32313f5809304c261d5d330b060de8 Mon Sep 17 00:00:00 2001 From: Daniel Soifer Date: Sun, 24 Jul 2022 15:31:12 +0300 Subject: [PATCH 2/2] fix: added controller config validation Signed-off-by: Daniel Soifer --- controllers/cmd/start.go | 7 ++++++- controllers/config.go | 12 ++++++++++++ pkg/apis/eventsource/v1alpha1/webhook_context.go | 5 +---- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/controllers/cmd/start.go b/controllers/cmd/start.go index fc699dfc73..3b74fcb2d4 100644 --- a/controllers/cmd/start.go +++ b/controllers/cmd/start.go @@ -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) diff --git a/controllers/config.go b/controllers/config.go index b31dfe9b6e..c64365ea1b 100644 --- a/controllers/config.go +++ b/controllers/config.go @@ -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 +} diff --git a/pkg/apis/eventsource/v1alpha1/webhook_context.go b/pkg/apis/eventsource/v1alpha1/webhook_context.go index db8710144b..d261ded9ef 100644 --- a/pkg/apis/eventsource/v1alpha1/webhook_context.go +++ b/pkg/apis/eventsource/v1alpha1/webhook_context.go @@ -16,13 +16,10 @@ type WebhookContext struct { // Port on which HTTP server is listening for incoming events. Port string `json:"port" protobuf:"bytes,3,opt,name=port"` // URL is the url of the server. - // +optional - URL string `json:"url,omitempty" protobuf:"bytes,4,opt,name=url"` + URL string `json:"url" protobuf:"bytes,4,opt,name=url"` // ServerCertPath refers the file that contains the cert. - // +optional ServerCertSecret *corev1.SecretKeySelector `json:"serverCertSecret,omitempty" protobuf:"bytes,5,opt,name=serverCertSecret"` // ServerKeyPath refers the file that contains private key - // +optional ServerKeySecret *corev1.SecretKeySelector `json:"serverKeySecret,omitempty" protobuf:"bytes,6,opt,name=serverKeySecret"` // Metadata holds the user defined metadata which will passed along the event payload. // +optional