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 2023/12/19 14:10:18 UTC

(camel-k) branch main updated: Updating source checks for native builds (#4987)

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


The following commit(s) were added to refs/heads/main by this push:
     new 011bf47a5 Updating source checks for native builds (#4987)
011bf47a5 is described below

commit 011bf47a5a896236c77847ad255e2a9c90948ee4
Author: Hernan Guardado <72...@users.noreply.github.com>
AuthorDate: Tue Dec 19 09:10:12 2023 -0500

    Updating source checks for native builds (#4987)
    
    * Adding language settings check for native builds
    
    * Added functionality to get specific camel catalog version
    
    * Reverting changes for version catalog lookup and native kit check
    
    * reverting additional changes
    
    * Updating test function calls
    
    * Replacing integration sources reference
    
    * Refactoring for integration AllSources & UserDefinedSources
    
    ---------
    
    Co-authored-by: Hernan Guardado <he...@Hernans-MBP.frontiernet.net>
    Co-authored-by: Hernan Guardado <he...@Hernans-MBP.lan>
---
 pkg/apis/camel/v1/integration_types_support.go |  8 +++++++-
 pkg/cmd/describe_integration.go                |  6 +++---
 pkg/controller/integration/kits.go             |  8 ++++----
 pkg/controller/integration/kits_test.go        | 12 ++++++------
 pkg/trait/camel.go                             |  2 +-
 pkg/trait/mount.go                             |  2 +-
 pkg/trait/quarkus.go                           |  6 +++---
 pkg/trait/trait_types.go                       |  6 +++---
 pkg/util/kubernetes/resolver.go                |  2 +-
 9 files changed, 29 insertions(+), 23 deletions(-)

diff --git a/pkg/apis/camel/v1/integration_types_support.go b/pkg/apis/camel/v1/integration_types_support.go
index 4ad79634f..ef24e207b 100644
--- a/pkg/apis/camel/v1/integration_types_support.go
+++ b/pkg/apis/camel/v1/integration_types_support.go
@@ -61,7 +61,7 @@ func (in *Integration) Initialize() {
 }
 
 // Sources return a new slice containing all the sources associated to the integration.
-func (in *Integration) Sources() []SourceSpec {
+func (in *Integration) AllSources() []SourceSpec {
 	sources := make([]SourceSpec, 0, len(in.Spec.Sources)+len(in.Status.GeneratedSources))
 	sources = append(sources, in.Spec.Sources...)
 	sources = append(sources, in.Status.GeneratedSources...)
@@ -69,6 +69,12 @@ func (in *Integration) Sources() []SourceSpec {
 	return sources
 }
 
+func (in *Integration) UserDefinedSources() []SourceSpec {
+	sources := make([]SourceSpec, 0, len(in.Spec.Sources))
+	sources = append(sources, in.Spec.Sources...)
+	return sources
+}
+
 func (in *IntegrationSpec) AddSource(name string, content string, language Language) {
 	in.Sources = append(in.Sources, NewSourceSpec(name, content, language))
 }
diff --git a/pkg/cmd/describe_integration.go b/pkg/cmd/describe_integration.go
index 848d40518..c18b21918 100644
--- a/pkg/cmd/describe_integration.go
+++ b/pkg/cmd/describe_integration.go
@@ -135,10 +135,10 @@ func (command *describeIntegrationCommandOptions) describeIntegration(cmd *cobra
 			}
 		}
 
-		if len(i.Sources()) > 0 {
+		if len(i.AllSources()) > 0 {
 			w.Writef(0, "Sources:\n")
 			if command.showSourceContent {
-				for _, s := range i.Sources() {
+				for _, s := range i.AllSources() {
 					w.Writef(1, "Name:\t%s\n", s.Name)
 					w.Writef(1, "Language:\t%s\n", s.InferLanguage())
 					w.Writef(1, "Compression:\t%t\n", s.Compression)
@@ -154,7 +154,7 @@ func (command *describeIntegrationCommandOptions) describeIntegration(cmd *cobra
 			} else {
 				//nolint:dupword
 				w.Writef(1, "Name\tLanguage\tCompression\tRef\tRef Key\n")
-				for _, s := range i.Sources() {
+				for _, s := range i.AllSources() {
 					w.Writef(1, "%s\t%s\t%t\t%s\t%s\n",
 						s.Name,
 						s.InferLanguage(),
diff --git a/pkg/controller/integration/kits.go b/pkg/controller/integration/kits.go
index e26c9f544..5cdfb0678 100644
--- a/pkg/controller/integration/kits.go
+++ b/pkg/controller/integration/kits.go
@@ -133,7 +133,7 @@ func integrationMatches(integration *v1.Integration, kit *v1.IntegrationKit) (bo
 	}
 	// If IntegrationKit has any source, we must verify that it corresponds with the one in the Integration.
 	// This is important in case of Native builds as we need to rebuild when language requires a source during build.
-	if (kit.Spec.Sources != nil && len(kit.Spec.Sources) > 0) && !hasMatchingSources(integration, kit) {
+	if (kit.Spec.Sources != nil && len(kit.Spec.Sources) > 0) && !hasMatchingSourcesForNative(integration, kit) {
 		ilog.Debug("Integration and integration-kit sources do not match", "integration", integration.Name, "integration-kit", kit.Name, "namespace", integration.Namespace)
 		return false, nil
 	}
@@ -256,11 +256,11 @@ func matchesTrait(it map[string]interface{}, kt map[string]interface{}) bool {
 	return reflect.DeepEqual(it, kt)
 }
 
-func hasMatchingSources(it *v1.Integration, kit *v1.IntegrationKit) bool {
-	if len(it.Sources()) != len(kit.Spec.Sources) {
+func hasMatchingSourcesForNative(it *v1.Integration, kit *v1.IntegrationKit) bool {
+	if len(it.UserDefinedSources()) != len(kit.Spec.Sources) {
 		return false
 	}
-	for _, itSource := range it.Sources() {
+	for _, itSource := range it.UserDefinedSources() {
 		found := false
 		for _, ikSource := range kit.Spec.Sources {
 			if itSource.Content == ikSource.Content {
diff --git a/pkg/controller/integration/kits_test.go b/pkg/controller/integration/kits_test.go
index 0a12ab3c6..173d884cf 100644
--- a/pkg/controller/integration/kits_test.go
+++ b/pkg/controller/integration/kits_test.go
@@ -343,7 +343,7 @@ func TestHasMatchingSources(t *testing.T) {
 		},
 	}
 
-	hms := hasMatchingSources(integration, kit)
+	hms := hasMatchingSourcesForNative(integration, kit)
 	assert.True(t, hms)
 
 	kit2 := &v1.IntegrationKit{
@@ -355,7 +355,7 @@ func TestHasMatchingSources(t *testing.T) {
 		},
 	}
 
-	hms2 := hasMatchingSources(integration, kit2)
+	hms2 := hasMatchingSourcesForNative(integration, kit2)
 	assert.False(t, hms2)
 }
 
@@ -378,7 +378,7 @@ func TestHasMatchingMultipleSources(t *testing.T) {
 		},
 	}
 
-	hms := hasMatchingSources(integration, kit)
+	hms := hasMatchingSourcesForNative(integration, kit)
 	assert.True(t, hms)
 
 	integration2 := &v1.Integration{
@@ -389,7 +389,7 @@ func TestHasMatchingMultipleSources(t *testing.T) {
 		},
 	}
 
-	hms2 := hasMatchingSources(integration2, kit)
+	hms2 := hasMatchingSourcesForNative(integration2, kit)
 	assert.False(t, hms2)
 }
 
@@ -410,7 +410,7 @@ func TestHasNotMatchingSources(t *testing.T) {
 		},
 	}
 
-	hsm := hasMatchingSources(integration, kit)
+	hsm := hasMatchingSourcesForNative(integration, kit)
 	assert.False(t, hsm)
 
 	kit2 := &v1.IntegrationKit{
@@ -419,6 +419,6 @@ func TestHasNotMatchingSources(t *testing.T) {
 		},
 	}
 
-	hsm2 := hasMatchingSources(integration, kit2)
+	hsm2 := hasMatchingSourcesForNative(integration, kit2)
 	assert.False(t, hsm2)
 }
diff --git a/pkg/trait/camel.go b/pkg/trait/camel.go
index 9842ea934..2a4e7b3f4 100644
--- a/pkg/trait/camel.go
+++ b/pkg/trait/camel.go
@@ -185,7 +185,7 @@ func (t *camelTrait) loadOrCreateCatalog(e *Environment, runtimeVersion string)
 }
 
 func (t *camelTrait) computeConfigMaps(e *Environment) []ctrl.Object {
-	sources := e.Integration.Sources()
+	sources := e.Integration.AllSources()
 	maps := make([]ctrl.Object, 0, len(sources)+1)
 
 	// combine properties of integration with kit, integration
diff --git a/pkg/trait/mount.go b/pkg/trait/mount.go
index 0a08eb798..75aa96faa 100644
--- a/pkg/trait/mount.go
+++ b/pkg/trait/mount.go
@@ -63,7 +63,7 @@ func (t *mountTrait) Configure(e *Environment) (bool, *TraitCondition, error) {
 	}
 
 	// mount trait needs to be executed only when it has sources attached or any trait configuration
-	return len(e.Integration.Sources()) > 0 ||
+	return len(e.Integration.AllSources()) > 0 ||
 		len(t.Configs) > 0 ||
 		len(t.Resources) > 0 ||
 		len(t.Volumes) > 0, nil, nil
diff --git a/pkg/trait/quarkus.go b/pkg/trait/quarkus.go
index 8f5cbfa3f..8027436fa 100644
--- a/pkg/trait/quarkus.go
+++ b/pkg/trait/quarkus.go
@@ -222,7 +222,7 @@ func (t *quarkusTrait) applyWhileBuildingKit(e *Environment) {
 }
 
 func (t *quarkusTrait) validateNativeSupport(e *Environment) bool {
-	for _, source := range e.Integration.Sources() {
+	for _, source := range e.Integration.AllSources() {
 		if language := source.InferLanguage(); !getLanguageSettings(e, language).native {
 			t.L.ForIntegration(e.Integration).Infof("Integration %s/%s contains a %s source that cannot be compiled to native executable", e.Integration.Namespace, e.Integration.Name, language)
 			e.Integration.Status.Phase = v1.IntegrationPhaseError
@@ -458,10 +458,10 @@ func sourcesRequiredAtBuildTime(e *Environment, source v1.SourceSpec) bool {
 	return settings.native && settings.sourcesRequiredAtBuildTime
 }
 
-// Propagates the sources that are required at build time for native compilation.
+// Propagates the user defined sources that are required at build time for native compilation.
 func propagateSourcesRequiredAtBuildTime(e *Environment) []v1.SourceSpec {
 	array := make([]v1.SourceSpec, 0)
-	for _, source := range e.Integration.Sources() {
+	for _, source := range e.Integration.UserDefinedSources() {
 		if sourcesRequiredAtBuildTime(e, source) {
 			array = append(array, source)
 		}
diff --git a/pkg/trait/trait_types.go b/pkg/trait/trait_types.go
index 9d838a688..d0cd19e6d 100644
--- a/pkg/trait/trait_types.go
+++ b/pkg/trait/trait_types.go
@@ -436,7 +436,7 @@ func (e *Environment) addSourcesProperties() {
 		e.ApplicationProperties = make(map[string]string)
 	}
 	idx := 0
-	for _, s := range e.Integration.Sources() {
+	for _, s := range e.Integration.AllSources() {
 		// We don't process routes embedded (native) or Kamelets
 		if e.isEmbedded(s) || s.IsGeneratedFromKamelet() {
 			continue
@@ -485,7 +485,7 @@ func (e *Environment) addSourcesProperties() {
 func (e *Environment) configureVolumesAndMounts(vols *[]corev1.Volume, mnts *[]corev1.VolumeMount) {
 	// Sources
 	idx := 0
-	for _, s := range e.Integration.Sources() {
+	for _, s := range e.Integration.AllSources() {
 		// We don't process routes embedded (native) or Kamelets
 		if e.isEmbedded(s) || s.IsGeneratedFromKamelet() {
 			continue
@@ -748,7 +748,7 @@ func (e *Environment) getAllInterceptors() []string {
 	util.StringSliceUniqueConcat(&res, e.Interceptors)
 
 	if e.Integration != nil {
-		for _, s := range e.Integration.Sources() {
+		for _, s := range e.Integration.AllSources() {
 			util.StringSliceUniqueConcat(&res, s.Interceptors)
 		}
 	}
diff --git a/pkg/util/kubernetes/resolver.go b/pkg/util/kubernetes/resolver.go
index fef16369f..e86d24db1 100644
--- a/pkg/util/kubernetes/resolver.go
+++ b/pkg/util/kubernetes/resolver.go
@@ -92,7 +92,7 @@ func ResolveIntegrationSources(
 		return nil, nil
 	}
 
-	return ResolveSources(integration.Sources(), func(name string) (*corev1.ConfigMap, error) {
+	return ResolveSources(integration.AllSources(), func(name string) (*corev1.ConfigMap, error) {
 		// the config map could be part of the resources created
 		// by traits
 		cm := resources.GetConfigMap(func(m *corev1.ConfigMap) bool {