You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by pc...@apache.org on 2021/12/28 10:19:56 UTC

[camel-k] branch main updated (fef775d -> db75003)

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

pcongiusti pushed a change to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git.


    from fef775d  Updated CHANGELOG.md
     new 2c58b44  chore(kamelet): remove bean and ref error handler types
     new db75003  chore(kamelet): rename error handler DLC to Sink

The 2 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:
 .../kamelets/kameletbindings-error-handler.adoc    |  63 ++--------
 docs/modules/ROOT/partials/apis/crds-html.adoc     | 130 +++++----------------
 e2e/common/kamelet_binding_test.go                 |   2 +-
 .../kamelet-binding-error-handler.yaml             |   2 +-
 examples/kamelets/error-handler/readme.md          |   6 +-
 pkg/apis/camel/v1/zz_generated.deepcopy.go         |   8 ++
 pkg/apis/camel/v1alpha1/error_handler_types.go     |  81 ++-----------
 pkg/apis/camel/v1alpha1/zz_generated.deepcopy.go   |  66 ++---------
 pkg/cmd/bind.go                                    |  19 +--
 pkg/cmd/bind_test.go                               |  10 +-
 pkg/controller/kameletbinding/error_handler.go     |  13 +--
 .../kameletbinding/error_handler_test.go           |  59 +++-------
 12 files changed, 99 insertions(+), 360 deletions(-)

[camel-k] 02/02: chore(kamelet): rename error handler DLC to Sink

Posted by pc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

pcongiusti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git

commit db75003b2fbbb395dfada1d4b7a143d19efb7328
Author: Pasquale Congiusti <pa...@gmail.com>
AuthorDate: Mon Dec 27 11:03:23 2021 +0100

    chore(kamelet): rename error handler DLC to Sink
    
    Closes #2815
---
 .../kamelets/kameletbindings-error-handler.adoc    |  14 +--
 docs/modules/ROOT/partials/apis/crds-html.adoc     | 130 +++++----------------
 e2e/common/kamelet_binding_test.go                 |   2 +-
 .../kamelet-binding-error-handler.yaml             |   2 +-
 examples/kamelets/error-handler/readme.md          |   6 +-
 pkg/apis/camel/v1alpha1/error_handler_types.go     |  16 +--
 pkg/apis/camel/v1alpha1/zz_generated.deepcopy.go   |  42 +++----
 pkg/cmd/bind.go                                    |  13 +--
 pkg/cmd/bind_test.go                               |   4 +-
 pkg/controller/kameletbinding/error_handler.go     |   9 +-
 .../kameletbinding/error_handler_test.go           |  28 ++---
 11 files changed, 99 insertions(+), 167 deletions(-)

diff --git a/docs/modules/ROOT/pages/kamelets/kameletbindings-error-handler.adoc b/docs/modules/ROOT/pages/kamelets/kameletbindings-error-handler.adoc
index 648e05b..3b5022e 100644
--- a/docs/modules/ROOT/pages/kamelets/kameletbindings-error-handler.adoc
+++ b/docs/modules/ROOT/pages/kamelets/kameletbindings-error-handler.adoc
@@ -1,7 +1,7 @@
 [[kameletbindings-error-handler]]
 = Kamelet Bindings Error Handler
 
-Kamelet Binding`s offer a mechanism to specify an error policy to adopt in case an event produced by a `source` or consumed by a `sink`. Through the definition of an `errorHandler` you will be able to apply certain logic to the failing event, such as simply logging, ignoring the event or posting the event to a `Dead Letter Channel`.
+Kamelet Binding`s offer a mechanism to specify an error policy to adopt in case an event produced by a `source` or consumed by a `sink`. Through the definition of an `errorHandler` you will be able to apply certain logic to the failing event, such as simply logging, ignoring the event or posting the event to a `Sink`.
 
 [source,yaml]
 ----
@@ -23,7 +23,7 @@ spec:
 [[kameletbindings-error-handler-types]]
 == Error Handler Types
 
-We have different types of error handler: `ǹone`, `log` and `dead-letter-channel`. The `errorHandler` parameter is optional.
+We have different types of error handler: `ǹone`, `log` and `sink`. The `errorHandler` parameter is optional.
 
 [[kameletbindings-error-handler-none]]
 === No error handler
@@ -70,10 +70,10 @@ spec:
 ----
 <1> Parameters belonging to the `log` error handler type
 
-[[kameletbindings-error-handler-dlc]]
-=== Dead Letter Channel error handler
+[[kameletbindings-error-handler-sink]]
+=== Sink error handler
 
-The `Dead Letter Channel` is probably the most interesting error handler type as it allows you to redirect any failing event to any other component, such as a third party URI, a queue or even another `Kamelet` which will be performing certain logic with the failing event.
+The `Sink` is probably the most interesting error handler type as it allows you to redirect any failing event to any other component, such as a third party URI, a queue or even another `Kamelet` which will be performing certain logic with the failing event.
 
 [source,yaml]
 ----
@@ -87,7 +87,7 @@ spec:
   sink: 
 ...
   errorHandler: 
-    dead-letter-channel:
+    sink:
       endpoint: 
         ref: # <1>
           kind: Kamelet
@@ -102,5 +102,5 @@ spec:
 ----
 <1> You can use `ref` or `uri`. `ref` will be interpreted by the operator according the `kind`, `apiVersion` and `name`. You can use any `Kamelet`, `KafkaTopic` channel or `Knative` destination.
 <2> Properties belonging to the endpoint (in this example, to the `Kamelet` named error handler)
-<3> Parameters belonging to the `dead-letter-channel` error handler type
+<3> Parameters belonging to the `sink` error handler type
 
diff --git a/docs/modules/ROOT/partials/apis/crds-html.adoc b/docs/modules/ROOT/partials/apis/crds-html.adoc
index 4adc586..80b5a3c 100644
--- a/docs/modules/ROOT/partials/apis/crds-html.adoc
+++ b/docs/modules/ROOT/partials/apis/crds-html.adoc
@@ -3090,6 +3090,16 @@ string
 <td>
 </td>
 </tr>
