You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by pc...@apache.org on 2024/08/28 08:58:00 UTC

(camel-k) 03/04: chore(traits): removed camel catalog condition

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

commit eba01873efaf3303d2677f7c1b65fe61efbd5d85
Author: Pasquale Congiusti <pa...@gmail.com>
AuthorDate: Thu Aug 22 10:48:36 2024 +0200

    chore(traits): removed camel catalog condition
    
    The default is to have a CamelCatalog, so, there is no need to skip traits any longer
---
 addons/keda/keda.go                |  3 ---
 addons/master/master.go            |  4 ----
 addons/resume/resume.go            |  3 ---
 addons/telemetry/telemetry.go      | 11 ++---------
 addons/telemetry/telemetry_test.go |  3 ---
 pkg/trait/builder.go               |  3 ---
 pkg/trait/cron.go                  |  3 ---
 pkg/trait/dependencies.go          |  3 ---
 pkg/trait/error_handler.go         |  4 ----
 pkg/trait/health.go                |  6 +++---
 pkg/trait/kamelets.go              |  5 -----
 pkg/trait/kamelets_test.go         |  9 ++++-----
 pkg/trait/knative.go               | 10 ++--------
 pkg/trait/knative_test.go          |  5 +----
 pkg/trait/logging.go               |  2 +-
 pkg/trait/openapi.go               |  8 +-------
 pkg/trait/quarkus.go               |  3 ---
 pkg/trait/service.go               |  3 ---
 pkg/trait/service_binding.go       |  3 ---
 pkg/trait/trait_condition_types.go | 15 ---------------
 20 files changed, 14 insertions(+), 92 deletions(-)

