You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by nf...@apache.org on 2022/08/31 15:30:12 UTC
[camel-k] 01/01: fix: Prevent panic on wrong kamelet binding
This is an automated email from the ASF dual-hosted git repository.
nfilotto pushed a commit to branch 3586/avoid-panic-on-wrong-kamelet-binding
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit 236f9aa8a34d0e8df690cb86061d3f51fe998d58
Author: Nicolas Filotto <nf...@talend.com>
AuthorDate: Wed Aug 31 15:20:01 2022 +0200
fix: Prevent panic on wrong kamelet binding
---
pkg/controller/kameletbinding/error_handler.go | 16 +++++++++++++---
pkg/controller/kameletbinding/error_handler_test.go | 15 +++++++++++++++
2 files changed, 28 insertions(+), 3 deletions(-)
diff --git a/pkg/controller/kameletbinding/error_handler.go b/pkg/controller/kameletbinding/error_handler.go
index f7dc600f4..643e9d843 100644
--- a/pkg/controller/kameletbinding/error_handler.go
+++ b/pkg/controller/kameletbinding/error_handler.go
@@ -87,17 +87,27 @@ func parseErrorHandler(rawMessage v1alpha1.RawMessage) (v1alpha1.ErrorHandler, e
return nil, err
}
- return dst, nil
+ return verifyErrorHandler(dst)
}
return nil, errors.New("You must provide any supported error handler")
}
-func setErrorHandlerConfiguration(errorHandlerBinding *bindings.Binding, errorHandler v1alpha1.ErrorHandler) error {
+func verifyErrorHandler(errorHandler v1alpha1.ErrorHandler) (v1alpha1.ErrorHandler, error) {
properties, err := errorHandler.Configuration()
if err != nil {
- return err
+ return nil, err
+ } else if properties == nil {
+ return nil, errors.New("The properties of the error handler could not be found")
+ }
+ if errorHandler.Type() == v1alpha1.ErrorHandlerTypeSink && errorHandler.Endpoint() == nil {
+ return nil, errors.New("The endpoint of the error handler could not be found")
}
+ return errorHandler, nil
+}
+
+func setErrorHandlerConfiguration(errorHandlerBinding *bindings.Binding, errorHandler v1alpha1.ErrorHandler) error {
+ properties, _ := errorHandler.Configuration()
// initialize map if not yet initialized
if errorHandlerBinding.ApplicationProperties == nil {
errorHandlerBinding.ApplicationProperties = make(map[string]string)
diff --git a/pkg/controller/kameletbinding/error_handler_test.go b/pkg/controller/kameletbinding/error_handler_test.go
index b6dab3923..818ca6ed8 100644
--- a/pkg/controller/kameletbinding/error_handler_test.go
+++ b/pkg/controller/kameletbinding/error_handler_test.go
@@ -101,3 +101,18 @@ func TestParseErrorHandlerSinkWithParametersDoesSucceed(t *testing.T) {
assert.Equal(t, "value1", parameters["camel.beans.defaultErrorHandler.param1"])
assert.Equal(t, "value2", parameters["camel.beans.defaultErrorHandler.param2"])
}
+
+func TestParseErrorHandlerWithWrongDefinition(t *testing.T) {
+ _, err := parseErrorHandler(
+ []byte(`{
+ "sink": {
+ "ref": {
+ "kind": "Kamelet",
+ "apiVersion": "camel.apache.org/v1alpha1",
+ "name": "err-sink"
+ }
+ }
+ }`),
+ )
+ assert.NotNil(t, err)
+}