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

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

commit 19f4c403f9156319b05ccc1a83db256bae58bfc0
Author: nferraro <[email protected]>
AuthorDate: Fri Oct 5 10:45:46 2018 +0200

    Formalize auto-detection
---
 pkg/trait/catalog.go |  2 +-
 pkg/trait/service.go |  6 +++---
 pkg/trait/types.go   | 14 ++++++++++++--
 3 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/pkg/trait/catalog.go b/pkg/trait/catalog.go
index df8ad07..abc6415 100644
--- a/pkg/trait/catalog.go
+++ b/pkg/trait/catalog.go
@@ -69,7 +69,7 @@ func (c *chainedCustomizer) id() id {
 func (c *chainedCustomizer) customize(environment *environment, resources 
*kubernetes.Collection) (bool, error) {
        atLeastOne := false
        for _, custom := range c.customizers {
-               if environment.isEnabled(custom.id()) {
+               if environment.isExplicitlyEnabled(custom.id()) || 
environment.isAutoDetectionMode(custom.id()) {
                        if done, err := custom.customize(environment, 
resources); err != nil {
                                return false, err
                        } else if done && custom.id() != "" {
diff --git a/pkg/trait/service.go b/pkg/trait/service.go
index f52d08d..9907466 100644
--- a/pkg/trait/service.go
+++ b/pkg/trait/service.go
@@ -45,11 +45,11 @@ func (*serviceTrait) id() id {
        return id("service")
 }
 
-func (e *serviceTrait) customize(environment *environment, resources 
*kubernetes.Collection) (bool, error) {
-       if !e.requiresService(environment) {
+func (s *serviceTrait) customize(environment *environment, resources 
*kubernetes.Collection) (bool, error) {
+       if environment.isAutoDetectionMode(s.id()) && 
!s.requiresService(environment) {
                return false, nil
        }
-       svc, err := e.getServiceFor(environment)
+       svc, err := s.getServiceFor(environment)
        if err != nil {
                return false, err
        }
diff --git a/pkg/trait/types.go b/pkg/trait/types.go
index ad002e1..306f0b4 100644
--- a/pkg/trait/types.go
+++ b/pkg/trait/types.go
@@ -53,9 +53,19 @@ func (e *environment) getTraitSpec(traitID id) 
*v1alpha1.IntegrationTraitSpec {
        return nil
 }
 
-func (e *environment) isEnabled(traitID id) bool {
+func (e *environment) isExplicitlyEnabled(traitID id) bool {
        conf := e.getTraitSpec(traitID)
-       return conf == nil || conf.Enabled == nil || *conf.Enabled
+       return conf != nil && conf.Enabled != nil && *conf.Enabled
+}
+
+func (e *environment) isExplicitlyDisabled(traitID id) bool {
+       conf := e.getTraitSpec(traitID)
+       return conf != nil && conf.Enabled != nil && !*conf.Enabled
+}
+
+func (e *environment) isAutoDetectionMode(traitID id) bool {
+       conf := e.getTraitSpec(traitID)
+       return conf == nil || conf.Enabled == nil
 }
 
 func (e *environment) getConfig(traitID id, key string) *string {

Reply via email to