fix #1005: allow to customize loader and add default dependencies for knative-source loader
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 @@
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 @@
import (
"sort"
+ "strings"
"github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
"github.com/apache/camel-k/pkg/metadata"
@@ -70,6 +71,11 @@
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 @@
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 @@
},
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 @@
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")
}