+<tr>
+<td>
+<code>info</code><br/>
+<em>
+map[string]string
+</em>
+</td>
+<td>
+</td>
+</tr>
 </tbody>
 </table>
 <h3 id="camel.apache.org/v1.IntegrationSpec">IntegrationSpec
@@ -4132,7 +4142,6 @@ RegistrySpec
 <a href="#camel.apache.org/v1alpha1.BeanProperties">BeanProperties</a>, 
 <a href="#camel.apache.org/v1alpha1.EndpointProperties">EndpointProperties</a>, 
 <a href="#camel.apache.org/v1alpha1.ErrorHandlerParameters">ErrorHandlerParameters</a>, 
-<a href="#camel.apache.org/v1alpha1.ErrorHandlerRef">ErrorHandlerRef</a>, 
 <a href="#camel.apache.org/v1alpha1.ErrorHandlerSpec">ErrorHandlerSpec</a>, 
 <a href="#camel.apache.org/v1.Flow">Flow</a>, 
 <a href="#camel.apache.org/v1.Template">Template</a>, 
@@ -5278,10 +5287,6 @@ KameletBindingStatus
 </div>
 <h3 id="camel.apache.org/v1alpha1.BeanProperties">BeanProperties
 </h3>
-<p>
-(<em>Appears on:</em>
-<a href="#camel.apache.org/v1alpha1.ErrorHandlerBean">ErrorHandlerBean</a>)
-</p>
 <div>
 <p>BeanProperties represent an unstructured object properties to be set on a bean</p>
 </div>
@@ -5311,7 +5316,7 @@ RawMessage
 </h3>
 <p>
 (<em>Appears on:</em>
-<a href="#camel.apache.org/v1alpha1.ErrorHandlerDeadLetterChannel">ErrorHandlerDeadLetterChannel</a>, 
+<a href="#camel.apache.org/v1alpha1.ErrorHandlerSink">ErrorHandlerSink</a>, 
 <a href="#camel.apache.org/v1alpha1.KameletBindingSpec">KameletBindingSpec</a>)
 </p>
 <div>
@@ -5420,99 +5425,11 @@ RawMessage
 <div>
 <p>ErrorHandler is a generic interface that represent any type of error handler specification</p>
 </div>
-<h3 id="camel.apache.org/v1alpha1.ErrorHandlerBean">ErrorHandlerBean
-</h3>
-<div>
-<p>ErrorHandlerBean represents a bean error handler type</p>
-</div>
-<table>
-<thead>
-<tr>
-<th>Field</th>
-<th>Description</th>
-</tr>
-</thead>
-<tbody>
-<tr>
-<td>
-<code>ErrorHandlerNone</code><br/>
-<em>
-<a href="#camel.apache.org/v1alpha1.ErrorHandlerNone">
-ErrorHandlerNone
-</a>
-</em>
-</td>
-<td>
-</td>
-</tr>
-<tr>
-<td>
-<code>type</code><br/>
-<em>
-string
-</em>
-</td>
-<td>
-</td>
-</tr>
-<tr>
-<td>
-<code>properties</code><br/>
-<em>
-<a href="#camel.apache.org/v1alpha1.BeanProperties">
-BeanProperties
-</a>
-</em>
-</td>
-<td>
-</td>
-</tr>
-</tbody>
-</table>
-<h3 id="camel.apache.org/v1alpha1.ErrorHandlerDeadLetterChannel">ErrorHandlerDeadLetterChannel
-</h3>
-<div>
-<p>ErrorHandlerDeadLetterChannel represents a dead letter channel error handler type</p>
-</div>
-<table>
-<thead>
-<tr>
-<th>Field</th>
-<th>Description</th>
-</tr>
-</thead>
-<tbody>
-<tr>
-<td>
-<code>ErrorHandlerLog</code><br/>
-<em>
-<a href="#camel.apache.org/v1alpha1.ErrorHandlerLog">
-ErrorHandlerLog
-</a>
-</em>
-</td>
-<td>
-</td>
-</tr>
-<tr>
-<td>
-<code>endpoint</code><br/>
-<em>
-<a href="#camel.apache.org/v1alpha1.Endpoint">
-Endpoint
-</a>
-</em>
-</td>
-<td>
-</td>
-</tr>
-</tbody>
-</table>
 <h3 id="camel.apache.org/v1alpha1.ErrorHandlerLog">ErrorHandlerLog
 </h3>
 <p>
 (<em>Appears on:</em>
-<a href="#camel.apache.org/v1alpha1.ErrorHandlerDeadLetterChannel">ErrorHandlerDeadLetterChannel</a>)
+<a href="#camel.apache.org/v1alpha1.ErrorHandlerSink">ErrorHandlerSink</a>)
 </p>
 <div>
 <p>ErrorHandlerLog represent a default (log) error handler type</p>
@@ -5555,7 +5472,6 @@ ErrorHandlerParameters
 </h3>
 <p>
 (<em>Appears on:</em>
-<a href="#camel.apache.org/v1alpha1.ErrorHandlerBean">ErrorHandlerBean</a>, 
 <a href="#camel.apache.org/v1alpha1.ErrorHandlerLog">ErrorHandlerLog</a>)
 </p>
 <div>
@@ -5602,10 +5518,10 @@ RawMessage
 </tr>
 </tbody>
 </table>
-<h3 id="camel.apache.org/v1alpha1.ErrorHandlerRef">ErrorHandlerRef
+<h3 id="camel.apache.org/v1alpha1.ErrorHandlerSink">ErrorHandlerSink
 </h3>
 <div>
-<p>ErrorHandlerRef represents a reference to an error handler builder available in the registry</p>
+<p>ErrorHandlerSink represents a sink error handler type which behave like a dead letter channel</p>
 </div>
 <table>
 <thead>
@@ -5617,10 +5533,22 @@ RawMessage
 <tbody>
 <tr>
 <td>
-<code>RawMessage</code><br/>
+<code>ErrorHandlerLog</code><br/>
 <em>
