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 2025/01/19 08:36:24 UTC

(camel-k) branch release-2.5.x updated (e54b18fee -> 2bf44a06d)

This is an automated email from the ASF dual-hosted git repository.

pcongiusti pushed a change to branch release-2.5.x
in repository https://gitbox.apache.org/repos/asf/camel-k.git


    from e54b18fee update registry location
     new 9719d5e8c fix(ctrl): use maven settings to install Kamelets
     new 6ee480fc8 fix(trait): workaround Knative h2c port name
     new 2bf44a06d fix(trait): use a configmap index

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 pkg/controller/integrationplatform/create_test.go  |  8 ++++
 pkg/controller/integrationplatform/kamelets.go     | 47 +++++++++++++++++++---
 .../integrationplatform/kamelets_test.go           | 19 ++++++++-
 pkg/trait/mount.go                                 |  9 ++++-
 pkg/trait/prometheus.go                            | 11 ++++-
 5 files changed, 85 insertions(+), 9 deletions(-)


(camel-k) 02/03: fix(trait): workaround Knative h2c port name

Posted by pc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

pcongiusti pushed a commit to branch release-2.5.x
in repository https://gitbox.apache.org/repos/asf/camel-k.git

commit 6ee480fc8b6d152cf53f713a542e1fd32bedb190
Author: Pasquale Congiusti <pa...@gmail.com>
AuthorDate: Thu Jan 16 18:22:27 2025 +0100

    fix(trait): workaround Knative h2c port name
    
    Closes #6014
---
 pkg/trait/prometheus.go | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/pkg/trait/prometheus.go b/pkg/trait/prometheus.go
