diff --git a/addons/strimzi/strimzi_test.go b/addons/strimzi/strimzi_test.go index 627283ccae..13fd4ed2bf 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/deploy/resources.go b/deploy/resources.go index bb299aea91..cf9251419b 100644 --- a/deploy/resources.go +++ b/deploy/resources.go @@ -161,9 +161,9 @@ var assets = func() http.FileSystem { "/operator-deployment.yaml": &vfsgen۰CompressedFileInfo{ name: "operator-deployment.yaml", modTime: time.Time{}, - uncompressedSize: 2139, + uncompressedSize: 2148, - compressedContent: []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xbc\x54\x41\x6f\xe3\x36\x13\xbd\xeb\x57\x3c\x58\x97\x5d\x20\xb6\xbf\x7c\x47\xf5\xa4\x26\x0e\x56\x68\x2a\x1b\x96\xb7\xc1\x9e\x8a\x09\x35\x92\x88\x50\xa4\x4a\x52\xd1\xea\xdf\x17\x94\xed\xd8\xce\x66\xd3\x1e\x82\xf2\x24\x71\x86\x6f\xde\x9b\x37\x64\x8c\xf9\xc7\xad\x28\xc6\xbd\x14\xac\x1d\x97\xf0\x06\xbe\x61\xa4\x1d\x89\x86\x51\x98\xca\x0f\x64\x19\x77\xa6\xd7\x25\x79\x69\x34\x3e\xa5\xc5\xdd\x67\xf4\xba\x64\x0b\xa3\x19\xc6\xa2\x35\x96\xa3\x18\xc2\x68\x6f\xe5\x63\xef\x8d\x85\xda\x03\x82\x6a\xcb\xdc\xb2\xf6\x6e\x01\x14\xcc\x13\x7a\xbe\xde\x65\x37\x2b\x54\x52\x31\x4a\xe9\xf6\x87\xb8\xc4\x20\x7d\x13\xc5\xf0\x8d\x74\x18\x8c\x7d\x42\x65\x2c\xa8\x2c\x65\x28\x4c\x0a\x52\x57\xc6\xb6\x7b\x1a\x96\x6b\xb2\xa5\xd4\x35\x84\xe9\x46\x2b\xeb\xc6\xc3\x0c\x9a\xad\x6b\x64\xb7\x88\x62\xec\x82\x8c\xe2\xee\xc8\xc4\xed\x61\xa7\x9a\xde\xe0\x9b\xe9\x0f\x1a\xce\xe4\x1e\xba\x70\x85\x3f\xd8\xba\x50\xe4\xff\x8b\xff\x45\x31\x3e\x85\x94\xd9\x21\x38\xfb\xfc\x0b\x46\xd3\xa3\xa5\x11\xda\x78\xf4\x8e\xcf\x90\xf9\xbb\xe0\xce\x43\x6a\x08\xd3\x76\x4a\x92\x16\x7c\x92\xf5\x52\x61\x81\x89\x40\xc0\x30\x8f\x9e\xa4\x06\x4d\x32\x60\xaa\xf3\x34\x90\x8f\xe2\x28\xc6\xb4\x1a\xef\xbb\x64\xb9\x1c\x86\x61\x41\x13\xdd\x85\xb1\xf5\xf2\xa8\x6e\x79\x9f\xdd\xac\xf2\x62\x35\x9f\x28\x47\x31\xbe\x6a\xc5\xce\xc1\xf2\x5f\xbd\xb4\x5c\xe2\x71\x04\x75\x9d\x92\x82\x1e\x15\x43\xd1\x10\x8c\x9b\xdc\x99\x4c\x97\x1a\x83\x95\x5e\xea\xfa\x0a\xee\xe0\x7a\x14\x5f\xb8\x73\x6a\xd7\x91\x9e\x74\x17\x09\x46\x83\x34\x66\x69\x81\xac\x98\xe1\xd7\xb4\xc8\x8a\xab\x28\xc6\x43\xb6\xfb\xb2\xfe\xba\xc3\x43\xba\xdd\xa6\xf9\x2e\x5b\x15\x58\x6f\x71\xb3\xce\x6f\xb3\x5d\xb6\xce\x0b\xac\xef\x90\xe6\xdf\xf0\x5b\x96\xdf\x5e\x81\xa5\x6f\xd8\x82\xbf\x77\x36\xf0\x37\x16\x32\x34\x92\xcb\xe0\xe9\x71\x80\x8e\x04\xc2\x7c\x84\x7f\xd7\xb1\x90\x95\x14\x50\xa4\xeb\x9e\x6a\x46\x6d\x9e\xd9\xea\x30\x1e\x1d\xdb\x56\xba\x60\xa7\x03\xe9\x32\x8a\xa1\x64\x2b\xfd\x34\x45\xee\x47\x51\xa1\xcc\x47\xde\xad\x88\x3a\x79\x18\xa7\x24\x38\xe0\x96\xcf\xd7\xd1\x93\xd4\x65\x82\x5b\xee\x94\x19\xc3\xe5\x88\x5a\xf6\x54\x92\xa7\x24\x02\x34\xb5\x9c\x40\x50\xcb\x6a\xfe\x34\x37\x1d\x5b\xf2\xc6\x46\x80\xa2\x47\x56\x2e\xa4\x20\x20\x25\x98\x1d\x92\x66\xd3\xd6\xf4\x73\x3e\x1b\x61\x04\x8d\x66\xed\x13\xbc\xa0\x84\x4e\x05\x04\xcb\xd3\x2c\xb8\x04\xd7\x11\xe0\xbc\x25\xcf\xf5\xb8\xc7\xf6\x63\xc7\x09\xb6\x2c\x2c\x93\xe7\x10\x66\xc5\xc2\x1b\xbb\x0f\xb7\xe4\x45\x73\x7f\xc6\xe5\x1d\xca\x9e\xdb\x4e\x91\xe7\xc3\xc9\x33\x95\x61\xa9\x0b\x90\x77\x60\xf6\xeb\x5f\x09\x3c\x26\xbf\xd1\xa0\xa3\xf6\xe9\x9b\xed\xb3\x14\x9c\x0a\x61\x7a\xed\xf3\xf7\x0a\x87\x67\x8d\x64\x78\x59\x4e\x4c\xe7\xff\xc4\x15\x90\x2d\xd5\x9c\xa0\x34\xe2\x89\xed\x42\x9a\xe5\x9e\xf8\xf2\x70\x24\xb9\x5e\x84\xab\x7a\xca\x17\xa6\x6d\x49\x97\xc9\xd9\xd6\x1c\x4f\x21\xf9\x62\xe7\x67\x95\x36\xbd\x52\x1b\xa3\xa4\x18\x13\x64\x55\x6e\xfc\xc6\xb2\x0b\xa3\x75\xca\x63\xfd\x7c\x8e\x7e\x52\xf1\x90\xee\x6e\xbe\xfc\x99\xa7\xbf\xaf\x8a\x4d\x7a\xb3\xba\xc8\x01\x9e\x49\xf5\x7c\x67\x4d\x9b\xbc\x0a\x00\x95\x64\x55\x6e\xb9\xfa\x31\x72\x88\x6d\xc8\x37\xc9\x8b\xef\x8b\x50\xce\x75\x24\xf8\x4d\x1a\xeb\xcd\x6a\x9b\xee\xd6\xdb\x89\xc9\x5b\x24\x5e\x1b\xfa\x1a\x60\xb3\xbe\xfd\xe9\xd9\x8f\x13\x70\x91\x1a\xe3\xa5\x6d\xe1\x39\x24\x35\xd0\xe8\xa6\xf7\xe4\x68\x14\x5e\x44\x5f\x41\xea\x92\x3b\xd6\x25\x6b\xaf\x46\x54\xd6\xb4\xef\xf6\xfe\xa8\xeb\x3f\x75\xe6\xef\x00\x00\x00\xff\xff\x82\xc4\xfe\xb7\x5b\x08\x00\x00"), + compressedContent: []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xbc\x54\x41\x6f\xe3\x36\x13\xbd\xeb\x57\x3c\x58\x97\x5d\x20\xb6\x37\xdf\x77\x53\x4f\x6a\xe2\x20\x46\x53\xc9\xb0\xbc\x0d\xf6\x54\x4c\xa8\x91\x44\x84\x22\x55\x92\x8a\x56\xff\xbe\xa0\x6c\x27\x76\x36\x9b\xf6\x10\x94\x27\x9b\x33\xf3\xe6\xbd\x79\x23\xc6\x98\x7f\xdc\x89\x62\xdc\x49\xc1\xda\x71\x09\x6f\xe0\x1b\x46\xda\x91\x68\x18\x85\xa9\xfc\x40\x96\x71\x63\x7a\x5d\x92\x97\x46\xe3\x53\x5a\xdc\x7c\x46\xaf\x4b\xb6\x30\x9a\x61\x2c\x5a\x63\x39\x8a\x21\x8c\xf6\x56\x3e\xf4\xde\x58\xa8\x3d\x20\xa8\xb6\xcc\x2d\x6b\xef\x16\x40\xc1\x3c\xa1\x67\xf9\x6e\x7d\xb5\x42\x25\x15\xa3\x94\x6e\x5f\xc4\x25\x06\xe9\x9b\x28\x86\x6f\xa4\xc3\x60\xec\x23\x2a\x63\x41\x65\x29\x43\x63\x52\x90\xba\x32\xb6\xdd\xd3\xb0\x5c\x93\x2d\xa5\xae\x21\x4c\x37\x5a\x59\x37\x1e\x66\xd0\x6c\x5d\x23\xbb\x45\x14\x63\x17\x64\x14\x37\x47\x26\x6e\x0f\x3b\xf5\xf4\x06\xdf\x4c\x7f\xd0\x70\x22\xf7\x30\x85\x0b\xfc\xc1\xd6\x85\x26\xff\x5b\x7c\x89\x62\x7c\x0a\x29\xb3\x43\x70\xf6\xf9\x17\x8c\xa6\x47\x4b\x23\xb4\xf1\xe8\x1d\x9f\x20\xf3\x77\xc1\x9d\x87\xd4\x10\xa6\xed\x94\x24\x2d\xf8\x45\xd6\x73\x87\x05\x26\x02\x01\xc3\x3c\x78\x92\x1a\x34\xc9\x80\xa9\x4e\xd3\x40\x3e\x8a\xa3\x18\xd3\x69\xbc\xef\x92\xe5\x72\x18\x86\x05\x4d\x74\x17\xc6\xd6\xcb\xa3\xba\xe5\xdd\xfa\x6a\x95\x15\xab\xf9\x44\x39\x8a\xf1\x55\x2b\x76\x0e\x96\xff\xea\xa5\xe5\x12\x0f\x23\xa8\xeb\x94\x14\xf4\xa0\x18\x8a\x86\x60\xdc\xe4\xce\x64\xba\xd4\x18\xac\xf4\x52\xd7\x17\x70\x07\xd7\xa3\xf8\xcc\x9d\x97\x71\x1d\xe9\x49\x77\x96\x60\x34\x48\x63\x96\x16\x58\x17\x33\xfc\x9a\x16\xeb\xe2\x22\x8a\x71\xbf\xde\xdd\xe6\x5f\x77\xb8\x4f\xb7\xdb\x34\xdb\xad\x57\x05\xf2\x2d\xae\xf2\xec\x7a\xbd\x5b\xe7\x59\x81\xfc\x06\x69\xf6\x0d\xbf\xad\xb3\xeb\x0b\xb0\xf4\x0d\x5b\xf0\xf7\xce\x06\xfe\xc6\x42\x86\x41\x72\x19\x3c\x3d\x2e\xd0\x91\x40\xd8\x8f\xf0\xdf\x75\x2c\x64\x25\x05\x14\xe9\xba\xa7\x9a\x51\x9b\x27\xb6\x3a\xac\x47\xc7\xb6\x95\x2e\xd8\xe9\x40\xba\x8c\x62\x28\xd9\x4a\x3f\x6d\x91\xfb\x51\x54\x68\xf3\x91\xdf\x56\x44\x9d\x3c\xac\x53\x12\x1c\x70\xcb\xa7\xcb\xe8\x51\xea\x32\xc1\x35\x77\xca\x8c\xe1\xe3\x88\x5a\xf6\x54\x92\xa7\x24\x02\x34\xb5\x9c\x40\x50\xcb\x6a\xfe\x38\x37\x1d\x5b\xf2\xc6\x46\x80\xa2\x07\x56\x2e\xa4\x20\x20\x25\x98\x1d\x92\x66\xd3\xd5\xf4\xe7\x74\x37\xc2\x0a\x1a\xcd\xda\x27\x78\x46\x09\x93\x0a\x08\x96\xa7\x5d\x70\x09\x2e\x23\xc0\x79\x4b\x9e\xeb\x71\x8f\xed\xc7\x8e\x13\x6c\x59\x58\x26\xcf\x21\xcc\x8a\x85\x37\x76\x1f\x6e\xc9\x8b\xe6\xee\x84\xcb\x3b\x94\x3d\xb7\x9d\x22\xcf\x87\xca\x13\x95\xe1\xa8\x33\x90\x77\x60\xf6\xe7\x5f\x09\x3c\x26\xbf\x31\xa0\xa3\xf6\xe9\x37\xdb\x27\x29\x38\x15\xc2\xf4\xda\x67\xef\x35\x0e\xcf\x1a\xc9\xf0\xb2\xbc\x30\x9d\xff\x13\x57\x40\xb6\x54\x73\x82\xd2\x88\x47\xb6\x0b\x69\x96\x7b\xe2\xcb\x43\x49\x72\xb9\xf8\xff\xe2\xcb\xbc\xc8\xd2\x4d\x71\x9b\xef\x4e\x0a\x85\x69\x5b\xd2\x65\x72\x72\x35\xc7\x63\xa8\x3a\xbb\xf9\x59\xcb\x4d\xaf\xd4\xc6\x28\x29\xc6\x04\xeb\x2a\x33\x7e\x63\xd9\x85\x1d\x7b\xc9\x63\xfd\x74\x8a\xfe\x22\xe7\x3e\xdd\x5d\xdd\xfe\x99\xa5\xbf\xaf\x8a\x4d\x7a\xb5\x3a\xcb\x01\x9e\x48\xf5\x7c\x63\x4d\x9b\xbc\x0a\x00\x95\x64\x55\x6e\xb9\xfa\x31\x72\x88\x6d\xc8\x37\xc9\xf3\x02\x2c\x42\x3b\xd7\x91\xe0\x37\x69\xe4\x9b\xd5\x36\xdd\xe5\xdb\x89\xc9\x5b\x24\x5e\x3b\xfb\x1a\x60\x93\x5f\xff\xb4\xf6\xe3\x04\x9c\xa5\xc6\x78\x1e\x5b\x78\x17\x49\x0d\x34\xba\xe9\x61\x39\x1a\x85\x67\xd1\x17\x90\xba\xe4\x8e\x75\xc9\xda\xab\x11\x95\x35\xed\xbb\xb3\x3f\xea\xfa\x4f\x9d\xf9\x3b\x00\x00\xff\xff\xea\x7e\xed\xb5\x64\x08\x00\x00"), }, "/operator-role-binding-events.yaml": &vfsgen۰CompressedFileInfo{ name: "operator-role-binding-events.yaml", diff --git a/pkg/controller/kameletbinding/initialize.go b/pkg/controller/kameletbinding/initialize.go index d3874d68de..8f794d69fc 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 f07d8cca7b..05ea123281 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 385febf5a6..266402ab5e 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 }{ @@ -157,6 +158,14 @@ func TestBindings(t *testing.T) { "configuration": asKnativeConfig("https://myurl/hey"), }), }, + { + endpointType: v1alpha1.EndpointTypeSink, + endpoint: v1alpha1.Endpoint{ + URI: asStringPointer("https://myurl/hey"), + }, + profile: camelv1.TraitProfileKubernetes, + uri: "https://myurl/hey", + }, { endpointType: v1alpha1.EndpointTypeSink, endpoint: v1alpha1.Endpoint{ @@ -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 88bdd0c539..01cafa542c 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