-<a href="#camel.apache.org/v1.RawMessage">
-RawMessage
+<a href="#camel.apache.org/v1alpha1.ErrorHandlerLog">
+ErrorHandlerLog
+</a>
+</em>
+</td>
+<td>
+</td>
+</tr>
+<tr>
+<td>
+<code>endpoint</code><br/>
+<em>
+<a href="#camel.apache.org/v1alpha1.Endpoint">
+Endpoint
 </a>
 </em>
 </td>
diff --git a/e2e/common/kamelet_binding_test.go b/e2e/common/kamelet_binding_test.go
index f8519d1..7d68cb7 100644
--- a/e2e/common/kamelet_binding_test.go
+++ b/e2e/common/kamelet_binding_test.go
@@ -52,7 +52,7 @@ func TestErrorHandler(t *testing.T) {
 		}
 
 		errorHandler := map[string]interface{}{
-			"dead-letter-channel": map[string]interface{}{
+			"sink": map[string]interface{}{
 				"endpoint": map[string]interface{}{
 					"ref": map[string]string{
 						"kind":       "Kamelet",
diff --git a/examples/kamelets/error-handler/kamelet-binding-error-handler.yaml b/examples/kamelets/error-handler/kamelet-binding-error-handler.yaml
index 3d3c3a5..6a5f4b7 100644
--- a/examples/kamelets/error-handler/kamelet-binding-error-handler.yaml
+++ b/examples/kamelets/error-handler/kamelet-binding-error-handler.yaml
@@ -31,7 +31,7 @@ spec:
       apiVersion: camel.apache.org/v1alpha1
       name: log-sink
   errorHandler:
-    dead-letter-channel:
+    sink:
       endpoint:
         ref:
           kind: Kamelet
diff --git a/examples/kamelets/error-handler/readme.md b/examples/kamelets/error-handler/readme.md
index c9a6857..2c400dc 100644
--- a/examples/kamelets/error-handler/readme.md
+++ b/examples/kamelets/error-handler/readme.md
@@ -1,5 +1,5 @@
 # Kamelets Binding Error Handler example
-This example shows how to create a simple _source_ `Kamelet` which sends periodically events (and certain failures). The events are consumed by a log _sink_ in a `KameletBinding`. With the support of the `ErrorHandler` we will be able to redirect all errors to a `Dead Letter Channel` _error-handler_ `Kamelet` whose goal is to store the events in a `Kafka` topic and provide a nice log notifying us about the error happened.
+This example shows how to create a simple _source_ `Kamelet` which sends periodically events (and certain failures). The events are consumed by a log _sink_ in a `KameletBinding`. With the support of the `ErrorHandler` we will be able to redirect all errors to a `Sink` _error-handler_ `Kamelet` whose goal is to store the events in a `Kafka` topic and provide a nice log notifying us about the error happened.
 
 ## Incremental ID Source Kamelet
 First of all, you must install the _incremental-id-source_ Kamelet defined in `incremental-id-source.kamelet.yaml` file. This source will emit events every second with an autoincrement counter that will be forced to fail when the number 0 is caught. With this trick, we will simulate possible event faults.
@@ -81,11 +81,11 @@ log-sink                Ready
 incremental-id-source   Ready
 ```
 ## Error Handler Kamelet Binding
-We can now create a `KameletBinding` which is started by the _incremental-id-source_ `Kamelet` and log events to _log-sink_ `Kamelet`. As this will sporadically fail, we can configure an _errorHandler_ with the _error-handler_ `Kamelet` as **Dead Letter Channel**. We want to configure also some redelivery policies (1 retry, with a 2000 milliseconds delay). We can declare it as in `kamelet-binding-error-handler.yaml` file:
+We can now create a `KameletBinding` which is started by the _incremental-id-source_ `Kamelet` and log events to _log-sink_ `Kamelet`. As this will sporadically fail, we can configure an _errorHandler_ with the _error-handler_ `Kamelet` as **Sink**. We want to configure also some redelivery policies (1 retry, with a 2000 milliseconds delay). We can declare it as in `kamelet-binding-error-handler.yaml` file:
 ```
 ...
   errorHandler:
-    dead-letter-channel:
+    sink:
       endpoint:
         ref:
           kind: Kamelet
diff --git a/pkg/apis/camel/v1alpha1/error_handler_types.go b/pkg/apis/camel/v1alpha1/error_handler_types.go
index c7ebd8a..af038cb 100644
--- a/pkg/apis/camel/v1alpha1/error_handler_types.go
+++ b/pkg/apis/camel/v1alpha1/error_handler_types.go
@@ -125,24 +125,24 @@ func (e ErrorHandlerLog) Configuration() (map[string]interface{}, error) {
 	return properties, nil
 }
 
-// ErrorHandlerDeadLetterChannel represents a dead letter channel error handler type
-type ErrorHandlerDeadLetterChannel struct {
+// ErrorHandlerSink represents a sink error handler type which behave like a dead letter channel
+type ErrorHandlerSink struct {
 	ErrorHandlerLog
 	DLCEndpoint *Endpoint `json:"endpoint,omitempty"`
 }
 
 // Type --
-func (e ErrorHandlerDeadLetterChannel) Type() ErrorHandlerType {
-	return ErrorHandlerTypeDeadLetterChannel
+func (e ErrorHandlerSink) Type() ErrorHandlerType {
+	return ErrorHandlerTypeSink
 }
 
 // Endpoint --
-func (e ErrorHandlerDeadLetterChannel) Endpoint() *Endpoint {
+func (e ErrorHandlerSink) Endpoint() *Endpoint {
 	return e.DLCEndpoint
 }
 
 // Configuration --
-func (e ErrorHandlerDeadLetterChannel) Configuration() (map[string]interface{}, error) {
+func (e ErrorHandlerSink) Configuration() (map[string]interface{}, error) {
 	properties, err := e.ErrorHandlerLog.Configuration()
 	if err != nil {
 		return nil, err
@@ -161,6 +161,8 @@ const (
 	ErrorHandlerTypeNone ErrorHandlerType = "none"
 	// ErrorHandlerTypeLog --
 	ErrorHandlerTypeLog ErrorHandlerType = "log"
-	// ErrorHandlerTypeDeadLetterChannel --
+	// ErrorHandlerTypeSink --
+	ErrorHandlerTypeSink ErrorHandlerType = "sink"
+	// ErrorHandlerTypeDeadLetterChannel Deprecated in favour of ErrorHandlerTypeSink
 	ErrorHandlerTypeDeadLetterChannel ErrorHandlerType = "dead-letter-channel"
 )
diff --git a/pkg/apis/camel/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/camel/v1alpha1/zz_generated.deepcopy.go
index c492985..be6e2c5 100644
--- a/pkg/apis/camel/v1alpha1/zz_generated.deepcopy.go
+++ b/pkg/apis/camel/v1alpha1/zz_generated.deepcopy.go
@@ -105,27 +105,6 @@ func (in *EndpointProperties) DeepCopy() *EndpointProperties {
 }
 
 // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
-func (in *ErrorHandlerDeadLetterChannel) DeepCopyInto(out *ErrorHandlerDeadLetterChannel) {
-	*out = *in
-	in.ErrorHandlerLog.DeepCopyInto(&out.ErrorHandlerLog)
-	if in.DLCEndpoint != nil {
-		in, out := &in.DLCEndpoint, &out.DLCEndpoint
-		*out = new(Endpoint)
-		(*in).DeepCopyInto(*out)
-	}
-}
-
-// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ErrorHandlerDeadLetterChannel.
-func (in *ErrorHandlerDeadLetterChannel) DeepCopy() *ErrorHandlerDeadLetterChannel {
-	if in == nil {
-		return nil
-	}
-	out := new(ErrorHandlerDeadLetterChannel)
-	in.DeepCopyInto(out)
-	return out
-}
-
-// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
 func (in *ErrorHandlerLog) DeepCopyInto(out *ErrorHandlerLog) {
 	*out = *in
 	out.ErrorHandlerNone = in.ErrorHandlerNone
@@ -183,6 +162,27 @@ func (in *ErrorHandlerParameters) DeepCopy() *ErrorHandlerParameters {
 }
 
 // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
+func (in *ErrorHandlerSink) DeepCopyInto(out *ErrorHandlerSink) {
+	*out = *in
+	in.ErrorHandlerLog.DeepCopyInto(&out.ErrorHandlerLog)
+	if in.DLCEndpoint != nil {
+		in, out := &in.DLCEndpoint, &out.DLCEndpoint
+		*out = new(Endpoint)
+		(*in).DeepCopyInto(*out)
+	}
+}
+
+// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ErrorHandlerSink.
+func (in *ErrorHandlerSink) DeepCopy() *ErrorHandlerSink {
+	if in == nil {
+		return nil
+	}
+	out := new(ErrorHandlerSink)
+	in.DeepCopyInto(out)
+	return out
+}
+
+// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
 func (in *ErrorHandlerSpec) DeepCopyInto(out *ErrorHandlerSpec) {
 	*out = *in
 	if in.RawMessage != nil {
diff --git a/pkg/cmd/bind.go b/pkg/cmd/bind.go
index 396b3b2..b81d49d 100644
--- a/pkg/cmd/bind.go
+++ b/pkg/cmd/bind.go
@@ -58,7 +58,7 @@ func newCmdBind(rootCmdOptions *RootCmdOptions) (*cobra.Command, *bindCmdOptions
 	}
 
 	cmd.Flags().StringArrayP("connect", "c", nil, "A ServiceBinding or Provisioned Service that the integration should bind to, specified as [[apigroup/]version:]kind:[namespace/]name")
-	cmd.Flags().String("error-handler", "", `Add error handler (none|log|dlc:<endpoint>). DLC endpoints are expected in the format "[[apigroup/]version:]kind:[namespace/]name", plain Camel URIs or Kamelet name.`)
+	cmd.Flags().String("error-handler", "", `Add error handler (none|log|sink:<endpoint>). Sink endpoints are expected in the format "[[apigroup/]version:]kind:[namespace/]name", plain Camel URIs or Kamelet name.`)
 	cmd.Flags().String("name", "", "Name for the binding")
 	cmd.Flags().StringP("output", "o", "", "Output format. One of: json|yaml")
 	cmd.Flags().StringArrayP("property", "p", nil, `Add a binding property in the form of "source.<key>=<value>", "sink.<key>=<value>", "error-handler.<key>=<value>" or "step-<n>.<key>=<value>"`)
@@ -239,13 +239,13 @@ func (o *bindCmdOptions) parseErrorHandler() (*v1alpha1.ErrorHandlerSpec, error)
 		errHandlMap["none"] = nil
 	case "log":
 		errHandlMap["log"] = nil
-	case "dlc":
-		dlcSpec, err := o.decode(errHandlValue, errorHandlerKey)
+	case "sink":
+		sinkSpec, err := o.decode(errHandlValue, errorHandlerKey)
 		if err != nil {
 			return nil, err
 		}
-		errHandlMap["dead-letter-channel"] = map[string]interface{}{
-			"endpoint": dlcSpec,
+		errHandlMap["sink"] = map[string]interface{}{
+			"endpoint": sinkSpec,
 		}
 	default:
 		return nil, fmt.Errorf("invalid error handler type %s", o.ErrorHandler)
@@ -259,8 +259,7 @@ func (o *bindCmdOptions) parseErrorHandler() (*v1alpha1.ErrorHandlerSpec, error)
 
 func parseErrorHandlerByType(value string) (string, string, error) {
 	errHandlSplit := strings.SplitN(value, ":", 2)
-	if (errHandlSplit[0] == "dlc" || errHandlSplit[0] == "bean" || errHandlSplit[0] == "ref") &&
-		len(errHandlSplit) != 2 {
+	if (errHandlSplit[0] == "sink") && len(errHandlSplit) != 2 {
 		return "", "", fmt.Errorf("invalid error handler syntax. Type %s needs a configuration (ie %s:value)",
 			errHandlSplit[0], errHandlSplit[0])
 	}
diff --git a/pkg/cmd/bind_test.go b/pkg/cmd/bind_test.go
index 0065fb9..34736d1 100644
--- a/pkg/cmd/bind_test.go
+++ b/pkg/cmd/bind_test.go
@@ -89,7 +89,7 @@ func TestBindOutputUnknownFormat(t *testing.T) {
 func TestBindErrorHandlerDLCKamelet(t *testing.T) {
 	buildCmdOptions, bindCmd, _ := initializeBindCmdOptions(t)
 	output, err := test.ExecuteCommand(bindCmd, cmdBind, "my:src", "my:dst", "-o", "yaml",
-		"--error-handler", "dlc:my-kamelet", "-p", "error-handler.my-prop=value")
+		"--error-handler", "sink:my-kamelet", "-p", "error-handler.my-prop=value")
 	assert.Equal(t, "yaml", buildCmdOptions.OutputFormat)
 
 	assert.Nil(t, err)
@@ -100,7 +100,7 @@ metadata:
   name: my-to-my
 spec:
   errorHandler:
-    dead-letter-channel:
+    sink:
       endpoint:
         properties:
           my-prop: value
diff --git a/pkg/controller/kameletbinding/error_handler.go b/pkg/controller/kameletbinding/error_handler.go
index e240e52..48f1639 100644
--- a/pkg/controller/kameletbinding/error_handler.go
+++ b/pkg/controller/kameletbinding/error_handler.go
@@ -35,7 +35,7 @@ func maybeErrorHandler(errHandlConf *v1alpha1.ErrorHandlerSpec, bindingContext b
 			return nil, errors.Wrap(err, "could not parse error handler")
 		}
 		// We need to get the translated URI from any referenced resource (ie, kamelets)
-		if errorHandlerSpec.Type() == v1alpha1.ErrorHandlerTypeDeadLetterChannel {
+		if errorHandlerSpec.Type() == v1alpha1.ErrorHandlerTypeSink {
 			errorHandlerBinding, err = bindings.Translate(bindingContext, bindings.EndpointContext{Type: v1alpha1.EndpointTypeErrorHandler}, *errorHandlerSpec.Endpoint())
 			if err != nil {
 				return nil, errors.Wrap(err, "could not determine error handler URI")
@@ -74,8 +74,11 @@ func parseErrorHandler(rawMessage v1.RawMessage) (v1alpha1.ErrorHandler, error)
 			dst = new(v1alpha1.ErrorHandlerNone)
 		case v1alpha1.ErrorHandlerTypeLog:
 			dst = new(v1alpha1.ErrorHandlerLog)
+		// Deprecated: left for compatibility for some version
 		case v1alpha1.ErrorHandlerTypeDeadLetterChannel:
-			dst = new(v1alpha1.ErrorHandlerDeadLetterChannel)
+			dst = new(v1alpha1.ErrorHandlerSink)
+		case v1alpha1.ErrorHandlerTypeSink:
+			dst = new(v1alpha1.ErrorHandlerSink)
 		default:
 			return nil, errors.Errorf("Unknown error handler type %s", errHandlType)
 		}
@@ -103,7 +106,7 @@ func setErrorHandlerConfiguration(errorHandlerBinding *bindings.Binding, errorHa
 	for key, value := range properties {
 		errorHandlerBinding.ApplicationProperties[key] = fmt.Sprintf("%v", value)
 	}
-	if errorHandler.Type() == v1alpha1.ErrorHandlerTypeDeadLetterChannel && errorHandlerBinding.URI != "" {
+	if errorHandler.Type() == v1alpha1.ErrorHandlerTypeSink && errorHandlerBinding.URI != "" {
 		errorHandlerBinding.ApplicationProperties[fmt.Sprintf("%s.deadLetterUri", v1alpha1.ErrorHandlerAppPropertiesPrefix)] = fmt.Sprintf("%v", errorHandlerBinding.URI)
 	}
 	return nil
diff --git a/pkg/controller/kameletbinding/error_handler_test.go b/pkg/controller/kameletbinding/error_handler_test.go
index c182ad1..b6dab39 100644
--- a/pkg/controller/kameletbinding/error_handler_test.go
+++ b/pkg/controller/kameletbinding/error_handler_test.go
@@ -63,25 +63,25 @@ func TestParseErrorHandlerLogWithParametersDoesSucceed(t *testing.T) {
 	assert.Equal(t, v1alpha1.ErrorHandlerRefDefaultName, parameters[v1alpha1.ErrorHandlerRefName])
 }
 
-func TestParseErrorHandlerDLCDoesSucceed(t *testing.T) {
+func TestParseErrorHandlerSinkDoesSucceed(t *testing.T) {
 	fmt.Println("Test")
-	dlcErrorHandler, err := parseErrorHandler(
-		[]byte(`{"dead-letter-channel": {"endpoint": {"uri": "someUri"}}}`),
+	sinkErrorHandler, err := parseErrorHandler(
+		[]byte(`{"sink": {"endpoint": {"uri": "someUri"}}}`),
 	)
 	assert.Nil(t, err)
-	assert.NotNil(t, dlcErrorHandler)
-	assert.Equal(t, v1alpha1.ErrorHandlerTypeDeadLetterChannel, dlcErrorHandler.Type())
-	assert.Equal(t, "someUri", *dlcErrorHandler.Endpoint().URI)
-	parameters, err := dlcErrorHandler.Configuration()
+	assert.NotNil(t, sinkErrorHandler)
+	assert.Equal(t, v1alpha1.ErrorHandlerTypeSink, sinkErrorHandler.Type())
+	assert.Equal(t, "someUri", *sinkErrorHandler.Endpoint().URI)
+	parameters, err := sinkErrorHandler.Configuration()
 	assert.Nil(t, err)
 	assert.Equal(t, "#class:org.apache.camel.builder.DeadLetterChannelBuilder", parameters[v1alpha1.ErrorHandlerAppPropertiesPrefix])
 	assert.Equal(t, v1alpha1.ErrorHandlerRefDefaultName, parameters[v1alpha1.ErrorHandlerRefName])
 }
 
-func TestParseErrorHandlerDLCWithParametersDoesSucceed(t *testing.T) {
-	dlcErrorHandler, err := parseErrorHandler(
+func TestParseErrorHandlerSinkWithParametersDoesSucceed(t *testing.T) {
+	sinkErrorHandler, err := parseErrorHandler(
 		[]byte(`{
-			"dead-letter-channel": {
+			"sink": {
 				"endpoint": {
 					"uri": "someUri"
 					}, 
@@ -91,10 +91,10 @@ func TestParseErrorHandlerDLCWithParametersDoesSucceed(t *testing.T) {
 		}`),
 	)
 	assert.Nil(t, err)
-	assert.NotNil(t, dlcErrorHandler)
-	assert.Equal(t, v1alpha1.ErrorHandlerTypeDeadLetterChannel, dlcErrorHandler.Type())
-	assert.Equal(t, "someUri", *dlcErrorHandler.Endpoint().URI)
-	parameters, err := dlcErrorHandler.Configuration()
+	assert.NotNil(t, sinkErrorHandler)
+	assert.Equal(t, v1alpha1.ErrorHandlerTypeSink, sinkErrorHandler.Type())
+	assert.Equal(t, "someUri", *sinkErrorHandler.Endpoint().URI)
+	parameters, err := sinkErrorHandler.Configuration()
 	assert.Nil(t, err)
 	assert.Equal(t, "#class:org.apache.camel.builder.DeadLetterChannelBuilder", parameters[v1alpha1.ErrorHandlerAppPropertiesPrefix])
 	assert.Equal(t, v1alpha1.ErrorHandlerRefDefaultName, parameters[v1alpha1.ErrorHandlerRefName])

[camel-k] 01/02: chore(kamelet): remove bean and ref error handler types

Posted by pc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

pcongiusti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git

commit 2c58b44a546bdefc6151f5368889eea39cf90666
Author: Pasquale Congiusti <pa...@gmail.com>
AuthorDate: Mon Dec 27 10:39:10 2021 +0100

    chore(kamelet): remove bean and ref error handler types
---
 .../kamelets/kameletbindings-error-handler.adoc    | 51 +----------------
 pkg/apis/camel/v1/zz_generated.deepcopy.go         |  8 +++
 pkg/apis/camel/v1alpha1/error_handler_types.go     | 65 ----------------------
 pkg/apis/camel/v1alpha1/zz_generated.deepcopy.go   | 48 +---------------
 pkg/cmd/bind.go                                    |  8 +--
 pkg/cmd/bind_test.go                               |  6 +-
 pkg/controller/kameletbinding/error_handler.go     |  4 --
 .../kameletbinding/error_handler_test.go           | 31 -----------
 8 files changed, 14 insertions(+), 207 deletions(-)

diff --git a/docs/modules/ROOT/pages/kamelets/kameletbindings-error-handler.adoc b/docs/modules/ROOT/pages/kamelets/kameletbindings-error-handler.adoc
index 57a7d8e..648e05b 100644
--- a/docs/modules/ROOT/pages/kamelets/kameletbindings-error-handler.adoc
+++ b/docs/modules/ROOT/pages/kamelets/kameletbindings-error-handler.adoc
@@ -23,7 +23,7 @@ spec:
 [[kameletbindings-error-handler-types]]
 == Error Handler Types
 
-We have different types of error handler: `ǹone`, `log`, `dead-letter-channel`, `bean`, `ref`. The `errorHandler` parameter is optional.
+We have different types of error handler: `ǹone`, `log` and `dead-letter-channel`. The `errorHandler` parameter is optional.
 
 [[kameletbindings-error-handler-none]]
 === No error handler
@@ -104,52 +104,3 @@ spec:
 <2> Properties belonging to the endpoint (in this example, to the `Kamelet` named error handler)
 <3> Parameters belonging to the `dead-letter-channel` error handler type
 
-[[kameletbindings-error-handler-bean]]
-=== Bean error handler
-
-With the `Bean` error handler you can extend the functionality of the Error Handler by providing a custom bean to be used as Error Handler.
-
-[source,yaml]
-----
-apiVersion: camel.apache.org/v1alpha1
-kind: KameletBinding
-metadata:
-  name: my-kamelet-binding
-spec:
-  source:
-...
-  sink: 
-...
-  errorHandler: 
-    bean:
-      type: "org.apache.camel.builder.DeadLetterChannelBuilder" # <1>
-      properties: # <2>
-        deadLetterUri: log:error
-        ... 
-----
-<1> Fully qualified name of the ErrorHandlerBuilder
-<2> Properties expected by your type
-
-[[kameletbindings-error-handler-ref]]
-=== Ref error handler
-
-With the `Ref` error handler you can use any `Bean` that is expected to be found in the Camel registry at runtime.
-
-[source,yaml]
-----
-apiVersion: camel.apache.org/v1alpha1
-kind: KameletBinding
-metadata:
-  name: my-kamelet-binding
-spec:
-  source:
-...
-  sink: 
-...
-  errorHandler: 
-    ref: my-custom-builder # <1>
-... 
-----
-<1> The name of the bean to be looked up at runtime
-
-NOTE: make sure to have the `ref` correctly bind at runtime.
diff --git a/pkg/apis/camel/v1/zz_generated.deepcopy.go b/pkg/apis/camel/v1/zz_generated.deepcopy.go
index bc44413..f23a7da 100644
--- a/pkg/apis/camel/v1/zz_generated.deepcopy.go
+++ b/pkg/apis/camel/v1/zz_generated.deepcopy.go
@@ -1,3 +1,4 @@
+//go:build !ignore_autogenerated
 // +build !ignore_autogenerated
 
 // Code generated by controller-gen. DO NOT EDIT.
@@ -1023,6 +1024,13 @@ func (in *IntegrationPlatformStatus) DeepCopyInto(out *IntegrationPlatformStatus
 			(*in)[i].DeepCopyInto(&(*out)[i])
 		}
 	}
+	if in.Info != nil {
+		in, out := &in.Info, &out.Info
+		*out = make(map[string]string, len(*in))
+		for key, val := range *in {
+			(*out)[key] = val
+		}
+	}
 }
 
 // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new IntegrationPlatformStatus.
diff --git a/pkg/apis/camel/v1alpha1/error_handler_types.go b/pkg/apis/camel/v1alpha1/error_handler_types.go
index d60074a..c7ebd8a 100644
--- a/pkg/apis/camel/v1alpha1/error_handler_types.go
+++ b/pkg/apis/camel/v1alpha1/error_handler_types.go
@@ -19,7 +19,6 @@ package v1alpha1
 
 import (
 	"encoding/json"
-	"fmt"
 
 	v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
 )
@@ -153,66 +152,6 @@ func (e ErrorHandlerDeadLetterChannel) Configuration() (map[string]interface{},
 	return properties, err
 }
 
-// ErrorHandlerRef represents a reference to an error handler builder available in the registry
-type ErrorHandlerRef struct {
-	baseErrorHandler
-	v1.RawMessage
-}
-
-// Type --
-func (e ErrorHandlerRef) Type() ErrorHandlerType {
-	return ErrorHandlerTypeRef
-}
-
-// Configuration --
-func (e ErrorHandlerRef) Configuration() (map[string]interface{}, error) {
-	var refName string
-	err := json.Unmarshal(e.RawMessage, &refName)
-	if err != nil {
-		return nil, err
-	}
-
-	properties := map[string]interface{}{
-		ErrorHandlerRefName: refName,
-	}
-
-	return properties, nil
-}
-
-// ErrorHandlerBean represents a bean error handler type
-type ErrorHandlerBean struct {
-	ErrorHandlerNone
-	BeanType       *string         `json:"type,omitempty"`
-	BeanProperties *BeanProperties `json:"properties,omitempty"`
-}
-
-// Type --
-func (e ErrorHandlerBean) Type() ErrorHandlerType {
-	return ErrorHandlerTypeBean
-}
-
-// Configuration --
-func (e ErrorHandlerBean) Configuration() (map[string]interface{}, error) {
-	properties, err := e.ErrorHandlerNone.Configuration()
-	if err != nil {
-		return nil, err
-	}
-	properties[ErrorHandlerAppPropertiesPrefix] = fmt.Sprintf("#class:%v", *e.BeanType)
-
-	if e.BeanProperties != nil {
-		var beanProperties map[string]interface{}
-		err := json.Unmarshal(e.BeanProperties.RawMessage, &beanProperties)
-		if err != nil {
-			return nil, err
-		}
-		for key, value := range beanProperties {
-			properties[ErrorHandlerAppPropertiesPrefix+"."+key] = value
-		}
-	}
-
-	return properties, err
-}
-
 // ErrorHandlerType --
 type ErrorHandlerType string
 
@@ -224,8 +163,4 @@ const (
 	ErrorHandlerTypeLog ErrorHandlerType = "log"
 	// ErrorHandlerTypeDeadLetterChannel --
 	ErrorHandlerTypeDeadLetterChannel ErrorHandlerType = "dead-letter-channel"
-	// ErrorHandlerTypeRef --
-	ErrorHandlerTypeRef ErrorHandlerType = "ref"
-	// ErrorHandlerTypeBean --
-	ErrorHandlerTypeBean ErrorHandlerType = "bean"
 )
diff --git a/pkg/apis/camel/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/camel/v1alpha1/zz_generated.deepcopy.go
index 4bbf8b6..c492985 100644
--- a/pkg/apis/camel/v1alpha1/zz_generated.deepcopy.go
+++ b/pkg/apis/camel/v1alpha1/zz_generated.deepcopy.go
@@ -1,3 +1,4 @@
+//go:build !ignore_autogenerated
 // +build !ignore_autogenerated
 
 // Code generated by controller-gen. DO NOT EDIT.
@@ -104,32 +105,6 @@ func (in *EndpointProperties) DeepCopy() *EndpointProperties {
 }
 
 // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
-func (in *ErrorHandlerBean) DeepCopyInto(out *ErrorHandlerBean) {
-	*out = *in
-	out.ErrorHandlerNone = in.ErrorHandlerNone
-	if in.BeanType != nil {
-		in, out := &in.BeanType, &out.BeanType
-		*out = new(string)
-		**out = **in
-	}
-	if in.BeanProperties != nil {
-		in, out := &in.BeanProperties, &out.BeanProperties
-		*out = new(BeanProperties)
-		(*in).DeepCopyInto(*out)
-	}
-}
-
-// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ErrorHandlerBean.
-func (in *ErrorHandlerBean) DeepCopy() *ErrorHandlerBean {
-	if in == nil {
-		return nil
-	}
-	out := new(ErrorHandlerBean)
-	in.DeepCopyInto(out)
-	return out
-}
-
-// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
 func (in *ErrorHandlerDeadLetterChannel) DeepCopyInto(out *ErrorHandlerDeadLetterChannel) {
 	*out = *in
 	in.ErrorHandlerLog.DeepCopyInto(&out.ErrorHandlerLog)
@@ -208,27 +183,6 @@ func (in *ErrorHandlerParameters) DeepCopy() *ErrorHandlerParameters {
 }
 
 // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
-func (in *ErrorHandlerRef) DeepCopyInto(out *ErrorHandlerRef) {
-	*out = *in
-	out.baseErrorHandler = in.baseErrorHandler
-	if in.RawMessage != nil {
-		in, out := &in.RawMessage, &out.RawMessage
-		*out = make(v1.RawMessage, len(*in))
-		copy(*out, *in)
-	}
-}
-
-// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ErrorHandlerRef.
-func (in *ErrorHandlerRef) DeepCopy() *ErrorHandlerRef {
-	if in == nil {
-		return nil
-	}
-	out := new(ErrorHandlerRef)
-	in.DeepCopyInto(out)
-	return out
-}
-
-// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
 func (in *ErrorHandlerSpec) DeepCopyInto(out *ErrorHandlerSpec) {
 	*out = *in
 	if in.RawMessage != nil {
diff --git a/pkg/cmd/bind.go b/pkg/cmd/bind.go
index 019c1ff..396b3b2 100644
--- a/pkg/cmd/bind.go
+++ b/pkg/cmd/bind.go
@@ -58,7 +58,7 @@ func newCmdBind(rootCmdOptions *RootCmdOptions) (*cobra.Command, *bindCmdOptions
 	}
 
 	cmd.Flags().StringArrayP("connect", "c", nil, "A ServiceBinding or Provisioned Service that the integration should bind to, specified as [[apigroup/]version:]kind:[namespace/]name")
-	cmd.Flags().String("error-handler", "", `Add error handler (none|log|dlc:<endpoint>|bean:<type>|ref:<registry-ref>). DLC endpoints are expected in the format "[[apigroup/]version:]kind:[namespace/]name", plain Camel URIs or Kamelet name.`)
+	cmd.Flags().String("error-handler", "", `Add error handler (none|log|dlc:<endpoint>). DLC endpoints are expected in the format "[[apigroup/]version:]kind:[namespace/]name", plain Camel URIs or Kamelet name.`)
 	cmd.Flags().String("name", "", "Name for the binding")
 	cmd.Flags().StringP("output", "o", "", "Output format. One of: json|yaml")
 	cmd.Flags().StringArrayP("property", "p", nil, `Add a binding property in the form of "source.<key>=<value>", "sink.<key>=<value>", "error-handler.<key>=<value>" or "step-<n>.<key>=<value>"`)
@@ -247,12 +247,6 @@ func (o *bindCmdOptions) parseErrorHandler() (*v1alpha1.ErrorHandlerSpec, error)
 		errHandlMap["dead-letter-channel"] = map[string]interface{}{
 			"endpoint": dlcSpec,
 		}
-	case "bean":
-		errHandlMap["bean"] = map[string]interface{}{
-			"type": errHandlValue,
-		}
-	case "ref":
-		errHandlMap["ref"] = errHandlValue
 	default:
 		return nil, fmt.Errorf("invalid error handler type %s", o.ErrorHandler)
 	}
diff --git a/pkg/cmd/bind_test.go b/pkg/cmd/bind_test.go
index a23ee91..0065fb9 100644
--- a/pkg/cmd/bind_test.go
+++ b/pkg/cmd/bind_test.go
@@ -139,10 +139,10 @@ status: {}
 `, output)
 }
 
-func TestBindErrorHandlerRef(t *testing.T) {
+func TestBindErrorHandlerLog(t *testing.T) {
 	buildCmdOptions, bindCmd, _ := initializeBindCmdOptions(t)
 	output, err := test.ExecuteCommand(bindCmd, cmdBind, "my:src", "my:dst", "-o", "yaml",
-		"--error-handler", "ref:my-registry-reference")
+		"--error-handler", "log")
 	assert.Equal(t, "yaml", buildCmdOptions.OutputFormat)
 
 	assert.Nil(t, err)
@@ -153,7 +153,7 @@ metadata:
   name: my-to-my
 spec:
   errorHandler:
-    ref: my-registry-reference
+    log: null
   sink:
     uri: my:dst
   source:
diff --git a/pkg/controller/kameletbinding/error_handler.go b/pkg/controller/kameletbinding/error_handler.go
index df52dc2..e240e52 100644
--- a/pkg/controller/kameletbinding/error_handler.go
+++ b/pkg/controller/kameletbinding/error_handler.go
@@ -76,10 +76,6 @@ func parseErrorHandler(rawMessage v1.RawMessage) (v1alpha1.ErrorHandler, error)
 			dst = new(v1alpha1.ErrorHandlerLog)
 		case v1alpha1.ErrorHandlerTypeDeadLetterChannel:
 			dst = new(v1alpha1.ErrorHandlerDeadLetterChannel)
-		case v1alpha1.ErrorHandlerTypeRef:
-			dst = new(v1alpha1.ErrorHandlerRef)
-		case v1alpha1.ErrorHandlerTypeBean:
-			dst = new(v1alpha1.ErrorHandlerBean)
 		default:
 			return nil, errors.Errorf("Unknown error handler type %s", errHandlType)
 		}
diff --git a/pkg/controller/kameletbinding/error_handler_test.go b/pkg/controller/kameletbinding/error_handler_test.go
index 94e6643..c182ad1 100644
--- a/pkg/controller/kameletbinding/error_handler_test.go
+++ b/pkg/controller/kameletbinding/error_handler_test.go
@@ -101,34 +101,3 @@ func TestParseErrorHandlerDLCWithParametersDoesSucceed(t *testing.T) {
 	assert.Equal(t, "value1", parameters["camel.beans.defaultErrorHandler.param1"])
 	assert.Equal(t, "value2", parameters["camel.beans.defaultErrorHandler.param2"])
 }
-
-func TestParseErrorHandlerBeanWithParamsDoesSucceed(t *testing.T) {
-	beanErrorHandler, err := parseErrorHandler(
-		[]byte(`{
-			"bean": {
-				"type": "com.acme.MyType",
-				"properties": 
-					{"beanProp1": "value1", "beanProp2": "value2"}
-			}
-		}`),
-	)
-	assert.Nil(t, err)
-	assert.Equal(t, v1alpha1.ErrorHandlerTypeBean, beanErrorHandler.Type())
-	parameters, err := beanErrorHandler.Configuration()
-	assert.Nil(t, err)
-	assert.Equal(t, "#class:com.acme.MyType", parameters[v1alpha1.ErrorHandlerAppPropertiesPrefix])
-	assert.Equal(t, v1alpha1.ErrorHandlerRefDefaultName, parameters[v1alpha1.ErrorHandlerRefName])
-	assert.Equal(t, "value1", parameters["camel.beans.defaultErrorHandler.beanProp1"])
-	assert.Equal(t, "value2", parameters["camel.beans.defaultErrorHandler.beanProp2"])
-}
-
-func TestParseErrorHandlerRefDoesSucceed(t *testing.T) {
-	refErrorHandler, err := parseErrorHandler(
-		[]byte(`{"ref": "my-registry-ref"}`),
-	)
-	assert.Nil(t, err)
-	assert.Equal(t, v1alpha1.ErrorHandlerTypeRef, refErrorHandler.Type())
-	parameters, err := refErrorHandler.Configuration()
-	assert.Nil(t, err)
-	assert.Equal(t, "my-registry-ref", parameters[v1alpha1.ErrorHandlerRefName])
-}