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:53 UTC

[camel-k] branch 3586/avoid-panic-on-wrong-kamelet-binding updated (236f9aa8a -> 12795356d)

This is an automated email from the ASF dual-hosted git repository.

nfilotto pushed a change to branch 3586/avoid-panic-on-wrong-kamelet-binding
in repository https://gitbox.apache.org/repos/asf/camel-k.git


 discard 236f9aa8a fix: Prevent panic on wrong kamelet binding
     new 12795356d fix: Prevent panic on wrong Kamelet binding

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (236f9aa8a)
            \
             N -- N -- N   refs/heads/3586/avoid-panic-on-wrong-kamelet-binding (12795356d)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:


[camel-k] 01/01: fix: Prevent panic on wrong Kamelet binding

Posted by nf...@apache.org.
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 12795356d713a5f3e4b47e94781c8d009bb77ecd
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)
+}