You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by lb...@apache.org on 2019/01/29 14:30:44 UTC
[camel-k] branch master updated: Use named target ports in
integration service
This is an automated email from the ASF dual-hosted git repository.
lburgazzoli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-k.git
The following commit(s) were added to refs/heads/master by this push:
new cdbc09d Use named target ports in integration service
cdbc09d is described below
commit cdbc09d3eb453b04cabf0dbac770fb12b9af4016
Author: Antonin Stefanutti <an...@stefanutti.fr>
AuthorDate: Tue Jan 29 11:00:16 2019 +0100
Use named target ports in integration service
---
pkg/trait/prometheus.go | 12 ++++++++----
pkg/trait/service.go | 8 +++++---
pkg/trait/trait_test.go | 2 +-
3 files changed, 14 insertions(+), 8 deletions(-)
diff --git a/pkg/trait/prometheus.go b/pkg/trait/prometheus.go
index 7a4d7be..66121a8 100644
--- a/pkg/trait/prometheus.go
+++ b/pkg/trait/prometheus.go
@@ -27,6 +27,7 @@ import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+ "k8s.io/apimachinery/pkg/util/intstr"
monitoringv1 "github.com/coreos/prometheus-operator/pkg/apis/monitoring/v1"
)
@@ -38,6 +39,8 @@ type prometheusTrait struct {
Port int `property:"port"`
}
+const prometheusPortName = "prometheus"
+
// The Prometheus trait must be executed prior to the deployment trait
// as it mutates environment variables
func newPrometheusTrait() *prometheusTrait {
@@ -75,9 +78,10 @@ func (t *prometheusTrait) Apply(e *Environment) (err error) {
e.Resources.Add(svc)
}
port := corev1.ServicePort{
- Name: "prometheus",
- Port: int32(t.Port),
- Protocol: corev1.ProtocolTCP,
+ Name: prometheusPortName,
+ Port: int32(t.Port),
+ Protocol: corev1.ProtocolTCP,
+ TargetPort: intstr.FromString(prometheusPortName),
}
svc.Spec.Ports = append(svc.Spec.Ports, port)
@@ -91,7 +95,7 @@ func (t *prometheusTrait) Apply(e *Environment) (err error) {
})
if container != nil {
container.Ports = append(container.Ports, corev1.ContainerPort{
- Name: "prometheus",
+ Name: prometheusPortName,
ContainerPort: int32(t.Port),
Protocol: corev1.ProtocolTCP,
})
diff --git a/pkg/trait/service.go b/pkg/trait/service.go
index b8c14b2..4e4dda0 100644
--- a/pkg/trait/service.go
+++ b/pkg/trait/service.go
@@ -33,6 +33,8 @@ type serviceTrait struct {
Port int `property:"port"`
}
+const httpPortName = "http"
+
func newServiceTrait() *serviceTrait {
return &serviceTrait{
BaseTrait: BaseTrait{
@@ -76,10 +78,10 @@ func (t *serviceTrait) Apply(e *Environment) (err error) {
e.Resources.Add(svc)
}
port := corev1.ServicePort{
- Name: "http",
+ Name: httpPortName,
Port: 80,
Protocol: corev1.ProtocolTCP,
- TargetPort: intstr.FromInt(t.Port),
+ TargetPort: intstr.FromString(httpPortName),
}
svc.Spec.Ports = append(svc.Spec.Ports, port)
@@ -93,7 +95,7 @@ func (t *serviceTrait) Apply(e *Environment) (err error) {
})
if container != nil {
container.Ports = append(container.Ports, corev1.ContainerPort{
- Name: "http",
+ Name: httpPortName,
ContainerPort: int32(t.Port),
Protocol: corev1.ProtocolTCP,
})
diff --git a/pkg/trait/trait_test.go b/pkg/trait/trait_test.go
index 3ea9b7d..244c29e 100644
--- a/pkg/trait/trait_test.go
+++ b/pkg/trait/trait_test.go
@@ -85,7 +85,7 @@ func TestOpenShiftTraitsWithWebAndConfig(t *testing.T) {
assert.NotNil(t, env.GetTrait(ID("service")))
assert.NotNil(t, env.GetTrait(ID("route")))
assert.NotNil(t, res.GetService(func(svc *corev1.Service) bool {
- return svc.Name == TestDeployment && svc.Spec.Ports[0].TargetPort.IntVal == int32(7071)
+ return svc.Name == TestDeployment && svc.Spec.Ports[0].TargetPort.StrVal == "http"
}))
}