Skip to content

Commit

Permalink
Updating source checks for native builds (#4987)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
Co-authored-by: Hernan Guardado <[email protected]>
  • Loading branch information
3 people authored Dec 19, 2023
1 parent 83bb727 commit 011bf47
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 23 deletions.
8 changes: 7 additions & 1 deletion pkg/apis/camel/v1/integration_types_support.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,20 @@ 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...)

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))
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/cmd/describe_integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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(),
Expand Down
8 changes: 4 additions & 4 deletions pkg/controller/integration/kits.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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 {
Expand Down
12 changes: 6 additions & 6 deletions pkg/controller/integration/kits_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ func TestHasMatchingSources(t *testing.T) {
},
}

hms := hasMatchingSources(integration, kit)
hms := hasMatchingSourcesForNative(integration, kit)
assert.True(t, hms)

kit2 := &v1.IntegrationKit{
Expand All @@ -355,7 +355,7 @@ func TestHasMatchingSources(t *testing.T) {
},
}

hms2 := hasMatchingSources(integration, kit2)
hms2 := hasMatchingSourcesForNative(integration, kit2)
assert.False(t, hms2)
}

Expand All @@ -378,7 +378,7 @@ func TestHasMatchingMultipleSources(t *testing.T) {
},
}

hms := hasMatchingSources(integration, kit)
hms := hasMatchingSourcesForNative(integration, kit)
assert.True(t, hms)

integration2 := &v1.Integration{
Expand All @@ -389,7 +389,7 @@ func TestHasMatchingMultipleSources(t *testing.T) {
},
}

hms2 := hasMatchingSources(integration2, kit)
hms2 := hasMatchingSourcesForNative(integration2, kit)
assert.False(t, hms2)
}

Expand All @@ -410,7 +410,7 @@ func TestHasNotMatchingSources(t *testing.T) {
},
}

hsm := hasMatchingSources(integration, kit)
hsm := hasMatchingSourcesForNative(integration, kit)
assert.False(t, hsm)

kit2 := &v1.IntegrationKit{
Expand All @@ -419,6 +419,6 @@ func TestHasNotMatchingSources(t *testing.T) {
},
}

hsm2 := hasMatchingSources(integration, kit2)
hsm2 := hasMatchingSourcesForNative(integration, kit2)
assert.False(t, hsm2)
}
2 changes: 1 addition & 1 deletion pkg/trait/camel.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/trait/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions pkg/trait/quarkus.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/trait/trait_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/util/kubernetes/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 011bf47

Please sign in to comment.