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/10/11 13:49:24 UTC
[camel-k] 01/02: fix #1005: allow to customize loader and add
default dependencies for knative-source loader
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 d5b004821ad0ac37f3dc0ddaee86447feae16dea
Author: nferraro <ni...@gmail.com>
AuthorDate: Fri Oct 11 13:28:55 2019 +0200
fix #1005: allow to customize loader and add default dependencies for knative-source loader
---
pkg/apis/camel/v1alpha1/integration_types.go | 3 ++
pkg/trait/dependencies.go | 6 ++++
pkg/trait/dependencies_test.go | 44 ++++++++++++++++++++++++++++
pkg/trait/trait_types.go | 4 +++
4 files changed, 57 insertions(+)
diff --git a/pkg/apis/camel/v1alpha1/integration_types.go b/pkg/apis/camel/v1alpha1/integration_types.go
index 2b0ba8e..3d8d488 100644
--- a/pkg/apis/camel/v1alpha1/integration_types.go
+++ b/pkg/apis/camel/v1alpha1/integration_types.go
@@ -107,6 +107,9 @@ const (
type SourceSpec struct {
DataSpec
Language Language `json:"language,omitempty"`
+ // Loader is an optional id of the org.apache.camel.k.RoutesLoader that will
+ // interpret this source at runtime
+ Loader string `json:"loader,omitempty"`
}
// Language --
diff --git a/pkg/trait/dependencies.go b/pkg/trait/dependencies.go
index 7a2b94b..9659577 100644
--- a/pkg/trait/dependencies.go
+++ b/pkg/trait/dependencies.go
@@ -19,6 +19,7 @@ package trait
import (
"sort"
+ "strings"
"github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
"github.com/apache/camel-k/pkg/metadata"
@@ -70,6 +71,11 @@ func (t *dependenciesTrait) Apply(e *Environment) error {
util.StringSliceUniqueAdd(&dependencies, "mvn:org.apache.camel.k/camel-k-loader-java")
}
+ if strings.HasPrefix(s.Loader, "knative-source") {
+ util.StringSliceUniqueAdd(&dependencies, "mvn:org.apache.camel.k/camel-k-loader-knative")
+ util.StringSliceUniqueAdd(&dependencies, "mvn:org.apache.camel.k/camel-k-runtime-knative")
+ }
+
// main required by default
util.StringSliceUniqueAdd(&dependencies, "mvn:org.apache.camel.k/camel-k-runtime-main")
diff --git a/pkg/trait/dependencies_test.go b/pkg/trait/dependencies_test.go
index fd9ae24..d92866a 100644
--- a/pkg/trait/dependencies_test.go
+++ b/pkg/trait/dependencies_test.go
@@ -188,3 +188,47 @@ func TestIntegrationAutoGeneratedDeps(t *testing.T) {
e.Integration.Status.Dependencies,
)
}
+
+func TestIntegrationCustomLoader(t *testing.T) {
+ catalog, err := test.DefaultCatalog()
+ assert.Nil(t, err)
+
+ e := &Environment{
+ CamelCatalog: catalog,
+ Integration: &v1alpha1.Integration{
+ Spec: v1alpha1.IntegrationSpec{
+ Sources: []v1alpha1.SourceSpec{
+ {
+ DataSpec: v1alpha1.DataSpec{
+ Name: "flow.yaml",
+ Content: "- from:\n uri: direct:foo\n steps:\n - to: log:bar",
+ },
+ Language: v1alpha1.LanguageYaml,
+ Loader: "knative-source-yaml",
+ },
+ },
+ },
+ Status: v1alpha1.IntegrationStatus{
+ Phase: v1alpha1.IntegrationPhaseInitialization,
+ },
+ },
+ }
+
+ trait := newDependenciesTrait()
+ enabled, err := trait.Configure(e)
+ assert.Nil(t, err)
+ assert.True(t, enabled)
+
+ err = trait.Apply(e)
+ assert.Nil(t, err)
+ assert.ElementsMatch(t,
+ []string{
+ "camel:direct",
+ "camel:log",
+ "mvn:org.apache.camel.k/camel-k-loader-knative",
+ "mvn:org.apache.camel.k/camel-k-loader-yaml",
+ "mvn:org.apache.camel.k/camel-k-runtime-knative",
+ "mvn:org.apache.camel.k/camel-k-runtime-main"},
+ e.Integration.Status.Dependencies,
+ )
+}
diff --git a/pkg/trait/trait_types.go b/pkg/trait/trait_types.go
index fabf049..f1cb187 100644
--- a/pkg/trait/trait_types.go
+++ b/pkg/trait/trait_types.go
@@ -325,6 +325,7 @@ func (e *Environment) ComputeConfigMaps() []runtime.Object {
},
Annotations: map[string]string{
"camel.apache.org/source.language": string(s.InferLanguage()),
+ "camel.apache.org/source.loader": s.Loader,
"camel.apache.org/source.name": s.Name,
"camel.apache.org/source.compression": strconv.FormatBool(s.Compression),
},
@@ -394,6 +395,9 @@ func (e *Environment) ComputeSourcesURI() []string {
if s.InferLanguage() != "" {
params = append(params, "language="+string(s.InferLanguage()))
}
+ if s.Loader != "" {
+ params = append(params, "loader="+s.Loader)
+ }
if s.Compression {
params = append(params, "compression=true")
}