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 8f830deba4e77c38be2b94cfea804d82c89a85ab
Author: Antonin Stefanutti <[email protected]>
AuthorDate: Wed Sep 7 15:14:58 2022 +0200

    fix: camel trait should fail-fast when runtime version is nil
---
 pkg/trait/camel.go | 39 +++++++++++++++++++++++----------------
 1 file changed, 23 insertions(+), 16 deletions(-)

diff --git a/pkg/trait/camel.go b/pkg/trait/camel.go
index 17f847560..82f0e91c2 100644
--- a/pkg/trait/camel.go
+++ b/pkg/trait/camel.go
@@ -24,6 +24,7 @@ import (
        "strings"
 
        "github.com/pkg/errors"
+
        corev1 "k8s.io/api/core/v1"
        metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
        "k8s.io/utils/pointer"
@@ -52,20 +53,26 @@ func (t *camelTrait) Configure(e *Environment) (bool, 
error) {
                return false, errors.New("trait camel cannot be disabled")
        }
 
+       if t.RuntimeVersion == "" {
+               t.RuntimeVersion = determineRuntimeVersion(e)
+       }
+
        return true, nil
 }
 
 func (t *camelTrait) Apply(e *Environment) error {
-       rv := t.determineRuntimeVersion(e)
+       if t.RuntimeVersion == "" {
+               return errors.New("unable to determine runtime version")
+       }
 
        if e.CamelCatalog == nil {
-               err := t.loadOrCreateCatalog(e, rv)
+               err := t.loadOrCreateCatalog(e, t.RuntimeVersion)
                if err != nil {
                        return err
                }
        }
 
-       e.RuntimeVersion = rv
+       e.RuntimeVersion = t.RuntimeVersion
 
        if e.Integration != nil {
                e.Integration.Status.RuntimeVersion = 
e.CamelCatalog.Runtime.Version
@@ -144,19 +151,6 @@ func (t *camelTrait) loadOrCreateCatalog(e *Environment, 
runtimeVersion string)
        return nil
 }
 
-func (t *camelTrait) determineRuntimeVersion(e *Environment) string {
-       if t.RuntimeVersion != "" {
-               return t.RuntimeVersion
-       }
-       if e.Integration != nil && e.Integration.Status.RuntimeVersion != "" {
-               return e.Integration.Status.RuntimeVersion
-       }
-       if e.IntegrationKit != nil && e.IntegrationKit.Status.RuntimeVersion != 
"" {
-               return e.IntegrationKit.Status.RuntimeVersion
-       }
-       return e.Platform.Status.Build.RuntimeVersion
-}
-
 // IsPlatformTrait overrides base class method.
 func (t *camelTrait) IsPlatformTrait() bool {
        return true
@@ -287,3 +281,16 @@ func (t *camelTrait) computeConfigMaps(e *Environment) 
[]ctrl.Object {
 
        return maps
 }
+
+func determineRuntimeVersion(e *Environment) string {
+       if e.Integration != nil && e.Integration.Status.RuntimeVersion != "" {
+               return e.Integration.Status.RuntimeVersion
+       }
+       if e.IntegrationKit != nil && e.IntegrationKit.Status.RuntimeVersion != 
"" {
+               return e.IntegrationKit.Status.RuntimeVersion
+       }
+       if e.Platform != nil && e.Platform.Status.Build.RuntimeVersion != "" {
+               return e.Platform.Status.Build.RuntimeVersion
+       }
+       return ""
+}

Reply via email to