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


The following commit(s) were added to refs/heads/main by this push:
     new dc6b814f8 feat(traits): service binding refactoring
dc6b814f8 is described below

commit dc6b814f84b928b38328dd80a60814dccb60c47e
Author: Pasquale Congiusti <pasquale.congiu...@gmail.com>
AuthorDate: Fri Mar 22 12:17:22 2024 +0100

    feat(traits): service binding refactoring
---
 pkg/trait/service_binding.go      | 26 +++++++++++++++++++++++++-
 pkg/trait/service_binding_test.go | 14 ++++++++++----
 2 files changed, 35 insertions(+), 5 deletions(-)

diff --git a/pkg/trait/service_binding.go b/pkg/trait/service_binding.go
index 5921499af..867c8b4c2 100644
--- a/pkg/trait/service_binding.go
+++ b/pkg/trait/service_binding.go
@@ -88,14 +88,38 @@ func (t *serviceBindingTrait) Apply(e *Environment) error {
                return err
        }
 
+       if 
e.CamelCatalog.Runtime.Capabilities["service-binding"].RuntimeProperties != nil 
{
+               t.setCatalogConfiguration(e)
+       } else {
+               t.setProperties(e)
+       }
+
        secret := createSecret(ctx, e.Integration.Namespace, e.Integration.Name)
        if secret != nil {
                e.Resources.Add(secret)
-               
e.ApplicationProperties["quarkus.kubernetes-service-binding.enabled"] = "true"
        }
+
        return nil
 }
 
+func (t *serviceBindingTrait) setCatalogConfiguration(e *Environment) {
+       if e.ApplicationProperties == nil {
+               e.ApplicationProperties = make(map[string]string)
+       }
+       e.ApplicationProperties["camel.k.serviceBinding.enabled"] = True
+       for _, cp := range 
e.CamelCatalog.Runtime.Capabilities["service-binding"].RuntimeProperties {
+               e.ApplicationProperties[CapabilityPropertyKey(cp.Key, 
e.ApplicationProperties)] = cp.Value
+       }
+}
+
+// Deprecated: to be removed in future release in favor of func 
setCatalogConfiguration().
+func (t *serviceBindingTrait) setProperties(e *Environment) {
+       if e.ApplicationProperties == nil {
+               e.ApplicationProperties = make(map[string]string)
+       }
+       e.ApplicationProperties["quarkus.kubernetes-service-binding.enabled"] = 
"true"
+}
+
 func (t *serviceBindingTrait) getContext(e *Environment) (pipeline.Context, 
error) {
        services, err := t.parseServices(e.Integration.Namespace)
        if err != nil {
diff --git a/pkg/trait/service_binding_test.go 
b/pkg/trait/service_binding_test.go
index c62bec13a..407646639 100644
--- a/pkg/trait/service_binding_test.go
+++ b/pkg/trait/service_binding_test.go
@@ -44,18 +44,24 @@ func TestServiceBinding(t *testing.T) {
        handlers = []pipeline.Handler{}
        err = sbTrait.Apply(environment)
        require.NoError(t, err)
+       assert.Equal(t, "true", 
environment.ApplicationProperties["camel.k.serviceBinding.enabled"])
+       assert.Equal(t, "${camel.k.serviceBinding.enabled}", 
environment.ApplicationProperties["quarkus.kubernetes-service-binding.enabled"])
        // TODO we should make the service binding trait to easily work with 
fake client
-       // and test the apply result in the environment accordingly.
+       // and test the apply secret in the environment accordingly.
 }
 
 func createNominalServiceBindingTest() (*serviceBindingTrait, *Environment) {
        trait, _ := newServiceBindingTrait().(*serviceBindingTrait)
        client, _ := test.NewFakeClient()
-
+       catalog := NewCatalog(client)
+       c, err := camel.DefaultCatalog()
+       if err != nil {
+               panic(err)
+       }
        environment := &Environment{
                Client:       client,
-               Catalog:      NewCatalog(client),
-               CamelCatalog: &camel.RuntimeCatalog{},
+               Catalog:      catalog,
+               CamelCatalog: c,
                Integration: &v1.Integration{
                        Spec: v1.IntegrationSpec{
                                Sources: []v1.SourceSpec{

Reply via email to