index ba11aaa55..2bf706a84 100644
--- a/pkg/trait/prometheus.go
+++ b/pkg/trait/prometheus.go
@@ -87,7 +87,7 @@ func (t *prometheusTrait) Apply(e *Environment) error {
 
 	// Add the PodMonitor resource
 	if ptr.Deref(t.PodMonitor, true) {
-		portName := containerPort.Name
+		portName := getPortName(containerPort.Name)
 		podMonitor, err := t.getPodMonitorFor(e, portName)
 		if err != nil {
 			return err
@@ -103,6 +103,15 @@ func (t *prometheusTrait) Apply(e *Environment) error {
 	return nil
 }
 
+func getPortName(portName string) string {
+	// This is a workaround to fix Knative behavior
+	// as described in https://github.com/apache/camel-k/issues/6014
+	if portName == defaultKnativeContainerPortName {
+		return "user-port"
+	}
+	return portName
+}
+
 func (t *prometheusTrait) getPodMonitorFor(e *Environment, portName string) (*monitoringv1.PodMonitor, error) {
 	labels, err := keyValuePairArrayAsStringMap(t.PodMonitorLabels)
 	if err != nil {


(camel-k) 01/03: fix(ctrl): use maven settings to install Kamelets

Posted by pc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

pcongiusti pushed a commit to branch release-2.5.x
in repository https://gitbox.apache.org/repos/asf/camel-k.git

commit 9719d5e8c8bf444a18ab89281c81545486ebb54f
Author: Pasquale Congiusti <pa...@gmail.com>
AuthorDate: Thu Jan 16 18:10:04 2025 +0100

    fix(ctrl): use maven settings to install Kamelets
    
    Closes #6030
---
 pkg/controller/integrationplatform/create_test.go  |  8 ++++
 pkg/controller/integrationplatform/kamelets.go     | 47 +++++++++++++++++++---
 .../integrationplatform/kamelets_test.go           | 19 ++++++++-
 3 files changed, 68 insertions(+), 6 deletions(-)

diff --git a/pkg/controller/integrationplatform/create_test.go b/pkg/controller/integrationplatform/create_test.go
index 0124a81db..30726a8b2 100644
--- a/pkg/controller/integrationplatform/create_test.go
+++ b/pkg/controller/integrationplatform/create_test.go
@@ -24,6 +24,7 @@ import (
 	"os"
 	"strings"
 	"testing"
+	"time"
 
 	v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1"
 	"github.com/apache/camel-k/v2/pkg/platform"
@@ -35,6 +36,7 @@ import (
 	"github.com/stretchr/testify/assert"
 	"github.com/stretchr/testify/require"
 	corev1 "k8s.io/api/core/v1"
+	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
 	"k8s.io/apimachinery/pkg/runtime"
 	k8stesting "k8s.io/client-go/testing"
 	k8sclient "sigs.k8s.io/controller-runtime/pkg/client"
@@ -124,6 +126,9 @@ func TestCreateNewCatalog(t *testing.T) {
 			Build: v1.IntegrationPlatformBuildSpec{
 				RuntimeProvider: v1.RuntimeProviderQuarkus,
 				RuntimeVersion:  defaults.DefaultRuntimeVersion,
+				Timeout: &metav1.Duration{
+					Duration: 1 * time.Minute,
+				},
 			},
 		},
 	}
@@ -187,6 +192,9 @@ func TestCreateNewCatalog(t *testing.T) {
 			Build: v1.IntegrationPlatformBuildSpec{
 				RuntimeProvider: v1.RuntimeProviderQuarkus,
 				RuntimeVersion:  defaults.DefaultRuntimeVersion,
+				Timeout: &metav1.Duration{
+					Duration: 1 * time.Minute,
+				},
 			},
 		},
 	}
diff --git a/pkg/controller/integrationplatform/kamelets.go b/pkg/controller/integrationplatform/kamelets.go
index 9ff27c956..7d355e339 100644
--- a/pkg/controller/integrationplatform/kamelets.go
+++ b/pkg/controller/integrationplatform/kamelets.go
@@ -36,6 +36,8 @@ import (
 	"github.com/apache/camel-k/v2/pkg/client"
 	"github.com/apache/camel-k/v2/pkg/util"
 	"github.com/apache/camel-k/v2/pkg/util/defaults"
+	"github.com/apache/camel-k/v2/pkg/util/jvm"
+	"github.com/apache/camel-k/v2/pkg/util/kubernetes"
 	"github.com/apache/camel-k/v2/pkg/util/log"
 	"github.com/apache/camel-k/v2/pkg/util/maven"
 	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -61,7 +63,7 @@ func installKameletCatalog(ctx context.Context, c client.Client, platform *v1.In
 		return -1, -1, err
 	}
 	// Download Kamelet dependency
-	if err := downloadKameletDependency(ctx, version, kameletDir); err != nil {
+	if err := downloadKameletDependency(ctx, c, platform, version, kameletDir); err != nil {
 		return -1, -1, err
 	}
 	// Extract Kamelets files
@@ -100,9 +102,7 @@ func prepareKameletDirectory() (string, error) {
 	return kameletDir, nil
 }
 
-func downloadKameletDependency(ctx context.Context, version, kameletsDir string) error {
-	// TODO: we may want to add the maven settings coming from the platform
-	// in order to cover any user security setting in place
+func downloadKameletDependency(ctx context.Context, c client.Client, platform *v1.IntegrationPlatform, version, kameletsDir string) error {
 	p := maven.NewProjectWithGAV("org.apache.camel.k.kamelets", "kamelets-catalog", defaults.Version)
 	mc := maven.NewContext(kameletsDir)
 	mc.AddArgument("-q")
@@ -111,7 +111,44 @@ func downloadKameletDependency(ctx context.Context, version, kameletsDir string)
 	mc.AddArgument("-Dmdep.useBaseVersion=true")
 	mc.AddArgument(fmt.Sprintf("-DoutputDirectory=%s", kameletsDir))
 
-	return p.Command(mc).Do(ctx)
+	if settings, err := kubernetes.ResolveValueSource(ctx, c, platform.Namespace, &platform.Status.Build.Maven.Settings); err != nil {
+		return err
+	} else if settings != "" {
+		mc.UserSettings = []byte(settings)
+	}
+
+	settings, err := maven.NewSettings(maven.DefaultRepositories, maven.ProxyFromEnvironment)
+	if err != nil {
+		return err
+	}
+	data, err := settings.MarshalBytes()
+	if err != nil {
+		return err
+	}
+	mc.GlobalSettings = data
+	secrets := platform.Status.Build.Maven.CASecrets
+
+	if secrets != nil {
+		certsData, err := kubernetes.GetSecretsRefData(ctx, c, platform.Namespace, secrets)
+		if err != nil {
+			return err
+		}
+		trustStoreName := "trust.jks"
+		trustStorePass := jvm.NewKeystorePassword()
+		err = jvm.GenerateKeystore(ctx, kameletsDir, trustStoreName, trustStorePass, certsData)
+		if err != nil {
+			return err
+		}
+		mc.ExtraMavenOpts = append(mc.ExtraMavenOpts,
+			"-Djavax.net.ssl.trustStore="+trustStoreName,
+			"-Djavax.net.ssl.trustStorePassword="+trustStorePass,
+		)
+	}
+
+	timeoutCtx, cancel := context.WithTimeout(ctx, platform.Status.Build.GetTimeout().Duration)
+	defer cancel()
+
+	return p.Command(mc).Do(timeoutCtx)
 }
 
 func extractKameletsFromDependency(ctx context.Context, version, kameletsDir string) error {
diff --git a/pkg/controller/integrationplatform/kamelets_test.go b/pkg/controller/integrationplatform/kamelets_test.go
index 0bf31c0c2..f99abe1d1 100644
--- a/pkg/controller/integrationplatform/kamelets_test.go
+++ b/pkg/controller/integrationplatform/kamelets_test.go
@@ -26,13 +26,16 @@ import (
 	"path/filepath"
 	"strings"
 	"testing"
+	"time"
 
 	v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1"
 	"github.com/apache/camel-k/v2/pkg/util/boolean"
 	"github.com/apache/camel-k/v2/pkg/util/camel"
+	"github.com/apache/camel-k/v2/pkg/util/defaults"
 	"github.com/apache/camel-k/v2/pkg/util/test"
 	"github.com/stretchr/testify/assert"
 	"github.com/stretchr/testify/require"
+	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
 )
 
 func TestLoadKamelet(t *testing.T) {
@@ -112,6 +115,20 @@ func TestPrepareKameletsDirectory(t *testing.T) {
 }
 
 func TestDownloadKameletDependencyAndExtract(t *testing.T) {
+	cli, err := test.NewFakeClient()
+	assert.NoError(t, err)
+	itp := v1.NewIntegrationPlatform("itp-ns", "my-itp")
+	itp.Status = v1.IntegrationPlatformStatus{
+		IntegrationPlatformSpec: v1.IntegrationPlatformSpec{
+			Build: v1.IntegrationPlatformBuildSpec{
+				RuntimeProvider: v1.RuntimeProviderQuarkus,
+				RuntimeVersion:  defaults.DefaultRuntimeVersion,
+				Timeout: &metav1.Duration{
+					Duration: 1 * time.Minute,
+				},
+			},
+		},
+	}
 	// use local Maven executable in tests
 	t.Setenv("MAVEN_WRAPPER", boolean.FalseString)
 	_, ok := os.LookupEnv("MAVEN_CMD")
@@ -126,7 +143,7 @@ func TestDownloadKameletDependencyAndExtract(t *testing.T) {
 	assert.NoError(t, err)
 	camelVersion := c.Runtime.Metadata["camel.version"]
 	assert.NotEqual(t, "", camelVersion)
-	err = downloadKameletDependency(context.TODO(), camelVersion, tmpDir)
+	err = downloadKameletDependency(context.TODO(), cli, &itp, camelVersion, tmpDir)
 	assert.NoError(t, err)
 	downloadedDependency, err := os.Stat(path.Join(tmpDir, fmt.Sprintf("camel-kamelets-%s.jar", camelVersion)))
 	assert.NoError(t, err)


(camel-k) 03/03: fix(trait): use a configmap index

Posted by pc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

pcongiusti pushed a commit to branch release-2.5.x
in repository https://gitbox.apache.org/repos/asf/camel-k.git

commit 2bf44a06d7ea87499e616acbc2b8af912c4216b4
Author: Pasquale Congiusti <pa...@gmail.com>
AuthorDate: Sat Nov 16 15:52:50 2024 +0100

    fix(trait): use a configmap index
    
    Closes #5924
---
 pkg/trait/mount.go | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/pkg/trait/mount.go b/pkg/trait/mount.go
index 38a770382..fe87b5db2 100644
--- a/pkg/trait/mount.go
+++ b/pkg/trait/mount.go
@@ -180,15 +180,17 @@ func (t *mountTrait) configureVolumesAndMounts(e *Environment, vols *[]corev1.Vo
 // configureCamelVolumesAndMounts is in charge to mount volumes and mounts coming from Camel configuration
 // (ie, sources, properties, kamelets, etcetera).
 func (t *mountTrait) configureCamelVolumesAndMounts(e *Environment, vols *[]corev1.Volume, mnts *[]corev1.VolumeMount) {
-	// Sources
+	// Sources index
 	idx := 0
+	// Configmap index (may differ as generated sources can have a different name)
+	cmx := 0
 	for _, s := range e.Integration.AllSources() {
 		// We don't process routes embedded (native) or Kamelets
 		if e.isEmbedded(s) || s.IsGeneratedFromKamelet() {
 			continue
 		}
 		// Routes are copied under /etc/camel/sources and discovered by the runtime accordingly
-		cmName := fmt.Sprintf("%s-source-%03d", e.Integration.Name, idx)
+		cmName := fmt.Sprintf("%s-source-%03d", e.Integration.Name, cmx)
 		if s.ContentRef != "" {
 			cmName = s.ContentRef
 		}
@@ -205,6 +207,9 @@ func (t *mountTrait) configureCamelVolumesAndMounts(e *Environment, vols *[]core
 		*vols = append(*vols, *vol)
 		*mnts = append(*mnts, *mnt)
 		idx++
+		if s.ContentRef == "" {
+			cmx++
+		}
 	}
 	// Resources (likely application properties or kamelets)
 	if e.Resources != nil {