Skip to content

Commit

Permalink
fix(trait): don't report runtime version...
Browse files Browse the repository at this point in the history
... for external kit or syntetic Integrations.

As a side effect, we had to introduce a further check to avoid leveraging a Camel catalog which was taken as default.

Closes apache#5309
  • Loading branch information
squakez committed Apr 23, 2024
1 parent a5c2ce7 commit 36bae83
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 8 deletions.
15 changes: 8 additions & 7 deletions pkg/trait/camel.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ func (t *camelTrait) Matches(trait Trait) bool {
}

func (t *camelTrait) Configure(e *Environment) (bool, *TraitCondition, error) {
if e.IntegrationKit != nil && e.IntegrationKit.IsExternal() {
return false, newIntegrationConditionPlatformDisabledWithMessage("Camel", "integration kit was not created via Camel K operator"), nil
}
if e.Integration != nil && e.Integration.IsSynthetic() {
return false, newIntegrationConditionPlatformDisabledWithMessage("Camel", "syntetic integration"), nil
}

if t.RuntimeVersion == "" {
if runtimeVersion, err := determineRuntimeVersion(e); err != nil {
return false, nil, err
Expand All @@ -71,21 +78,15 @@ func (t *camelTrait) Configure(e *Environment) (bool, *TraitCondition, error) {
}
}

// Don't run this trait for a synthetic Integration
return e.Integration == nil || !e.Integration.IsSynthetic(), nil, nil
return true, nil, nil
}

func (t *camelTrait) Apply(e *Environment) error {
if t.RuntimeVersion == "" {
return errors.New("unable to determine runtime version")
}

if e.CamelCatalog == nil {
if err := t.loadOrCreateCatalog(e, t.RuntimeVersion); err != nil {
return err
}
}

e.RuntimeVersion = e.CamelCatalog.Runtime.Version

if e.Integration != nil {
Expand Down
29 changes: 29 additions & 0 deletions pkg/trait/camel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,3 +246,32 @@ func TestCamelCatalogSemver(t *testing.T) {
// 2.x will translate with 2.16.0 as it is already existing
assert.Equal(t, environment.CamelCatalog.CamelCatalogSpec.Runtime.Version, environment.RuntimeVersion)
}

func TestCamelTraitExternalKit(t *testing.T) {
trait, environment := createNominalCamelTest(true)
environment.Integration.Status = v1.IntegrationStatus{}
environment.IntegrationKit.Labels[v1.IntegrationKitTypeLabel] = v1.IntegrationKitTypeExternal

configured, condition, err := trait.Configure(environment)
require.NoError(t, err)
assert.Equal(t, "explicitly disabled by the platform: integration kit was not created via Camel K operator", condition.message)
assert.False(t, configured)

assert.Equal(t, v1.RuntimeProvider(""), environment.Integration.Status.RuntimeProvider)
assert.Equal(t, "", environment.Integration.Status.RuntimeVersion)
}

func TestCamelTraitSyntheticIntegration(t *testing.T) {
trait, environment := createNominalCamelTest(true)
environment.Integration.Status = v1.IntegrationStatus{}
environment.Integration.Annotations = make(map[string]string)
environment.Integration.Annotations[v1.IntegrationSyntheticLabel] = "true"

configured, condition, err := trait.Configure(environment)
require.NoError(t, err)
assert.Equal(t, "explicitly disabled by the platform: syntetic integration", condition.message)
assert.False(t, configured)

assert.Equal(t, v1.RuntimeProvider(""), environment.Integration.Status.RuntimeProvider)
assert.Equal(t, "", environment.Integration.Status.RuntimeVersion)
}
3 changes: 3 additions & 0 deletions pkg/trait/cron.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ func (t *cronTrait) Configure(e *Environment) (bool, *TraitCondition, error) {
if !e.IntegrationInPhase(v1.IntegrationPhaseInitialization) && !e.IntegrationInRunningPhases() {
return false, nil, nil
}
if e.CamelCatalog == nil {
return false, newIntegrationConditionPlatformDisabledWithMessage("Cron", "no camel catalog available for this Integration"), nil
}

if _, ok := e.CamelCatalog.Runtime.Capabilities[v1.CapabilityCron]; !ok {
return false, NewIntegrationCondition(
Expand Down
3 changes: 3 additions & 0 deletions pkg/trait/jvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ func (t *jvmTrait) Configure(e *Environment) (bool, *TraitCondition, error) {
return false, newIntegrationConditionPlatformDisabledWithMessage("JVM", "integration kit was not created via Camel K operator"), nil
}

if e.CamelCatalog == nil {
return false, newIntegrationConditionPlatformDisabledWithMessage("JVM", "no camel catalog available for this Integration"), nil
}
return true, nil, nil
}

Expand Down
4 changes: 3 additions & 1 deletion pkg/trait/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,12 @@ func (l loggingTrait) Configure(e *Environment) (bool, *TraitCondition, error) {
if e.Integration == nil {
return false, nil, nil
}

if !pointer.BoolDeref(l.Enabled, true) {
return false, NewIntegrationConditionUserDisabled("Logging"), nil
}
if e.CamelCatalog == nil {
return false, newIntegrationConditionPlatformDisabledWithMessage("Logging", "no camel catalog available for this Integration"), nil
}

return e.IntegrationInRunningPhases(), nil, nil
}
Expand Down

0 comments on commit 36bae83

Please sign in to comment.