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

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

commit 6b7e83934fbc61d83962b593808251a86c6eb233
Author: Antonin Stefanutti <anto...@stefanutti.fr>
AuthorDate: Wed Sep 7 15:22:38 2022 +0200

    fix: check platform readiness before calling traits that require it
---
 pkg/trait/builder_test.go  |  3 +++
 pkg/trait/trait_catalog.go |  6 +++---
 pkg/trait/trait_types.go   | 14 ++++++++++++++
 3 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/pkg/trait/builder_test.go b/pkg/trait/builder_test.go
index ad7f8e861..c444d4d54 100644
--- a/pkg/trait/builder_test.go
+++ b/pkg/trait/builder_test.go
@@ -138,6 +138,9 @@ func createBuilderTestEnv(cluster 
v1.IntegrationPlatformCluster, strategy v1.Int
                                        KanikoBuildCache:       &kanikoCache,
                                },
                        },
+                       Status: v1.IntegrationPlatformStatus{
+                               Phase: v1.IntegrationPlatformPhaseReady,
+                       },
                },
                EnvVars:        make([]corev1.EnvVar, 0),
                ExecutedTraits: make([]Trait, 0),
diff --git a/pkg/trait/trait_catalog.go b/pkg/trait/trait_catalog.go
index 807bd4055..5acbaf94c 100644
--- a/pkg/trait/trait_catalog.go
+++ b/pkg/trait/trait_catalog.go
@@ -96,7 +96,7 @@ func (c *Catalog) apply(environment *Environment) error {
 
        applicable := false
        for _, trait := range traits {
-               if environment.Platform == nil && 
trait.RequiresIntegrationPlatform() {
+               if 
!environment.PlatformInPhase(v1.IntegrationPlatformPhaseReady) && 
trait.RequiresIntegrationPlatform() {
                        c.L.Debugf("Skipping trait because of missing 
integration platform: %s", trait.ID())
 
                        continue
@@ -131,8 +131,8 @@ func (c *Catalog) apply(environment *Environment) error {
        }
        c.L.Debugf("Applied traits: %s", strings.Join(traitIds, ","))
 
-       if !applicable && environment.Platform == nil {
-               return errors.New("no trait can be executed because of no 
integration platform found")
+       if !applicable && 
environment.PlatformInPhase(v1.IntegrationPlatformPhaseReady) {
+               return errors.New("no trait can be executed because of no ready 
platform found")
        }
 
        for _, processor := range environment.PostProcessors {
diff --git a/pkg/trait/trait_types.go b/pkg/trait/trait_types.go
index 82aa32ecd..c420e0095 100644
--- a/pkg/trait/trait_types.go
+++ b/pkg/trait/trait_types.go
@@ -251,6 +251,20 @@ func (e *Environment) IntegrationKitInPhase(phases 
...v1.IntegrationKitPhase) bo
        return false
 }
 
+func (e *Environment) PlatformInPhase(phases ...v1.IntegrationPlatformPhase) 
bool {
+       if e.Platform == nil {
+               return false
+       }
+
+       for _, phase := range phases {
+               if e.Platform.Status.Phase == phase {
+                       return true
+               }
+       }
+
+       return false
+}
+
 func (e *Environment) InPhase(c v1.IntegrationKitPhase, i v1.IntegrationPhase) 
bool {
        return e.IntegrationKitInPhase(c) && e.IntegrationInPhase(i)
 }

Reply via email to