You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by nf...@apache.org on 2019/01/29 08:39:30 UTC
[camel-k] branch master updated: Add container ports to integration
deployment
This is an automated email from the ASF dual-hosted git repository.
nferraro 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 c07b579 Add container ports to integration deployment
c07b579 is described below
commit c07b57981d945b1a80d4a8bf533a70eb0d2a9ee4
Author: Antonin Stefanutti <an...@stefanutti.fr>
AuthorDate: Mon Jan 28 10:50:01 2019 +0100
Add container ports to integration deployment
---
pkg/trait/catalog.go | 7 +++++++
pkg/trait/jolokia.go | 23 +++++++++++++++++++++++
pkg/trait/prometheus.go | 23 ++++++++++++++++++++++-
pkg/trait/service.go | 21 +++++++++++++++++++++
pkg/trait/types.go | 3 ++-
5 files changed, 75 insertions(+), 2 deletions(-)
diff --git a/pkg/trait/catalog.go b/pkg/trait/catalog.go
index 2311462..defa0e1 100644
--- a/pkg/trait/catalog.go
+++ b/pkg/trait/catalog.go
@@ -192,6 +192,13 @@ func (c *Catalog) apply(environment *Environment) error {
}
}
+ for _, processor := range environment.PostProcessors {
+ err := processor(environment)
+ if err != nil {
+ return err
+ }
+ }
+
return nil
}
diff --git a/pkg/trait/jolokia.go b/pkg/trait/jolokia.go
index c3ffbc8..b7c7080 100644
--- a/pkg/trait/jolokia.go
+++ b/pkg/trait/jolokia.go
@@ -18,10 +18,13 @@ limitations under the License.
package trait
import (
+ "errors"
"strconv"
"github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
"github.com/apache/camel-k/pkg/util/envvar"
+ corev1 "k8s.io/api/core/v1"
+
"github.com/sirupsen/logrus"
)
@@ -82,5 +85,25 @@ func (t *jolokiaTrait) Apply(e *Environment) (err error) {
envvar.SetVal(&e.EnvVars, "AB_JOLOKIA_PASSWORD_RANDOM", strconv.FormatBool(*t.RandomPassword))
}
+ // Register a post processor to add a container port to the integration deployment
+ e.PostProcessors = append(e.PostProcessors, func(environment *Environment) error {
+ var container *corev1.Container
+ environment.Resources.VisitContainer(func(c *corev1.Container) {
+ if c.Name == environment.Integration.Name {
+ container = c
+ }
+ })
+ if container != nil {
+ container.Ports = append(container.Ports, corev1.ContainerPort{
+ Name: "jolokia",
+ ContainerPort: int32(t.Port),
+ Protocol: corev1.ProtocolTCP,
+ })
+ } else {
+ return errors.New("Cannot add Jolokia container port: no integration container")
+ }
+ return nil
+ })
+
return nil
}
diff --git a/pkg/trait/prometheus.go b/pkg/trait/prometheus.go
index 3e71587..3ee31e9 100644
--- a/pkg/trait/prometheus.go
+++ b/pkg/trait/prometheus.go
@@ -22,6 +22,7 @@ import (
"github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
"github.com/apache/camel-k/pkg/util/envvar"
+ "github.com/pkg/errors"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -64,7 +65,7 @@ func (t *prometheusTrait) Apply(e *Environment) (err error) {
// Expose the Prometheus endpoint
// Either update the existing service added by previously executed traits
// (e.g. the service trait) or add a new service resource
- svc := e.Resources.GetService(func (svc *corev1.Service) bool {
+ svc := e.Resources.GetService(func(svc *corev1.Service) bool {
return svc.Name == e.Integration.Name
})
if svc == nil {
@@ -78,6 +79,26 @@ func (t *prometheusTrait) Apply(e *Environment) (err error) {
}
svc.Spec.Ports = append(svc.Spec.Ports, port)
+ // Register a post processor to add a container port to the integration deployment
+ e.PostProcessors = append(e.PostProcessors, func(environment *Environment) error {
+ var container *corev1.Container
+ environment.Resources.VisitContainer(func(c *corev1.Container) {
+ if c.Name == environment.Integration.Name {
+ container = c
+ }
+ })
+ if container != nil {
+ container.Ports = append(container.Ports, corev1.ContainerPort{
+ Name: "prometheus",
+ ContainerPort: int32(t.Port),
+ Protocol: corev1.ProtocolTCP,
+ })
+ } else {
+ return errors.New("Cannot add Prometheus container port: no integration container")
+ }
+ return nil
+ })
+
// Add the ServiceMonitor resource
smt := t.getServiceMonitorFor(e)
e.Resources.Add(smt)
diff --git a/pkg/trait/service.go b/pkg/trait/service.go
index 043444c..b8c14b2 100644
--- a/pkg/trait/service.go
+++ b/pkg/trait/service.go
@@ -20,6 +20,7 @@ package trait
import (
"github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
"github.com/apache/camel-k/pkg/metadata"
+ "github.com/pkg/errors"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
@@ -82,6 +83,26 @@ func (t *serviceTrait) Apply(e *Environment) (err error) {
}
svc.Spec.Ports = append(svc.Spec.Ports, port)
+ // Register a post processor to add a container port to the integration deployment
+ e.PostProcessors = append(e.PostProcessors, func(environment *Environment) error {
+ var container *corev1.Container
+ environment.Resources.VisitContainer(func(c *corev1.Container) {
+ if c.Name == environment.Integration.Name {
+ container = c
+ }
+ })
+ if container != nil {
+ container.Ports = append(container.Ports, corev1.ContainerPort{
+ Name: "http",
+ ContainerPort: int32(t.Port),
+ Protocol: corev1.ProtocolTCP,
+ })
+ } else {
+ return errors.New("Cannot add HTTP container port: no integration container")
+ }
+ return nil
+ })
+
return nil
}
diff --git a/pkg/trait/types.go b/pkg/trait/types.go
index 4f7470d..a848492 100644
--- a/pkg/trait/types.go
+++ b/pkg/trait/types.go
@@ -30,8 +30,8 @@ import (
"github.com/apache/camel-k/pkg/metadata"
"github.com/apache/camel-k/pkg/platform"
"github.com/apache/camel-k/pkg/util/kubernetes"
- "k8s.io/api/core/v1"
corev1 "k8s.io/api/core/v1"
+ v1 "k8s.io/api/core/v1"
)
// Identifiable represent an identifiable type
@@ -99,6 +99,7 @@ type Environment struct {
Context *v1alpha1.IntegrationContext
Integration *v1alpha1.Integration
Resources *kubernetes.Collection
+ PostProcessors []func(*Environment) error
Steps []builder.Step
BuildDir string
ExecutedTraits []Trait