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:26 UTC

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

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 {