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 b20507074 fix(trait): use it and ik repositories b20507074 is described below commit b205070749e59bb664add83f2ca39ceb17208090 Author: Pasquale Congiusti <pasquale.congiu...@gmail.com> AuthorDate: Wed Apr 2 18:39:16 2025 +0200 fix(trait): use it and ik repositories ... when generating catalog. Closes #6115 --- pkg/controller/integrationplatform/create.go | 4 +++- pkg/trait/camel.go | 12 +++++++++++- pkg/util/camel/camel_runtime.go | 11 ++++++----- pkg/util/camel/camel_runtime_test.go | 7 +++++-- pkg/util/camel/catalog.go | 16 +++++++--------- pkg/util/camel/catalog_test.go | 2 +- 6 files changed, 33 insertions(+), 19 deletions(-) diff --git a/pkg/controller/integrationplatform/create.go b/pkg/controller/integrationplatform/create.go index a553afb85..88ccf1fde 100644 --- a/pkg/controller/integrationplatform/create.go +++ b/pkg/controller/integrationplatform/create.go @@ -138,7 +138,9 @@ func (action *createAction) handleNewCatalog(ctx context.Context, platform *v1.I catalog *v1.CamelCatalog, runtimeSpec v1.RuntimeSpec) (*v1.IntegrationPlatform, error) { var camelVersion string if catalog == nil { - cat, err := camel.CreateCatalog(ctx, action.client, platform.Namespace, platform, runtimeSpec) + cat, err := camel.CreateCatalog( + ctx, action.client, platform.Namespace, platform.Status.Build.Maven, + platform.Status.Build.GetTimeout().Duration, runtimeSpec, nil) if err != nil { action.L.Error(err, "IntegrationPlatform unable to create Camel catalog", "runtime-version", runtimeSpec.Version, "runtime-provider", runtimeSpec.Provider) diff --git a/pkg/trait/camel.go b/pkg/trait/camel.go index 43868a991..770abb466 100644 --- a/pkg/trait/camel.go +++ b/pkg/trait/camel.go @@ -148,6 +148,7 @@ func (t *camelTrait) Apply(e *Environment) error { return nil } +//nolint:nestif func (t *camelTrait) loadOrCreateCatalog(e *Environment) error { catalogNamespace := e.DetermineCatalogNamespace() if catalogNamespace == "" { @@ -174,7 +175,16 @@ func (t *camelTrait) loadOrCreateCatalog(e *Environment) error { // the required versions (camel and runtime) are not expressed as // semver constraints if exactVersionRegexp.MatchString(t.runtimeVersion) { - catalog, err = camel.CreateCatalog(e.Ctx, e.Client, catalogNamespace, e.Platform, runtime) + mavenSpec := e.Platform.Status.Build.Maven + var extraRepositories []string + if e.Integration != nil && e.Integration.Spec.Repositories != nil { + extraRepositories = append(extraRepositories, e.Integration.Spec.Repositories...) + } + if e.IntegrationKit != nil && e.IntegrationKit.Spec.Repositories != nil { + extraRepositories = append(extraRepositories, e.IntegrationKit.Spec.Repositories...) + } + catalog, err = camel.CreateCatalog(e.Ctx, e.Client, catalogNamespace, + mavenSpec, e.Platform.Status.Build.GetTimeout().Duration, runtime, extraRepositories) if err != nil { return err } diff --git a/pkg/util/camel/camel_runtime.go b/pkg/util/camel/camel_runtime.go index 753c54801..7532b479d 100644 --- a/pkg/util/camel/camel_runtime.go +++ b/pkg/util/camel/camel_runtime.go @@ -21,9 +21,9 @@ import ( "context" "fmt" "strings" + "time" "github.com/apache/camel-k/v2/pkg/util/kubernetes" - "github.com/apache/camel-k/v2/pkg/util/maven" k8serrors "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/runtime/schema" k8sclient "sigs.k8s.io/controller-runtime/pkg/client" @@ -33,11 +33,12 @@ import ( ) // CreateCatalog --. -func CreateCatalog(ctx context.Context, client client.Client, namespace string, platform *v1.IntegrationPlatform, - runtime v1.RuntimeSpec) (*RuntimeCatalog, error) { - ctx, cancel := context.WithTimeout(ctx, platform.Status.Build.GetTimeout().Duration) +func CreateCatalog( + ctx context.Context, client client.Client, namespace string, + mavenSpec v1.MavenSpec, timeout time.Duration, runtime v1.RuntimeSpec, extraRepositories []string) (*RuntimeCatalog, error) { + ctx, cancel := context.WithTimeout(ctx, timeout) defer cancel() - catalog, err := GenerateCatalog(ctx, client, namespace, platform.Status.Build.Maven, runtime, []maven.Dependency{}) + catalog, err := GenerateCatalog(ctx, client, namespace, mavenSpec, runtime, extraRepositories) if err != nil { return nil, err } diff --git a/pkg/util/camel/camel_runtime_test.go b/pkg/util/camel/camel_runtime_test.go index afa981888..2c0f52aec 100644 --- a/pkg/util/camel/camel_runtime_test.go +++ b/pkg/util/camel/camel_runtime_test.go @@ -55,8 +55,11 @@ func TestCreateCatalog(t *testing.T) { context.TODO(), c, "", - &ip, - v1.RuntimeSpec{Provider: v1.RuntimeProviderQuarkus, Version: defaults.DefaultRuntimeVersion}) + ip.Status.Build.Maven, + ip.Status.Build.GetTimeout().Duration, + v1.RuntimeSpec{Provider: v1.RuntimeProviderQuarkus, Version: defaults.DefaultRuntimeVersion}, + nil, + ) require.NoError(t, err) assert.NotNil(t, catalog) assert.Equal(t, defaults.DefaultRuntimeVersion, catalog.Runtime.Version) diff --git a/pkg/util/camel/catalog.go b/pkg/util/camel/catalog.go index 566cc6250..573fdd6f9 100644 --- a/pkg/util/camel/catalog.go +++ b/pkg/util/camel/catalog.go @@ -78,13 +78,14 @@ func GenerateCatalog( namespace string, mvn v1.MavenSpec, runtime v1.RuntimeSpec, - providerDependencies []maven.Dependency) (*RuntimeCatalog, error) { + extraRepositories []string) (*RuntimeCatalog, error) { userSettings, err := kubernetes.ResolveValueSource(ctx, client, namespace, &mvn.Settings) if err != nil { return nil, err } - settings, err := maven.NewSettings(maven.DefaultRepositories, maven.ProxyFromEnvironment) + settings, err := maven.NewSettings( + maven.DefaultRepositories, maven.ProxyFromEnvironment, maven.Repositories(extraRepositories...)) if err != nil { return nil, err } @@ -101,7 +102,7 @@ func GenerateCatalog( } } - return GenerateCatalogCommon(ctx, globalSettings, []byte(userSettings), caCerts, mvn, runtime, providerDependencies) + return GenerateCatalogCommon(ctx, globalSettings, []byte(userSettings), caCerts, mvn, runtime) } func GenerateCatalogCommon( @@ -110,13 +111,12 @@ func GenerateCatalogCommon( userSettings []byte, caCert [][]byte, mvn v1.MavenSpec, - runtime v1.RuntimeSpec, - providerDependencies []maven.Dependency) (*RuntimeCatalog, error) { + runtime v1.RuntimeSpec) (*RuntimeCatalog, error) { catalog := v1.CamelCatalog{} err := util.WithTempDir("camel-catalog", func(tmpDir string) error { - project := generateMavenProject(runtime.Version, providerDependencies) + project := generateMavenProject(runtime.Version) mc := maven.NewContext(tmpDir) mc.LocalRepository = mvn.LocalRepository @@ -159,7 +159,7 @@ func GenerateCatalogCommon( return NewRuntimeCatalog(catalog), err } -func generateMavenProject(runtimeVersion string, providerDependencies []maven.Dependency) maven.Project { +func generateMavenProject(runtimeVersion string) maven.Project { p := maven.NewProjectWithGAV("org.apache.camel.k.integration", "camel-k-catalog-generator", defaults.Version) plugin := maven.Plugin{ @@ -176,8 +176,6 @@ func generateMavenProject(runtimeVersion string, providerDependencies []maven.De }, } - plugin.Dependencies = append(plugin.Dependencies, providerDependencies...) - p.Build = &maven.Build{ DefaultGoal: "generate-resources", Plugins: []maven.Plugin{plugin}, diff --git a/pkg/util/camel/catalog_test.go b/pkg/util/camel/catalog_test.go index c7a3dbc7f..7ff0f2516 100644 --- a/pkg/util/camel/catalog_test.go +++ b/pkg/util/camel/catalog_test.go @@ -26,7 +26,7 @@ import ( ) func TestCamelTraitGenerateMavenProjectSucceeds(t *testing.T) { - mvnProject := generateMavenProject("1.0.1", nil) + mvnProject := generateMavenProject("1.0.1") assert.NotNil(t, mvnProject) assert.Equal(t, "org.apache.camel.k.integration", mvnProject.GroupID) assert.Equal(t, "camel-k-catalog-generator", mvnProject.ArtifactID)