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 2020/10/23 12:12:33 UTC
[camel-k] branch master updated: Fix #1774: use direct HTTP binding
when Knative is not in use
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 2589ee3 Fix #1774: use direct HTTP binding when Knative is not in use
2589ee3 is described below
commit 2589ee316606ef11f70e8f6da032f6fc1a864a4a
Author: nicolaferraro <ni...@gmail.com>
AuthorDate: Fri Oct 23 12:07:58 2020 +0200
Fix #1774: use direct HTTP binding when Knative is not in use
---
addons/strimzi/strimzi_test.go | 3 +++
pkg/controller/kameletbinding/initialize.go | 39 +++++++++++++++++++++++++++++
pkg/util/bindings/api.go | 2 ++
pkg/util/bindings/bindings_test.go | 15 +++++++++++
pkg/util/bindings/knative_uri.go | 4 +++
5 files changed, 63 insertions(+)
diff --git a/addons/strimzi/strimzi_test.go b/addons/strimzi/strimzi_test.go
index 627283c..13fd4ed 100644
--- a/addons/strimzi/strimzi_test.go
+++ b/addons/strimzi/strimzi_test.go
@@ -22,6 +22,7 @@ import (
"encoding/json"
"github.com/apache/camel-k/addons/strimzi/duck/v1beta1"
"github.com/apache/camel-k/addons/strimzi/duck/v1beta1/client/internalclientset/fake"
+ camelv1 "github.com/apache/camel-k/pkg/apis/camel/v1"
"github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
"github.com/apache/camel-k/pkg/util/bindings"
"github.com/apache/camel-k/pkg/util/test"
@@ -42,6 +43,7 @@ func TestStrimziDirect(t *testing.T) {
Ctx: ctx,
Client: client,
Namespace: "test",
+ Profile: camelv1.TraitProfileKubernetes,
}
endpoint := v1alpha1.Endpoint{
@@ -102,6 +104,7 @@ func TestStrimziLookup(t *testing.T) {
bindingContext := bindings.BindingContext{
Ctx: ctx,
Namespace: "test",
+ Profile: camelv1.TraitProfileKubernetes,
}
endpoint := v1alpha1.Endpoint{
diff --git a/pkg/controller/kameletbinding/initialize.go b/pkg/controller/kameletbinding/initialize.go
index d3874d6..8f794d6 100644
--- a/pkg/controller/kameletbinding/initialize.go
+++ b/pkg/controller/kameletbinding/initialize.go
@@ -24,11 +24,14 @@ import (
v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
"github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
+ "github.com/apache/camel-k/pkg/platform"
"github.com/apache/camel-k/pkg/util/bindings"
+ "github.com/apache/camel-k/pkg/util/knative"
"github.com/apache/camel-k/pkg/util/kubernetes"
"github.com/apache/camel-k/pkg/util/patch"
"github.com/pkg/errors"
corev1 "k8s.io/api/core/v1"
+ k8serrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -75,10 +78,17 @@ func (action *initializeAction) Handle(ctx context.Context, kameletbinding *v1al
it.Spec = *kameletbinding.Spec.Integration.DeepCopy()
}
+ profile, err := action.determineProfile(ctx, kameletbinding)
+ if err != nil {
+ return nil, err
+ }
+ it.Spec.Profile = profile
+
bindingContext := bindings.BindingContext{
Ctx: ctx,
Client: action.client,
Namespace: it.Namespace,
+ Profile: profile,
}
from, err := bindings.Translate(bindingContext, v1alpha1.EndpointTypeSource, kameletbinding.Spec.Source)
@@ -183,3 +193,32 @@ func (action *initializeAction) findIcon(ctx context.Context, binding *v1alpha1.
}
return kamelet.Annotations[v1alpha1.AnnotationIcon], nil
}
+
+func (action *initializeAction) determineProfile(ctx context.Context, binding *v1alpha1.KameletBinding) (v1.TraitProfile, error) {
+ if binding.Spec.Integration != nil && binding.Spec.Integration.Profile != "" {
+ return binding.Spec.Integration.Profile, nil
+ }
+ pl, err := platform.GetCurrentPlatform(ctx, action.client, binding.Namespace)
+ if err != nil && !k8serrors.IsNotFound(err) {
+ return "", errors.Wrap(err, "error while retrieving the integration platform")
+ }
+ if pl != nil {
+ if pl.Status.Profile != "" {
+ return pl.Status.Profile, nil
+ }
+ if pl.Spec.Profile != "" {
+ return pl.Spec.Profile, nil
+ }
+ }
+ if knative.IsEnabledInNamespace(ctx, action.client, binding.Namespace) {
+ return v1.TraitProfileKnative, nil
+ }
+ if pl != nil {
+ // Determine profile from cluster type
+ plProfile := platform.GetProfile(pl)
+ if plProfile != "" {
+ return plProfile, nil
+ }
+ }
+ return v1.DefaultTraitProfile, nil
+}
diff --git a/pkg/util/bindings/api.go b/pkg/util/bindings/api.go
index f07d8cc..05ea123 100644
--- a/pkg/util/bindings/api.go
+++ b/pkg/util/bindings/api.go
@@ -20,6 +20,7 @@ package bindings
import (
"context"
+
v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
"github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
"github.com/apache/camel-k/pkg/client"
@@ -53,4 +54,5 @@ type BindingContext struct {
Ctx context.Context
Client client.Client
Namespace string
+ Profile v1.TraitProfile
}
diff --git a/pkg/util/bindings/bindings_test.go b/pkg/util/bindings/bindings_test.go
index 385febf..266402a 100644
--- a/pkg/util/bindings/bindings_test.go
+++ b/pkg/util/bindings/bindings_test.go
@@ -36,6 +36,7 @@ func TestBindings(t *testing.T) {
testcases := []struct {
endpointType v1alpha1.EndpointType
endpoint v1alpha1.Endpoint
+ profile camelv1.TraitProfile
uri string
traits map[string]camelv1.TraitSpec
}{
@@ -160,6 +161,14 @@ func TestBindings(t *testing.T) {
{
endpointType: v1alpha1.EndpointTypeSink,
endpoint: v1alpha1.Endpoint{
+ URI: asStringPointer("https://myurl/hey"),
+ },
+ profile: camelv1.TraitProfileKubernetes,
+ uri: "https://myurl/hey",
+ },
+ {
+ endpointType: v1alpha1.EndpointTypeSink,
+ endpoint: v1alpha1.Endpoint{
URI: asStringPointer("docker://xxx"),
},
uri: "docker://xxx",
@@ -174,10 +183,16 @@ func TestBindings(t *testing.T) {
client, err := test.NewFakeClient()
assert.NoError(t, err)
+ profile := tc.profile
+ if profile == "" {
+ profile = camelv1.TraitProfileKnative
+ }
+
bindingContext := BindingContext{
Ctx: ctx,
Client: client,
Namespace: "test",
+ Profile: profile,
}
binding, err := Translate(bindingContext, tc.endpointType, tc.endpoint)
diff --git a/pkg/util/bindings/knative_uri.go b/pkg/util/bindings/knative_uri.go
index 88bdd0c..01cafa5 100644
--- a/pkg/util/bindings/knative_uri.go
+++ b/pkg/util/bindings/knative_uri.go
@@ -40,6 +40,10 @@ func (k KnativeURIBindingProvider) Translate(ctx BindingContext, endpointType v1
// works only on uris
return nil, nil
}
+ if ctx.Profile != v1.TraitProfileKnative {
+ // use cloudevent binding only in Knative trait profile
+ return nil, nil
+ }
if !strings.HasPrefix(*e.URI, "http:") && !strings.HasPrefix(*e.URI, "https:") {
// only translates http/https uri to Knative calls
return nil, nil