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

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

commit 71e06243d44e6533d648b58b4c38e0d7f17a0c45
Author: Pasquale Congiusti <[email protected]>
AuthorDate: Tue Apr 27 10:24:04 2021 +0200

    refactor(controller): app properties binding
    
    Error handler application properties set via binding
---
 pkg/controller/kameletbinding/common.go        |  2 +-
 pkg/controller/kameletbinding/error_handler.go | 26 +++++++++++--------
 pkg/resources/resources.go                     | 36 +++++++++++++-------------
 pkg/trait/error_handler.go                     | 20 +++++++++++++-
 4 files changed, 53 insertions(+), 31 deletions(-)

diff --git a/pkg/controller/kameletbinding/common.go 
b/pkg/controller/kameletbinding/common.go
index 45509e1..5da336a 100644
--- a/pkg/controller/kameletbinding/common.go
+++ b/pkg/controller/kameletbinding/common.go
@@ -81,7 +81,7 @@ func createIntegrationFor(ctx context.Context, c 
client.Client, kameletbinding *
                return nil, errors.Wrap(err, "could not determine sink URI")
        }
        // error handler is optional
-       errorHandler, err := 
maybeErrorHandler(kameletbinding.Spec.ErrorHandler, bindingContext, &it.Spec)
+       errorHandler, err := 
maybeErrorHandler(kameletbinding.Spec.ErrorHandler, bindingContext)
        if err != nil {
                return nil, errors.Wrap(err, "could not determine error 
handler")
        }
diff --git a/pkg/controller/kameletbinding/error_handler.go 
b/pkg/controller/kameletbinding/error_handler.go
index 0f75670..1d71683 100644
--- a/pkg/controller/kameletbinding/error_handler.go
+++ b/pkg/controller/kameletbinding/error_handler.go
@@ -27,29 +27,33 @@ import (
        "github.com/pkg/errors"
 )
 
-func maybeErrorHandler(errHandlConf v1alpha1.ErrorHandlerSpec, bindingContext 
bindings.BindingContext, itSpec *v1.IntegrationSpec) (*bindings.Binding, error) 
{
-       var errorHandler *bindings.Binding
+func maybeErrorHandler(errHandlConf v1alpha1.ErrorHandlerSpec, bindingContext 
bindings.BindingContext) (*bindings.Binding, error) {
+       var errorHandlerBinding *bindings.Binding
        if errHandlConf.RawMessage != nil {
                errorHandlerSpec, err := 
parseErrorHandler(errHandlConf.RawMessage)
                if err != nil {
                        return nil, errors.Wrap(err, "could not parse error 
handler")
                }
                // We need to get the translated URI from any referenced 
resource (ie, kamelets)
-               errorHandlerURI := ""
                if errorHandlerSpec.Type() == 
v1alpha1.ErrorHandlerTypeDeadLetterChannel {
-                       errorHandler, err = bindings.Translate(bindingContext, 
bindings.EndpointContext{Type: v1alpha1.EndpointTypeErrorHandler}, 
*errorHandlerSpec.Endpoint())
+                       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")
                        }
-                       errorHandlerURI = errorHandler.URI
+               } else {
+                       // Create a new binding otherwise in order to store 
application properties
+                       errorHandlerBinding = &bindings.Binding{
+                               URI:                   "error-handler",
+                               ApplicationProperties: make(map[string]string),
+                       }
                }
 
-               err = setErrorHandlerConfiguration(itSpec, errorHandlerURI, 
errorHandlerSpec)
+               err = setErrorHandlerConfiguration(errorHandlerBinding, 
errorHandlerSpec)
                if err != nil {
                        return nil, errors.Wrap(err, "could not set integration 
error handler")
                }
 
-               return errorHandler, nil
+               return errorHandlerBinding, nil
        }
        return nil, nil
 }
@@ -92,16 +96,16 @@ func parseErrorHandler(rawMessage v1.RawMessage) 
(v1alpha1.ErrorHandler, error)
        return nil, errors.New("You must provide any supported error handler")
 }
 
-func setErrorHandlerConfiguration(it *v1.IntegrationSpec, errorHandlerURI 
string, errorHandler v1alpha1.ErrorHandler) error {
+func setErrorHandlerConfiguration(errorHandlerBinding *bindings.Binding, 
errorHandler v1alpha1.ErrorHandler) error {
        properties, err := errorHandler.Configuration()
        if err != nil {
                return err
        }
        for key, value := range properties {
-               it.AddConfiguration("property", fmt.Sprintf("%s=%v", key, 
value))
+               errorHandlerBinding.ApplicationProperties[key] = 
fmt.Sprintf("%v", value)
        }
-       if errorHandler.Type() == v1alpha1.ErrorHandlerTypeDeadLetterChannel && 
errorHandlerURI != "" {
-               it.AddConfiguration("property", 
fmt.Sprintf("%s.deadLetterUri=%v", v1alpha1.ErrorHandlerAppPropertiesPrefix, 
errorHandlerURI))
+       if errorHandler.Type() == v1alpha1.ErrorHandlerTypeDeadLetterChannel && 
errorHandlerBinding.URI != "" {
+               
errorHandlerBinding.ApplicationProperties[fmt.Sprintf("%s.deadLetterUri", 
v1alpha1.ErrorHandlerAppPropertiesPrefix)] = fmt.Sprintf("%v", 
errorHandlerBinding.URI)
        }
        return nil
 }
diff --git a/pkg/resources/resources.go b/pkg/resources/resources.go
index 5c771bb..9f43b93 100644
--- a/pkg/resources/resources.go
+++ b/pkg/resources/resources.go
@@ -238,19 +238,19 @@ var assets = func() http.FileSystem {
 
                        compressedContent: 
[]byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xac\x53\x4d\x6f\xab\x46\x14\xdd\xcf\xaf\x38\x32\x9b\xf7\x24\x1b\xb7\x5d\x55\xee\x8a\x97\xd8\x2d\x6a\x64\x4b\xc6\x69\x94\xe5\x78\xb8\xc0\xad\x61\x2e\x9d\x19\x42\xdc\x5f\x5f\x0d\xb6\x9b\x44\x55\xab\x2e\x32\x2b\x10\x97\xf3\x71\xcf\x99\x04\x8b\xcf\x3b\x2a\xc1\x03\x1b\xb2\x9e\x4a\x04\x41\x68\x08\x59\xaf\x4d\x43\x28\xa4\x0a\xa3\x76\x84\x8d\x0c\xb6\xd4\x81\xc5\xe2\x4b\x56\x6c\xbe\x62\xb0\x25\x39\x88\x25\x88\x43\x27\x8e\x54\x
 [...]
                },
-               "/rbac/operator-role-binding-service-binding.yaml": 
&vfsgen۰CompressedFileInfo{
-                       name:             
"operator-role-binding-service-binding.yaml",
+               "/rbac/operator-role-binding-podmonitors.yaml": 
&vfsgen۰CompressedFileInfo{
+                       name:             
"operator-role-binding-podmonitors.yaml",
                        modTime:          time.Time{},
-                       uncompressedSize: 1237,
+                       uncompressedSize: 1229,
 
-                       compressedContent: 
[]byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xac\x53\xcf\x6f\xf2\x46\x10\xbd\xef\x5f\xf1\x84\x2f\xdf\x27\x81\x69\x7b\xaa\xe8\xc9\x5f\x02\xad\xd5\x08\x24\x4c\x1a\xe5\xb8\x5e\x0f\xf6\x14\x7b\xc7\xdd\x5d\xc7\xa1\x7f\x7d\xb5\x06\x9a\x44\x55\x2b\x55\xca\xde\x10\x33\xef\xc7\xbc\xe7\x04\x8b\xcf\x7b\x2a\xc1\x03\x1b\xb2\x9e\x2a\x04\x41\x68\x08\x59\xaf\x4d\x43\x28\xe4\x18\x46\xed\x08\x1b\x19\x6c\xa5\x03\x8b\xc5\x97\xac\xd8\x7c\xc5\x60\x2b\x72\x10\x4b\x10\x87\x4e\x1c\xa9\x
 [...]
+                       compressedContent: 
[]byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xac\x53\x4d\x8f\xdb\x36\x10\xbd\xf3\x57\x3c\x58\x97\x04\x58\xcb\x6d\x4f\x85\x7b\x72\x36\xbb\xad\xd0\xc0\x06\x2c\xa7\x41\x8e\x34\x35\x96\xa6\x2b\x71\xd8\x21\xb5\x8a\xfb\xeb\x0b\xca\x76\x77\x83\xa2\x45\x0f\xe1\x4d\xd0\xf0\x7d\xcc\x7b\x2c\xb0\xfc\x76\xc7\x14\xf8\xc0\x8e\x7c\xa4\x06\x49\x90\x3a\xc2\x26\x58\xd7\x11\x6a\x39\xa5\xc9\x2a\xe1\x51\x46\xdf\xd8\xc4\xe2\xf1\x66\x53\x3f\xbe\xc5\xe8\x1b\x52\x88\x27\x88\x62\x10\x25\x
 [...]
                },
-               "/rbac/operator-role-binding-servicemonitors.yaml": 
&vfsgen۰CompressedFileInfo{
-                       name:             
"operator-role-binding-servicemonitors.yaml",
+               "/rbac/operator-role-binding-service-binding.yaml": 
&vfsgen۰CompressedFileInfo{
+                       name:             
"operator-role-binding-service-binding.yaml",
                        modTime:          time.Time{},
                        uncompressedSize: 1237,
 
-                       compressedContent: 
[]byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xac\x53\x4d\x8f\xdb\x36\x10\xbd\xf3\x57\x3c\x58\x97\x04\x58\xcb\x6d\x4f\x85\x7b\x52\x36\xeb\x56\x68\x60\x03\x96\xd3\x20\x47\x9a\x1a\x4b\x53\x4b\x1c\x75\x48\xad\xe2\xfe\xfa\x82\xb2\xdd\xdd\xa0\x68\x81\x02\xe1\xcd\xf0\xcc\xfb\x98\xf7\x94\x61\xf9\xed\x9e\xc9\xf0\x81\x1d\xf9\x40\x35\xa2\x20\xb6\x84\x62\xb0\xae\x25\x54\x72\x8a\x93\x55\xc2\x46\x46\x5f\xdb\xc8\xe2\xf1\xa6\xa8\x36\x6f\x31\xfa\x9a\x14\xe2\x09\xa2\xe8\x45\xc9\x
 [...]
+                       compressedContent: 
[]byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xac\x53\xcf\x6f\xf2\x46\x10\xbd\xef\x5f\xf1\x84\x2f\xdf\x27\x81\x69\x7b\xaa\xe8\xc9\x5f\x02\xad\xd5\x08\x24\x4c\x1a\xe5\xb8\x5e\x0f\xf6\x14\x7b\xc7\xdd\x5d\xc7\xa1\x7f\x7d\xb5\x06\x9a\x44\x55\x2b\x55\xca\xde\x10\x33\xef\xc7\xbc\xe7\x04\x8b\xcf\x7b\x2a\xc1\x03\x1b\xb2\x9e\x2a\x04\x41\x68\x08\x59\xaf\x4d\x43\x28\xe4\x18\x46\xed\x08\x1b\x19\x6c\xa5\x03\x8b\xc5\x97\xac\xd8\x7c\xc5\x60\x2b\x72\x10\x4b\x10\x87\x4e\x1c\xa9\x
 [...]
                },
                "/rbac/operator-role-binding-strimzi.yaml": 
&vfsgen۰CompressedFileInfo{
                        name:             "operator-role-binding-strimzi.yaml",
@@ -301,6 +301,13 @@ var assets = func() http.FileSystem {
 
                        compressedContent: 
[]byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xc4\x53\xc1\x8e\xdb\x46\x0c\xbd\xeb\x2b\x1e\xac\x4b\x02\xac\xe5\xb6\xa7\xc2\x3d\xb9\xc9\x6e\x6b\x34\xb0\x81\x95\xd3\x20\x47\x7a\x44\x4b\xc4\x8e\x86\xea\xcc\x68\x95\xed\xd7\x17\x33\xb6\x13\x6f\xdd\x6d\x2e\x01\xa2\x8b\x68\xf2\x89\x7c\x8f\x8f\x2e\x31\xff\x76\x4f\x51\xe2\x9d\x18\x76\x81\x1b\x44\x45\xec\x18\xab\x81\x4c\xc7\xa8\xf5\x10\x27\xf2\x8c\x3b\x1d\x5d\x43\x51\xd4\xe1\xd5\xaa\xbe\x7b\x8d\xd1\x35\xec\xa1\x8e\xa1\x1e\x
 [...]
                },
+               "/rbac/operator-role-podmonitors.yaml": 
&vfsgen۰CompressedFileInfo{
+                       name:             "operator-role-podmonitors.yaml",
+                       modTime:          time.Time{},
+                       uncompressedSize: 1242,
+
+                       compressedContent: 
[]byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xac\x53\x4d\x8f\xdb\x36\x10\xbd\xf3\x57\x3c\x58\x97\x04\x58\xcb\x6d\x4f\x85\x7b\x72\x37\xbb\xad\xd0\xc0\x06\x56\x4e\x83\x1c\x69\x6a\x2c\x0d\x96\xe2\xb0\x43\x6a\x95\xed\xaf\x2f\x24\xcb\xcd\x1a\xb9\x86\x17\x8f\xc9\xe1\xfb\xe0\x1b\x15\x58\xff\xb8\x65\x0a\x7c\x64\x47\x21\x51\x83\x2c\xc8\x1d\x61\x17\xad\xeb\x08\xb5\x9c\xf3\x68\x95\xf0\x28\x43\x68\x6c\x66\x09\x78\xb7\xab\x1f\xdf\x63\x08\x0d\x29\x24\x10\x44\xd1\x8b\x92\x29\x
 [...]
+               },
                "/rbac/operator-role-service-binding.yaml": 
&vfsgen۰CompressedFileInfo{
                        name:             "operator-role-service-binding.yaml",
                        modTime:          time.Time{},
@@ -308,13 +315,6 @@ var assets = func() http.FileSystem {
 
                        compressedContent: 
[]byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xac\x53\xc1\x6e\xdc\x36\x10\xbd\xf3\x2b\x1e\x56\x97\x04\xb0\xe4\xb6\xa7\x62\x7b\xda\x3a\x76\x2b\x34\xd8\x05\xac\x4d\x83\x1c\xb9\xd4\xac\x34\x30\xc5\x51\x87\x94\x15\xf7\xeb\x0b\x6a\xb5\x89\x8d\x5e\xa3\x0b\x47\xe4\xcc\x9b\xf7\xf8\x86\x05\xca\x1f\xf7\x99\x02\x1f\xd9\x51\x88\xd4\x22\x09\x52\x4f\xd8\x8d\xd6\xf5\x84\x46\xce\x69\xb6\x4a\x78\x90\x29\xb4\x36\xb1\x04\xbc\xdb\x35\x0f\xef\x31\x85\x96\x14\x12\x08\xa2\x18\x44\xc9\x
 [...]
                },
-               "/rbac/operator-role-servicemonitors.yaml": 
&vfsgen۰CompressedFileInfo{
-                       name:             "operator-role-servicemonitors.yaml",
-                       modTime:          time.Time{},
-                       uncompressedSize: 1250,
-
-                       compressedContent: 
[]byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xac\x53\xc1\x8e\xdb\x36\x10\xbd\xf3\x2b\x1e\xac\x4b\x02\xac\xe5\xb6\xa7\xc2\x3d\xb9\x9b\xdd\x56\x68\x60\x03\x2b\xa7\x41\x8e\x34\x35\x96\x06\x4b\x71\xd4\x21\xb5\x8a\xfb\xf5\x85\x68\xb9\xd9\x45\xae\xe1\xc5\x63\x72\x66\xde\x7b\xf3\x46\x05\xd6\x3f\xee\x98\x02\x1f\xd9\x51\x88\xd4\x20\x09\x52\x47\xd8\x0d\xd6\x75\x84\x5a\xce\x69\xb2\x4a\x78\x94\x31\x34\x36\xb1\x04\xbc\xdb\xd5\x8f\xef\x31\x86\x86\x14\x12\x08\xa2\xe8\x45\xc9\x
 [...]
-               },
                "/rbac/operator-role-strimzi.yaml": &vfsgen۰CompressedFileInfo{
                        name:             "operator-role-strimzi.yaml",
                        modTime:          time.Time{},
@@ -467,9 +467,9 @@ var assets = func() http.FileSystem {
                "/traits.yaml": &vfsgen۰CompressedFileInfo{
                        name:             "traits.yaml",
                        modTime:          time.Time{},
-                       uncompressedSize: 37171,
+                       uncompressedSize: 36976,
 
-                       compressedContent: 
[]byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xec\x7d\xed\x72\x1c\xb7\x11\xe0\x7f\x3d\x05\x8a\xb9\x2a\x7e\xd4\xee\x90\x72\xca\xb1\xb3\x77\xba\x14\x2d\x29\x09\x6d\x4b\xe2\x89\x8a\x53\x57\x3a\x57\x16\x3b\xd3\xbb\x0b\x11\x03\x4c\x00\x0c\xa9\xcd\xd5\xbd\xfb\x15\xba\x01\x0c\x66\x77\xb8\x1c\xca\xa6\xcb\xbc\xba\xe4\x87\x45\x72\xa6\xd1\x68\x34\xfa\xbb\x7b\x9c\xe1\xc2\xd9\xd9\xb3\x29\x53\xbc\x86\x19\xe3\xcb\xa5\x50\xc2\x6d\x9e\x31\xd6\x48\xee\x96\xda\xd4\x33\xb6\xe4\xd2\x
 [...]
+                       compressedContent: 
[]byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xec\x7d\x6d\x73\x1c\xb7\xd1\xe0\x77\xfd\x0a\x14\x9f\xab\xe2\x4b\xed\x0c\x29\xa7\x9c\xf8\xf6\x4e\x97\xa2\x25\x25\xa1\x6d\x49\x3c\x51\x71\xea\x4a\xa7\xca\x62\x67\x7a\x77\x21\x62\x80\x09\x80\x21\xb5\xb9\xba\xff\x7e\x85\x6e\x00\x83\xd9\x1d\x2e\x97\xb2\xe9\x32\xaf\x9e\xe4\x83\x45\x72\xa6\xd1\x68\x34\xfa\xbd\x7b\x9c\xe1\xc2\xd9\xe9\xb3\x82\x29\xde\xc0\x94\xf1\xc5\x42\x28\xe1\xd6\xcf\x18\x6b\x25\x77\x0b\x6d\x9a\x29\x5b\x70\x
 [...]
                },
        }
        fs["/"].(*vfsgen۰DirInfo).entries = []os.FileInfo{
@@ -524,8 +524,8 @@ var assets = func() http.FileSystem {
                fs["/rbac/operator-role-binding-knative.yaml"].(os.FileInfo),
                fs["/rbac/operator-role-binding-leases.yaml"].(os.FileInfo),
                fs["/rbac/operator-role-binding-openshift.yaml"].(os.FileInfo),
+               
fs["/rbac/operator-role-binding-podmonitors.yaml"].(os.FileInfo),
                
fs["/rbac/operator-role-binding-service-binding.yaml"].(os.FileInfo),
-               
fs["/rbac/operator-role-binding-servicemonitors.yaml"].(os.FileInfo),
                fs["/rbac/operator-role-binding-strimzi.yaml"].(os.FileInfo),
                fs["/rbac/operator-role-binding.yaml"].(os.FileInfo),
                fs["/rbac/operator-role-events.yaml"].(os.FileInfo),
@@ -533,8 +533,8 @@ var assets = func() http.FileSystem {
                fs["/rbac/operator-role-kubernetes.yaml"].(os.FileInfo),
                fs["/rbac/operator-role-leases.yaml"].(os.FileInfo),
                fs["/rbac/operator-role-openshift.yaml"].(os.FileInfo),
+               fs["/rbac/operator-role-podmonitors.yaml"].(os.FileInfo),
                fs["/rbac/operator-role-service-binding.yaml"].(os.FileInfo),
-               fs["/rbac/operator-role-servicemonitors.yaml"].(os.FileInfo),
                fs["/rbac/operator-role-strimzi.yaml"].(os.FileInfo),
                fs["/rbac/user-cluster-role.yaml"].(os.FileInfo),
                
fs["/rbac/user-global-kamelet-viewer-role-binding.yaml"].(os.FileInfo),
diff --git a/pkg/trait/error_handler.go b/pkg/trait/error_handler.go
index e705e97..fbd757f 100644
--- a/pkg/trait/error_handler.go
+++ b/pkg/trait/error_handler.go
@@ -83,7 +83,25 @@ func addErrorHandlerAsSource(e *Environment) error {
                Language: v1.LanguageJavaSource,
                Type:     v1.SourceTypeErrorHandler,
        }
-
+       /*
+               flowErrorHandler := map[string]interface{}{
+                       "error-handler": map[string]string{
+                               "ref": errorHandlerRefName,
+                       },
+               }
+               encodedFlowErrorHandler, err := yaml.Marshal(flowErrorHandler)
+               if err != nil {
+                       return err
+               }
+               errorHandlerSource := v1.SourceSpec{
+                       DataSpec: v1.DataSpec{
+                               Name:    "ErrorHandlerSource.yaml",
+                               Content: string(encodedFlowErrorHandler),
+                       },
+                       Language: v1.LanguageYaml,
+                       Type:     v1.SourceTypeErrorHandler,
+               }
+       */
        e.Integration.Status.AddOrReplaceGeneratedSources(errorHandlerSource)
 
        return nil

Reply via email to