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
commit a0b0881d6660e30251121d2aab1adf6a525f8727 Author: nferraro <ni.ferr...@gmail.com> AuthorDate: Fri Dec 21 17:02:26 2018 +0100 Moving camel environment to API --- cmd/camel-k/main.go | 2 +- cmd/kamel/main.go | 2 +- .../camel/v1alpha1}/knative/register.go | 0 pkg/{util => apis/camel/v1alpha1}/knative/types.go | 0 pkg/apis/camel/v1alpha1/knative/types_support.go | 54 ++++++++++++++++++++++ pkg/trait/knative.go | 29 ++++++------ 6 files changed, 71 insertions(+), 16 deletions(-) diff --git a/cmd/camel-k/main.go b/cmd/camel-k/main.go index e5d71f3..67da2fe 100644 --- a/cmd/camel-k/main.go +++ b/cmd/camel-k/main.go @@ -28,7 +28,7 @@ import ( "github.com/operator-framework/operator-sdk/pkg/util/k8sutil" sdkVersion "github.com/operator-framework/operator-sdk/version" - _ "github.com/apache/camel-k/pkg/util/knative" + _ "github.com/apache/camel-k/pkg/apis/camel/v1alpha1/knative" _ "github.com/apache/camel-k/pkg/util/openshift" "github.com/sirupsen/logrus" diff --git a/cmd/kamel/main.go b/cmd/kamel/main.go index e711d0d..18822ea 100644 --- a/cmd/kamel/main.go +++ b/cmd/kamel/main.go @@ -26,7 +26,7 @@ import ( "github.com/apache/camel-k/pkg/client/cmd" - _ "github.com/apache/camel-k/pkg/util/knative" + _ "github.com/apache/camel-k/pkg/apis/camel/v1alpha1/knative" _ "github.com/apache/camel-k/pkg/util/openshift" _ "k8s.io/client-go/plugin/pkg/client/auth/gcp" ) diff --git a/pkg/util/knative/register.go b/pkg/apis/camel/v1alpha1/knative/register.go similarity index 100% rename from pkg/util/knative/register.go rename to pkg/apis/camel/v1alpha1/knative/register.go diff --git a/pkg/util/knative/types.go b/pkg/apis/camel/v1alpha1/knative/types.go similarity index 100% rename from pkg/util/knative/types.go rename to pkg/apis/camel/v1alpha1/knative/types.go diff --git a/pkg/apis/camel/v1alpha1/knative/types_support.go b/pkg/apis/camel/v1alpha1/knative/types_support.go new file mode 100644 index 0000000..b8cc62d --- /dev/null +++ b/pkg/apis/camel/v1alpha1/knative/types_support.go @@ -0,0 +1,54 @@ +/* +Licensed to the Apache Software Foundation (ASF) under one or more +contributor license agreements. See the NOTICE file distributed with +this work for additional information regarding copyright ownership. +The ASF licenses this file to You under the Apache License, Version 2.0 +(the "License"); you may not use this file except in compliance with +the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package knative + +import ( + "net/url" + "strconv" +) + +// BuildCamelServiceDefinition creates a CamelServiceDefinition from a given URL +func BuildCamelServiceDefinition(name string, serviceType CamelServiceType, rawurl string) (*CamelServiceDefinition, error) { + serviceURL, err := url.Parse(rawurl) + if err != nil { + return nil, err + } + definition := CamelServiceDefinition{ + Name: name, + Host: serviceURL.Host, + Port: -1, + ServiceType: serviceType, + Protocol: CamelProtocol(serviceURL.Scheme), + Metadata: make(map[string]string), + } + portStr := serviceURL.Port() + if portStr != "" { + port, err := strconv.Atoi(portStr) + if err != nil { + return nil, err + } + definition.Port = port + } + path := serviceURL.Path + if path != "" { + definition.Metadata[CamelMetaServicePath] = path + } else { + definition.Metadata[CamelMetaServicePath] = "/" + } + return &definition, nil +} diff --git a/pkg/trait/knative.go b/pkg/trait/knative.go index ae2e30d..ae743af 100644 --- a/pkg/trait/knative.go +++ b/pkg/trait/knative.go @@ -33,6 +33,7 @@ import ( "github.com/apache/camel-k/pkg/metadata" knativeutil "github.com/apache/camel-k/pkg/util/knative" + knativeapi "github.com/apache/camel-k/pkg/apis/camel/v1alpha1/knative" eventing "github.com/knative/eventing/pkg/apis/eventing/v1alpha1" serving "github.com/knative/serving/pkg/apis/serving/v1alpha1" corev1 "k8s.io/api/core/v1" @@ -296,19 +297,19 @@ func (t *knativeTrait) getConfigurationSerialized(e *Environment) (string, error return string(res), nil } -func (t *knativeTrait) getConfiguration(e *Environment) (knativeutil.CamelEnvironment, error) { - env := knativeutil.NewCamelEnvironment() +func (t *knativeTrait) getConfiguration(e *Environment) (knativeapi.CamelEnvironment, error) { + env := knativeapi.NewCamelEnvironment() // Sources sourceChannels := t.getConfiguredSourceChannels() for _, ch := range sourceChannels { - svc := knativeutil.CamelServiceDefinition{ + svc := knativeapi.CamelServiceDefinition{ Name: ch, Host: "0.0.0.0", Port: 8080, - Protocol: knativeutil.CamelProtocolHTTP, - ServiceType: knativeutil.CamelServiceTypeChannel, + Protocol: knativeapi.CamelProtocolHTTP, + ServiceType: knativeapi.CamelServiceTypeChannel, Metadata: map[string]string{ - knativeutil.CamelMetaServicePath: "/", + knativeapi.CamelMetaServicePath: "/", }, } env.Services = append(env.Services, svc) @@ -324,27 +325,27 @@ func (t *knativeTrait) getConfiguration(e *Environment) (knativeutil.CamelEnviro if hostname == "" { return env, errors.New("cannot find address of channel " + ch) } - svc := knativeutil.CamelServiceDefinition{ + svc := knativeapi.CamelServiceDefinition{ Name: ch, Host: hostname, Port: 80, - Protocol: knativeutil.CamelProtocolHTTP, - ServiceType: knativeutil.CamelServiceTypeChannel, + Protocol: knativeapi.CamelProtocolHTTP, + ServiceType: knativeapi.CamelServiceTypeChannel, Metadata: map[string]string{ - knativeutil.CamelMetaServicePath: "/", + knativeapi.CamelMetaServicePath: "/", }, } env.Services = append(env.Services, svc) } // Adding default endpoint - defSvc := knativeutil.CamelServiceDefinition{ + defSvc := knativeapi.CamelServiceDefinition{ Name: "default", Host: "0.0.0.0", Port: 8080, - Protocol: knativeutil.CamelProtocolHTTP, - ServiceType: knativeutil.CamelServiceTypeEndpoint, + Protocol: knativeapi.CamelProtocolHTTP, + ServiceType: knativeapi.CamelServiceTypeEndpoint, Metadata: map[string]string{ - knativeutil.CamelMetaServicePath: "/", + knativeapi.CamelMetaServicePath: "/", }, } env.Services = append(env.Services, defSvc)