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 1c27a65a0 fix(ctrl): use maven repo when downloading kamelets
1c27a65a0 is described below

commit 1c27a65a057d98eeeb3e2dcba8f705394a9a7eb1
Author: Pasquale Congiusti <[email protected]>
AuthorDate: Wed Jun 18 18:11:21 2025 +0200

    fix(ctrl): use maven repo when downloading kamelets
    
    Closes #6180
---
 pkg/controller/integrationplatform/create_test.go | 16 +++++++++++++++-
 pkg/controller/integrationplatform/kamelets.go    |  1 +
 pkg/util/maven/maven_command.go                   |  6 ++++--
 3 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/pkg/controller/integrationplatform/create_test.go 
b/pkg/controller/integrationplatform/create_test.go
index 03f882bd0..9bcbb4ece 100644
--- a/pkg/controller/integrationplatform/create_test.go
+++ b/pkg/controller/integrationplatform/create_test.go
@@ -118,9 +118,17 @@ func TestCatalogAlreadyPresent(t *testing.T) {
 }
 
 func TestCreateNewCatalog(t *testing.T) {
+       // Set the m2 repo folder
+       m2RepoTmpDir, err := os.MkdirTemp("/tmp", "m2*")
+       assert.NoError(t, err)
        ip := v1.IntegrationPlatform{}
        ip.Namespace = "ns"
        ip.Name = "ck"
+       ip.Spec.Build = v1.IntegrationPlatformBuildSpec{
+               Maven: v1.MavenSpec{
+                       LocalRepository: m2RepoTmpDir,
+               },
+       }
        ip.Status = v1.IntegrationPlatformStatus{
                IntegrationPlatformSpec: v1.IntegrationPlatformSpec{
                        Build: v1.IntegrationPlatformBuildSpec{
@@ -129,6 +137,9 @@ func TestCreateNewCatalog(t *testing.T) {
                                Timeout: &metav1.Duration{
                                        Duration: 1 * time.Minute,
                                },
+                               Maven: v1.MavenSpec{
+                                       LocalRepository: m2RepoTmpDir,
+                               },
                        },
                },
        }
@@ -164,8 +175,8 @@ func TestCreateNewCatalog(t *testing.T) {
 
        // Set the folder where to install testing kamelets
        tmpDir, err := os.MkdirTemp("/tmp", "kamelets*")
-       defer os.Unsetenv(kameletDirEnv)
        assert.NoError(t, err)
+       defer os.Unsetenv(kameletDirEnv)
        os.Setenv(kameletDirEnv, tmpDir)
        answer, err := action.Handle(context.TODO(), &ip)
        require.NoError(t, err)
@@ -195,6 +206,9 @@ func TestCreateNewCatalog(t *testing.T) {
                                Timeout: &metav1.Duration{
                                        Duration: 1 * time.Minute,
                                },
+                               Maven: v1.MavenSpec{
+                                       LocalRepository: m2RepoTmpDir,
+                               },
                        },
                },
        }
diff --git a/pkg/controller/integrationplatform/kamelets.go 
b/pkg/controller/integrationplatform/kamelets.go
index 0e2a9b838..a3ce3c7e8 100644
--- a/pkg/controller/integrationplatform/kamelets.go
+++ b/pkg/controller/integrationplatform/kamelets.go
@@ -112,6 +112,7 @@ func downloadKameletDependency(ctx context.Context, c 
client.Client, platform *v
        mc.AddArgument("dependency:copy")
        
mc.AddArgument(fmt.Sprintf("-Dartifact=org.apache.camel.kamelets:camel-kamelets:%s:jar",
 version))
        mc.AddArgument("-Dmdep.useBaseVersion=true")
+       mc.AddArgument("-Dmaven.repo.local=" + mc.LocalRepository)
        mc.AddArgument(fmt.Sprintf("-DoutputDirectory=%s", kameletsDir))
 
        if settings, err := kubernetes.ResolveValueSource(ctx, c, 
platform.Namespace, &platform.Status.Build.Maven.Settings); err != nil {
diff --git a/pkg/util/maven/maven_command.go b/pkg/util/maven/maven_command.go
index 9a1a784ea..b853ad560 100644
--- a/pkg/util/maven/maven_command.go
+++ b/pkg/util/maven/maven_command.go
@@ -70,9 +70,11 @@ func (c *Command) DoSettings(ctx context.Context) error {
        args = append(args, c.context.AdditionalArguments...)
 
        if c.context.LocalRepository != "" {
-               if _, err := os.Stat(c.context.LocalRepository); err == nil {
-                       args = append(args, 
"-Dmaven.repo.local="+c.context.LocalRepository)
+               if _, err := os.Stat(c.context.LocalRepository); err != nil {
+                       return err
                }
+
+               args = append(args, 
"-Dmaven.repo.local="+c.context.LocalRepository)
        }
 
        settingsPath := filepath.Join(c.context.Path, "settings.xml")

Reply via email to