diff --git a/addons/keda/keda.go b/addons/keda/keda.go
index 3060d48b3..531753827 100644
--- a/addons/keda/keda.go
+++ b/addons/keda/keda.go
@@ -119,9 +119,6 @@ func (t *kedaTrait) Configure(e *trait.Environment) (bool, *trait.TraitCondition
 	if e.Integration == nil || !ptr.Deref(t.Enabled, false) {
 		return false, nil, nil
 	}
-	if e.CamelCatalog == nil {
-		return false, trait.NewIntegrationConditionPlatformDisabledCatalogMissing(), nil
-	}
 	if !e.IntegrationInPhase(camelv1.IntegrationPhaseInitialization) && !e.IntegrationInRunningPhases() {
 		return false, nil, nil
 	}
diff --git a/addons/master/master.go b/addons/master/master.go
index 5ebc04c79..f893e19bc 100644
--- a/addons/master/master.go
+++ b/addons/master/master.go
@@ -88,13 +88,9 @@ func (t *masterTrait) Configure(e *trait.Environment) (bool, *trait.TraitConditi
 	if !ptr.Deref(t.Enabled, true) {
 		return false, trait.NewIntegrationConditionUserDisabled(masterComponent), nil
 	}
-	if e.CamelCatalog == nil {
-		return false, trait.NewIntegrationConditionPlatformDisabledCatalogMissing(), nil
-	}
 	if !e.IntegrationInPhase(v1.IntegrationPhaseInitialization, v1.IntegrationPhaseBuildingKit) && !e.IntegrationInRunningPhases() {
 		return false, nil, nil
 	}
-
 	if !ptr.Deref(t.Auto, true) {
 		return ptr.Deref(t.Enabled, false), nil, nil
 	}
diff --git a/addons/resume/resume.go b/addons/resume/resume.go
index 6fed7e3bf..45d56756c 100644
--- a/addons/resume/resume.go
+++ b/addons/resume/resume.go
@@ -78,9 +78,6 @@ func (r *resumeTrait) Configure(environment *trait.Environment) (bool, *trait.Tr
 	if !ptr.Deref(r.Enabled, false) {
 		return false, nil, nil
 	}
-	if environment.CamelCatalog == nil {
-		return false, trait.NewIntegrationConditionPlatformDisabledCatalogMissing(), nil
-	}
 	if !environment.IntegrationInPhase(v1.IntegrationPhaseInitialization) && !environment.IntegrationInRunningPhases() {
 		return false, nil, nil
 	}
diff --git a/addons/telemetry/telemetry.go b/addons/telemetry/telemetry.go
index 806bbd1b9..07908c13f 100644
--- a/addons/telemetry/telemetry.go
+++ b/addons/telemetry/telemetry.go
@@ -90,17 +90,10 @@ func NewTelemetryTrait() trait.Trait {
 	}
 }
 
-func (t *telemetryTrait) isForcefullyEnabled() bool {
-	return ptr.Deref(t.Enabled, false) && !ptr.Deref(t.Auto, true)
-}
-
 func (t *telemetryTrait) Configure(e *trait.Environment) (bool, *trait.TraitCondition, error) {
 	if e.Integration == nil || !ptr.Deref(t.Enabled, false) {
 		return false, nil, nil
 	}
-	if e.CamelCatalog == nil && !t.isForcefullyEnabled() {
-		return false, trait.NewIntegrationConditionPlatformDisabledCatalogMissing(), nil
-	}
 
 	if !ptr.Deref(t.Auto, true) {
 		return true, nil, nil
@@ -143,7 +136,7 @@ func (t *telemetryTrait) Configure(e *trait.Environment) (bool, *trait.TraitCond
 func (t *telemetryTrait) Apply(e *trait.Environment) error {
 	util.StringSliceUniqueAdd(&e.Integration.Status.Capabilities, v1.CapabilityTelemetry)
 
-	if t.isForcefullyEnabled() || e.CamelCatalog.Runtime.Capabilities["telemetry"].RuntimeProperties != nil {
+	if e.CamelCatalog.Runtime.Capabilities["telemetry"].RuntimeProperties != nil {
 		t.setCatalogConfiguration(e)
 	} else {
 		t.setRuntimeProviderProperties(e)
@@ -175,7 +168,7 @@ func (t *telemetryTrait) setCatalogConfiguration(e *trait.Environment) {
 		e.ApplicationProperties["camel.k.telemetry.samplerParentBased"] = boolean.FalseString
 	}
 
-	if e.CamelCatalog != nil && e.CamelCatalog.Runtime.Capabilities["telemetry"].RuntimeProperties != nil {
+	if e.CamelCatalog.Runtime.Capabilities["telemetry"].RuntimeProperties != nil {
 		for _, cp := range e.CamelCatalog.Runtime.Capabilities["telemetry"].RuntimeProperties {
 			e.ApplicationProperties[trait.CapabilityPropertyKey(cp.Key, e.ApplicationProperties)] = cp.Value
 		}
diff --git a/addons/telemetry/telemetry_test.go b/addons/telemetry/telemetry_test.go
index d85431270..ad57ba96c 100644
--- a/addons/telemetry/telemetry_test.go
+++ b/addons/telemetry/telemetry_test.go
@@ -93,8 +93,6 @@ func TestTelemetryTraitWithValues(t *testing.T) {
 
 func TestTelemetryForSourceless(t *testing.T) {
 	e := createEnvironment(t, camel.QuarkusCatalog)
-	// CamelCatalog not necessarily available during a sourceless deployment
-	e.CamelCatalog = nil
 	telemetry := NewTelemetryTrait()
 	tt, _ := telemetry.(*telemetryTrait)
 	tt.Enabled = ptr.To(true)
@@ -104,7 +102,6 @@ func TestTelemetryForSourceless(t *testing.T) {
 	tt.Sampler = "ratio"
 	tt.SamplerRatio = "0.001"
 	tt.SamplerParentBased = ptr.To(false)
-	assert.True(t, tt.isForcefullyEnabled())
 
 	ok, condition, err := telemetry.Configure(e)
 	require.NoError(t, err)
diff --git a/pkg/trait/builder.go b/pkg/trait/builder.go
index 6ba5d7f7f..bb4cdc159 100644
--- a/pkg/trait/builder.go
+++ b/pkg/trait/builder.go
@@ -93,9 +93,6 @@ func (t *builderTrait) Configure(e *Environment) (bool, *TraitCondition, error)
 	if e.IntegrationKit == nil {
 		return false, nil, nil
 	}
-	if e.CamelCatalog == nil {
-		return false, NewIntegrationConditionPlatformDisabledCatalogMissing(), nil
-	}
 	condition := t.adaptDeprecatedFields()
 	if e.Platform.Status.Build.PublishStrategy == v1.IntegrationPlatformBuildPublishStrategySpectrum {
 		condition = newOrAppend(condition, "Spectrum publishing strategy is deprecated and may be removed in future releases. Make sure to use any supported publishing strategy instead.")
diff --git a/pkg/trait/cron.go b/pkg/trait/cron.go
index 55945f132..b86216041 100644
--- a/pkg/trait/cron.go
+++ b/pkg/trait/cron.go
@@ -88,9 +88,6 @@ 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, NewIntegrationConditionPlatformDisabledCatalogMissing(), nil
-	}
 	if _, ok := e.CamelCatalog.Runtime.Capabilities[v1.CapabilityCron]; !ok {
 		return false, NewIntegrationCondition(
 			"Cron",
diff --git a/pkg/trait/dependencies.go b/pkg/trait/dependencies.go
index 187e3bc26..55b1559de 100644
--- a/pkg/trait/dependencies.go
+++ b/pkg/trait/dependencies.go
@@ -46,9 +46,6 @@ func (t *dependenciesTrait) Configure(e *Environment) (bool, *TraitCondition, er
 	if e.Integration == nil {
 		return false, nil, nil
 	}
-	if e.CamelCatalog == nil {
-		return false, NewIntegrationConditionPlatformDisabledCatalogMissing(), nil
-	}
 	return e.IntegrationInPhase(v1.IntegrationPhaseInitialization), nil, nil
 }
 
diff --git a/pkg/trait/error_handler.go b/pkg/trait/error_handler.go
index 3aa8c1c84..05eabeaa1 100644
--- a/pkg/trait/error_handler.go
+++ b/pkg/trait/error_handler.go
@@ -49,10 +49,6 @@ func (t *errorHandlerTrait) Configure(e *Environment) (bool, *TraitCondition, er
 	if e.Integration == nil {
 		return false, nil, nil
 	}
-	if e.CamelCatalog == nil {
-		return false, NewIntegrationConditionPlatformDisabledCatalogMissing(), nil
-	}
-
 	if !e.IntegrationInPhase(v1.IntegrationPhaseInitialization) && !e.IntegrationInRunningPhases() {
 		return false, nil, nil
 	}
diff --git a/pkg/trait/health.go b/pkg/trait/health.go
index c4b7e6eec..98d87b046 100644
--- a/pkg/trait/health.go
+++ b/pkg/trait/health.go
@@ -76,7 +76,7 @@ func (t *healthTrait) Configure(e *Environment) (bool, *TraitCondition, error) {
 
 func (t *healthTrait) setProbesValues(e *Environment) {
 	if t.LivenessProbe == "" {
-		if e.CamelCatalog != nil && e.CamelCatalog.Runtime.Capabilities["health"].Metadata != nil {
+		if e.CamelCatalog.Runtime.Capabilities["health"].Metadata != nil {
 			t.LivenessProbe = e.CamelCatalog.Runtime.Capabilities["health"].Metadata["defaultLivenessProbePath"]
 		} else {
 			// Deprecated: to be removed
@@ -84,7 +84,7 @@ func (t *healthTrait) setProbesValues(e *Environment) {
 		}
 	}
 	if t.ReadinessProbe == "" {
-		if e.CamelCatalog != nil && e.CamelCatalog.Runtime.Capabilities["health"].Metadata != nil {
+		if e.CamelCatalog.Runtime.Capabilities["health"].Metadata != nil {
 			t.ReadinessProbe = e.CamelCatalog.Runtime.Capabilities["health"].Metadata["defaultReadinessProbePath"]
 		} else {
 			// Deprecated: to be removed
@@ -92,7 +92,7 @@ func (t *healthTrait) setProbesValues(e *Environment) {
 		}
 	}
 	if t.StartupProbe == "" {
-		if e.CamelCatalog != nil && e.CamelCatalog.Runtime.Capabilities["health"].Metadata != nil {
+		if e.CamelCatalog.Runtime.Capabilities["health"].Metadata != nil {
 			t.StartupProbe = e.CamelCatalog.Runtime.Capabilities["health"].Metadata["defaultStartupProbePath"]
 		} else {
 			// Deprecated: to be removed
diff --git a/pkg/trait/kamelets.go b/pkg/trait/kamelets.go
index 936770b6d..912bb6397 100644
--- a/pkg/trait/kamelets.go
+++ b/pkg/trait/kamelets.go
@@ -78,11 +78,6 @@ func (t *kameletsTrait) Configure(e *Environment) (bool, *TraitCondition, error)
 		t.MountPoint = filepath.Join(camel.BasePath, "kamelets")
 	}
 	if ptr.Deref(t.Auto, true) {
-		if e.CamelCatalog == nil {
-			// Cannot execute this trait for synthetic IntegrationKit. In order to use it, the
-			// user has to specify forcefully auto=false option and pass a list of kamelets explicitly
-			return false, NewIntegrationConditionPlatformDisabledCatalogMissing(), nil
-		}
 		var kamelets []string
 		_, err := e.ConsumeMeta(func(meta metadata.IntegrationMetadata) bool {
 			util.StringSliceUniqueConcat(&kamelets, meta.Kamelets)
diff --git a/pkg/trait/kamelets_test.go b/pkg/trait/kamelets_test.go
index afa018df1..d59e56d79 100644
--- a/pkg/trait/kamelets_test.go
+++ b/pkg/trait/kamelets_test.go
@@ -618,17 +618,16 @@ func TestKameletSyntheticKitAutoConditionFalse(t *testing.T) {
 				}),
 			},
 		})
-	environment.CamelCatalog = nil
 	environment.Integration.Spec.Sources = nil
 	trait.List = "timer-source"
 
-	// Auto=true by default, so, we will need to skip as
-	// we cannot parse sources
+	// Auto=true by default. The source parsing will be empty as
+	// there are no available sources.
 
 	enabled, condition, err := trait.Configure(environment)
 	require.NoError(t, err)
-	assert.False(t, enabled)
-	assert.NotNil(t, condition)
+	assert.True(t, enabled)
+	assert.Nil(t, condition)
 
 	kameletsBundle := environment.Resources.GetConfigMap(func(cm *corev1.ConfigMap) bool {
 		return cm.Labels[kubernetes.ConfigMapTypeLabel] == KameletBundleType
diff --git a/pkg/trait/knative.go b/pkg/trait/knative.go
index de24fc9aa..9f5233728 100644
--- a/pkg/trait/knative.go
+++ b/pkg/trait/knative.go
@@ -76,12 +76,6 @@ func (t *knativeTrait) Configure(e *Environment) (bool, *TraitCondition, error)
 	if !ptr.Deref(t.Enabled, true) {
 		return false, NewIntegrationConditionUserDisabled("Knative"), nil
 	}
-	if e.CamelCatalog == nil {
-		if ptr.Deref(t.Enabled, false) {
-			return true, nil, nil
-		}
-		return false, NewIntegrationConditionPlatformDisabledCatalogMissing(), nil
-	}
 	if !e.IntegrationInPhase(v1.IntegrationPhaseInitialization) && !e.IntegrationInRunningPhases() {
 		return false, nil, nil
 	}
@@ -130,8 +124,8 @@ func (t *knativeTrait) Configure(e *Environment) (bool, *TraitCondition, error)
 	}
 
 	hasKnativeEndpoint := len(t.ChannelSources) > 0 || len(t.ChannelSinks) > 0 || len(t.EndpointSources) > 0 || len(t.EndpointSinks) > 0 || len(t.EventSources) > 0 || len(t.EventSinks) > 0
-	t.Enabled = &hasKnativeEndpoint
-	if !hasKnativeEndpoint {
+
+	if !hasKnativeEndpoint && !ptr.Deref(t.Enabled, false) {
 		return false, nil, nil
 	}
 	if !knativeInstalled {
diff --git a/pkg/trait/knative_test.go b/pkg/trait/knative_test.go
index 9aaadba60..7a8a7e45f 100644
--- a/pkg/trait/knative_test.go
+++ b/pkg/trait/knative_test.go
@@ -1303,8 +1303,6 @@ func TestKnativeEnabled(t *testing.T) {
 
 	// apply the knative trait
 	require.NoError(t, knTrait.Apply(&environment))
-
-	assert.True(t, *knTrait.Enabled)
 	assert.Contains(t, environment.Integration.Status.Capabilities, v1.CapabilityKnative)
 }
 
@@ -1704,14 +1702,13 @@ func TestKnativeSyntheticKitDefault(t *testing.T) {
 	ok, condition, err := knTrait.Configure(&e)
 	require.NoError(t, err)
 	assert.False(t, ok)
-	assert.NotNil(t, condition)
+	assert.Nil(t, condition)
 }
 
 func TestKnativeSyntheticKitEnabled(t *testing.T) {
 	e := NewFakeEnvironmentForSyntheticKit(t)
 	knTrait, _ := newKnativeTrait().(*knativeTrait)
 	knTrait.Enabled = ptr.To(true)
-	knTrait.Auto = ptr.To(false)
 	ok, condition, err := knTrait.Configure(&e)
 	require.NoError(t, err)
 	assert.True(t, ok)
diff --git a/pkg/trait/logging.go b/pkg/trait/logging.go
index 60cdb4113..fdd6656a4 100644
--- a/pkg/trait/logging.go
+++ b/pkg/trait/logging.go
@@ -62,7 +62,7 @@ func (l loggingTrait) Configure(e *Environment) (bool, *TraitCondition, error) {
 }
 
 func (l loggingTrait) Apply(e *Environment) error {
-	if e.CamelCatalog != nil && e.CamelCatalog.Runtime.Capabilities["logging"].RuntimeProperties != nil {
+	if e.CamelCatalog.Runtime.Capabilities["logging"].RuntimeProperties != nil {
 		l.setCatalogConfiguration(e)
 	} else {
 		l.setEnvConfiguration(e)
diff --git a/pkg/trait/openapi.go b/pkg/trait/openapi.go
index cb201d080..fbc1bf49d 100644
--- a/pkg/trait/openapi.go
+++ b/pkg/trait/openapi.go
@@ -202,13 +202,7 @@ func (t *openAPITrait) createNewOpenAPIConfigMap(e *Environment, resource v1.Dat
 		return err
 	}
 
-	// If the catalog is missing, we use the default version used by the IntegrationPlatform
-	runtimeVersion := e.Platform.Status.Build.RuntimeVersion
-	if e.CamelCatalog != nil {
-		runtimeVersion = e.CamelCatalog.Runtime.Version
-	}
-
-	project := t.generateMavenProject(runtimeVersion)
+	project := t.generateMavenProject(e.CamelCatalog.Runtime.Version)
 	mc := maven.NewContext(tmpDir)
 	mc.LocalRepository = e.Platform.Status.Build.Maven.LocalRepository
 	mc.AdditionalArguments = e.Platform.Status.Build.Maven.CLIOptions
diff --git a/pkg/trait/quarkus.go b/pkg/trait/quarkus.go
index d720db315..b161ee6fb 100644
--- a/pkg/trait/quarkus.go
+++ b/pkg/trait/quarkus.go
@@ -140,9 +140,6 @@ func (t *quarkusTrait) Matches(trait Trait) bool {
 }
 
 func (t *quarkusTrait) Configure(e *Environment) (bool, *TraitCondition, error) {
-	if e.CamelCatalog == nil {
-		return false, NewIntegrationConditionPlatformDisabledCatalogMissing(), nil
-	}
 	condition := t.adaptDeprecatedFields()
 
 	return e.IntegrationInPhase(v1.IntegrationPhaseBuildingKit) ||
diff --git a/pkg/trait/service.go b/pkg/trait/service.go
index 8ed054700..087f289db 100644
--- a/pkg/trait/service.go
+++ b/pkg/trait/service.go
@@ -58,9 +58,6 @@ func (t *serviceTrait) Configure(e *Environment) (bool, *TraitCondition, error)
 			"explicitly disabled",
 		), nil
 	}
-	if e.CamelCatalog == nil {
-		return false, NewIntegrationConditionPlatformDisabledCatalogMissing(), nil
-	}
 	// in case the knative-service and service trait are enabled, the knative-service has priority
 	// then this service is disabled
 	if e.GetTrait(knativeServiceTraitID) != nil {
diff --git a/pkg/trait/service_binding.go b/pkg/trait/service_binding.go
index e2956858f..b8fd4ba45 100644
--- a/pkg/trait/service_binding.go
+++ b/pkg/trait/service_binding.go
@@ -74,9 +74,6 @@ func (t *serviceBindingTrait) Configure(e *Environment) (bool, *TraitCondition,
 	if !ptr.Deref(t.Enabled, true) {
 		return false, NewIntegrationConditionUserDisabled("ServiceBinding"), nil
 	}
-	if e.CamelCatalog == nil {
-		return false, NewIntegrationConditionPlatformDisabledCatalogMissing(), nil
-	}
 	if len(t.Services) == 0 {
 		return false, nil, nil
 	}
diff --git a/pkg/trait/trait_condition_types.go b/pkg/trait/trait_condition_types.go
index f1febd59a..942a3dbd6 100644
--- a/pkg/trait/trait_condition_types.go
+++ b/pkg/trait/trait_condition_types.go
@@ -56,25 +56,10 @@ func NewIntegrationConditionUserDisabled(traitID string) *TraitCondition {
 	return NewIntegrationCondition(traitID, v1.IntegrationConditionTraitInfo, corev1.ConditionTrue, traitConfigurationReason, userDisabledMessage)
 }
 
-func NewIntegrationConditionUserEnabledWithMessage(traitID string, message string) *TraitCondition {
-	return NewIntegrationCondition(traitID, v1.IntegrationConditionTraitInfo, corev1.ConditionTrue, traitConfigurationReason, fmt.Sprintf("%s: %s", userEnabledMessage, message))
-}
-
 func NewIntegrationConditionPlatformDisabledWithMessage(traitID string, message string) *TraitCondition {
 	return NewIntegrationCondition(traitID, v1.IntegrationConditionTraitInfo, corev1.ConditionTrue, traitConfigurationReason, fmt.Sprintf("%s: %s", platformDisabledMessage, message))
 }
 
-// This one is reused among different traits in order to avoid polluting the conditions with the same message.
-func NewIntegrationConditionPlatformDisabledCatalogMissing() *TraitCondition {
-	return NewIntegrationCondition(
-		"Generic",
-		v1.IntegrationConditionTraitInfo,
-		corev1.ConditionTrue,
-		traitConfigurationReason,
-		"no camel catalog available for this Integration. Several traits have not been executed for this reason. Check applied trait condition to know more.",
-	)
-}
-
 func (tc *TraitCondition) integrationCondition() (v1.IntegrationConditionType, corev1.ConditionStatus, string, string) {
 	return v1.IntegrationConditionType(tc.typeForCondition()),
 		tc.conditionStatus,