nicolaferraro closed pull request #314: chore(knative): do not change spec
during processing
URL: https://github.com/apache/camel-k/pull/314
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/pkg/apis/camel/v1alpha1/types.go b/pkg/apis/camel/v1alpha1/types.go
index 9951e3fe..09b46fa3 100644
--- a/pkg/apis/camel/v1alpha1/types.go
+++ b/pkg/apis/camel/v1alpha1/types.go
@@ -18,12 +18,11 @@ limitations under the License.
package v1alpha1
import (
- "strings"
-
"github.com/apache/camel-k/pkg/util"
-
"github.com/mitchellh/mapstructure"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+
+ "strings"
)
// ConfigurationSpec --
@@ -137,6 +136,17 @@ const (
LanguageYamlFlow Language = "flow"
)
+// Languages is the list of all supported languages
+var Languages = []Language{
+ LanguageJavaSource,
+ LanguageJavaClass,
+ LanguageJavaScript,
+ LanguageGroovy,
+ LanguageJavaScript,
+ LanguageKotlin,
+ LanguageYamlFlow,
+}
+
// A IntegrationTraitSpec contains the configuration of a trait
type IntegrationTraitSpec struct {
Configuration map[string]string `json:"configuration,omitempty"`
@@ -164,9 +174,11 @@ func (in *IntegrationTraitSpec) Decode(target interface{})
error {
// IntegrationStatus --
type IntegrationStatus struct {
- Phase IntegrationPhase `json:"phase,omitempty"`
- Digest string `json:"digest,omitempty"`
- Image string `json:"image,omitempty"`
+ Phase IntegrationPhase `json:"phase,omitempty"`
+ Digest string `json:"digest,omitempty"`
+ Image string `json:"image,omitempty"`
+ Dependencies []string `json:"dependencies,omitempty"`
+ Context string `json:"context,omitempty"`
}
// IntegrationPhase --
diff --git a/pkg/apis/camel/v1alpha1/types_support.go
b/pkg/apis/camel/v1alpha1/types_support.go
index 95a842f9..f73414c3 100644
--- a/pkg/apis/camel/v1alpha1/types_support.go
+++ b/pkg/apis/camel/v1alpha1/types_support.go
@@ -19,9 +19,9 @@ package v1alpha1
import (
"fmt"
- "gopkg.in/yaml.v2"
"strings"
+ "gopkg.in/yaml.v2"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
@@ -138,3 +138,16 @@ func (flows Flows) Serialize() (string, error) {
}
return string(res), nil
}
+
+// InferLanguage returns the language of the source or discovers it from file
extension if not set
+func (s SourceSpec) InferLanguage() Language {
+ if s.Language != "" {
+ return s.Language
+ }
+ for _, l := range Languages {
+ if strings.HasSuffix(s.Name, "."+string(l)) {
+ return l
+ }
+ }
+ return ""
+}
diff --git a/pkg/metadata/metadata_languages_test.go
b/pkg/apis/camel/v1alpha1/types_support_test.go
similarity index 71%
rename from pkg/metadata/metadata_languages_test.go
rename to pkg/apis/camel/v1alpha1/types_support_test.go
index 8a11a56d..ebfbc7e2 100644
--- a/pkg/metadata/metadata_languages_test.go
+++ b/pkg/apis/camel/v1alpha1/types_support_test.go
@@ -15,32 +15,29 @@ See the License for the specific language governing
permissions and
limitations under the License.
*/
-package metadata
+package v1alpha1
import (
"testing"
- "github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
"github.com/stretchr/testify/assert"
)
func TestLanguageJavaSource(t *testing.T) {
- code := v1alpha1.SourceSpec{
- DataSpec: v1alpha1.DataSpec{
+ code := SourceSpec{
+ DataSpec: DataSpec{
Name: "Request.java",
},
}
- meta := Extract(code)
- assert.Equal(t, v1alpha1.LanguageJavaSource, meta.Language)
+ assert.Equal(t, LanguageJavaSource, code.InferLanguage())
}
func TestLanguageAlreadySet(t *testing.T) {
- code := v1alpha1.SourceSpec{
- DataSpec: v1alpha1.DataSpec{
+ code := SourceSpec{
+ DataSpec: DataSpec{
Name: "Request.java",
},
- Language: v1alpha1.LanguageJavaScript,
+ Language: LanguageJavaScript,
}
- meta := Extract(code)
- assert.Equal(t, v1alpha1.LanguageJavaScript, meta.Language)
+ assert.Equal(t, LanguageJavaScript, code.InferLanguage())
}
diff --git a/pkg/apis/camel/v1alpha1/zz_generated.deepcopy.go
b/pkg/apis/camel/v1alpha1/zz_generated.deepcopy.go
index 85e3be81..8df47697 100644
--- a/pkg/apis/camel/v1alpha1/zz_generated.deepcopy.go
+++ b/pkg/apis/camel/v1alpha1/zz_generated.deepcopy.go
@@ -94,13 +94,35 @@ func (in *Flow) DeepCopy() *Flow {
return out
}
+// DeepCopyInto is an autogenerated deepcopy function, copying the receiver,
writing into out. in must be non-nil.
+func (in Flows) DeepCopyInto(out *Flows) {
+ {
+ in := &in
+ *out = make(Flows, len(*in))
+ for i := range *in {
+ (*in)[i].DeepCopyInto(&(*out)[i])
+ }
+ return
+ }
+}
+
+// DeepCopy is an autogenerated deepcopy function, copying the receiver,
creating a new Flows.
+func (in Flows) DeepCopy() Flows {
+ if in == nil {
+ return nil
+ }
+ out := new(Flows)
+ in.DeepCopyInto(out)
+ return *out
+}
+
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver,
writing into out. in must be non-nil.
func (in *Integration) DeepCopyInto(out *Integration) {
*out = *in
out.TypeMeta = in.TypeMeta
in.ObjectMeta.DeepCopyInto(&out.ObjectMeta)
in.Spec.DeepCopyInto(&out.Spec)
- out.Status = in.Status
+ in.Status.DeepCopyInto(&out.Status)
return
}
@@ -453,6 +475,11 @@ func (in *IntegrationSpec) DeepCopy() *IntegrationSpec {
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver,
writing into out. in must be non-nil.
func (in *IntegrationStatus) DeepCopyInto(out *IntegrationStatus) {
*out = *in
+ if in.Dependencies != nil {
+ in, out := &in.Dependencies, &out.Dependencies
+ *out = make([]string, len(*in))
+ copy(*out, *in)
+ }
return
}
diff --git a/pkg/client/cmd/get.go b/pkg/client/cmd/get.go
index 02d47265..d9e48510 100644
--- a/pkg/client/cmd/get.go
+++ b/pkg/client/cmd/get.go
@@ -64,7 +64,7 @@ func (o *getCmdOptions) run(cmd *cobra.Command, args
[]string) error {
w := tabwriter.NewWriter(os.Stdout, 0, 8, 1, '\t', 0)
fmt.Fprintln(w, "NAME\tCONTEXT\tSTATUS")
for _, integration := range integrationList.Items {
- fmt.Fprintf(w, "%s\t%s\t%s\n", integration.Name,
integration.Spec.Context, string(integration.Status.Phase))
+ fmt.Fprintf(w, "%s\t%s\t%s\n", integration.Name,
integration.Status.Context, string(integration.Status.Phase))
}
w.Flush()
diff --git a/pkg/metadata/http.go b/pkg/metadata/http.go
index 2feeecb7..9ca6a305 100644
--- a/pkg/metadata/http.go
+++ b/pkg/metadata/http.go
@@ -87,7 +87,7 @@ func getURIPrefix(uri string) string {
}
func hasRestIndicator(source v1alpha1.SourceSpec) bool {
- pat := getRestIndicatorRegexpsForLanguage(source.Language)
+ pat := getRestIndicatorRegexpsForLanguage(source.InferLanguage())
return pat.MatchString(source.Content)
}
diff --git a/pkg/metadata/languages.go b/pkg/metadata/languages.go
deleted file mode 100644
index 55389dcd..00000000
--- a/pkg/metadata/languages.go
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
-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 metadata
-
-import (
- "strings"
-
- "github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
-)
-
-// discoverLanguage discovers the code language from file extension if not set
-func discoverLanguage(source v1alpha1.SourceSpec) v1alpha1.Language {
- if source.Language != "" {
- return source.Language
- }
- for _, l := range []v1alpha1.Language{
- v1alpha1.LanguageJavaSource,
- v1alpha1.LanguageJavaClass,
- v1alpha1.LanguageJavaScript,
- v1alpha1.LanguageGroovy,
- v1alpha1.LanguageJavaScript,
- v1alpha1.LanguageKotlin,
- v1alpha1.LanguageYamlFlow} {
-
- if strings.HasSuffix(source.Name, "."+string(l)) {
- return l
- }
- }
- return ""
-}
diff --git a/pkg/metadata/metadata.go b/pkg/metadata/metadata.go
index 4f7d9806..bbdacfdb 100644
--- a/pkg/metadata/metadata.go
+++ b/pkg/metadata/metadata.go
@@ -28,7 +28,6 @@ import (
func ExtractAll(sources []v1alpha1.SourceSpec) IntegrationMetadata {
// neutral metadata
meta := IntegrationMetadata{
- Language: "",
Dependencies: []string{},
FromURIs: []string{},
ToURIs: []string{},
@@ -42,10 +41,6 @@ func ExtractAll(sources []v1alpha1.SourceSpec)
IntegrationMetadata {
}
func merge(m1 IntegrationMetadata, m2 IntegrationMetadata) IntegrationMetadata
{
- language := m2.Language
- if m1.Language != "" && m1.Language != language {
- language = ""
- }
deps := make(map[string]bool)
for _, d := range m1.Dependencies {
deps[d] = true
@@ -59,7 +54,6 @@ func merge(m1 IntegrationMetadata, m2 IntegrationMetadata)
IntegrationMetadata {
}
sort.Strings(allDependencies)
return IntegrationMetadata{
- Language: language,
FromURIs: append(m1.FromURIs, m2.FromURIs...),
ToURIs: append(m1.ToURIs, m2.ToURIs...),
Dependencies: allDependencies,
@@ -70,7 +64,7 @@ func merge(m1 IntegrationMetadata, m2 IntegrationMetadata)
IntegrationMetadata {
// Extract returns metadata information from the source code
func Extract(source v1alpha1.SourceSpec) IntegrationMetadata {
- language := discoverLanguage(source)
+ language := source.InferLanguage()
// TODO: handle error
fromURIs, _ := src.InspectorForLanguage(language).FromURIs(source)
// TODO:: handle error
@@ -79,7 +73,6 @@ func Extract(source v1alpha1.SourceSpec) IntegrationMetadata {
requiresHTTPService := requiresHTTPService(source, fromURIs)
passiveEndpoints := hasOnlyPassiveEndpoints(source, fromURIs)
return IntegrationMetadata{
- Language: language,
FromURIs: fromURIs,
ToURIs: toURIs,
Dependencies: dependencies,
diff --git a/pkg/metadata/types.go b/pkg/metadata/types.go
index 2874eafc..af81ef11 100644
--- a/pkg/metadata/types.go
+++ b/pkg/metadata/types.go
@@ -17,8 +17,6 @@ limitations under the License.
package metadata
-import "github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
-
// IntegrationMetadata contains aggregate metadata about all Camel routes in a
integrations
type IntegrationMetadata struct {
// All starting URIs of defined routes
@@ -27,8 +25,6 @@ type IntegrationMetadata struct {
ToURIs []string
// All inferred dependencies required to run the integration
Dependencies []string
- // The language in which the integration is written
- Language v1alpha1.Language
// RequiresHTTPService indicates if the integration needs to be invoked
through HTTP
RequiresHTTPService bool
// PassiveEndpoints indicates that the integration contains only
passive endpoints that are activated from
diff --git a/pkg/stub/action/context/build.go b/pkg/stub/action/context/build.go
index 08394c9e..eebf87e7 100644
--- a/pkg/stub/action/context/build.go
+++ b/pkg/stub/action/context/build.go
@@ -136,7 +136,7 @@ func (action *buildAction) informIntegrations(context
*v1alpha1.IntegrationConte
}
for _, integration := range list.Items {
integration := integration // pin
- if integration.Spec.Context != context.Name {
+ if integration.Status.Context != context.Name {
continue
}
diff --git a/pkg/stub/action/integration/build_context.go
b/pkg/stub/action/integration/build_context.go
index 97da4aa8..9f252258 100644
--- a/pkg/stub/action/integration/build_context.go
+++ b/pkg/stub/action/integration/build_context.go
@@ -66,12 +66,12 @@ func (action *buildContextAction) Handle(integration
*v1alpha1.Integration) erro
// amended to add/remove dependencies
//TODO: this is a very simple check, we may need to
provide a deps comparison strategy
- if !util.StringSliceContains(ctx.Spec.Dependencies,
integration.Spec.Dependencies) {
+ if !util.StringSliceContains(ctx.Spec.Dependencies,
integration.Status.Dependencies) {
// We need to re-generate a context or search
for a new one that
// satisfies integrations needs so let's remove
the association
// with a context
target := integration.DeepCopy()
- target.Spec.Context = ""
+ target.Status.Context = ""
return sdk.Update(target)
}
}
@@ -79,7 +79,7 @@ func (action *buildContextAction) Handle(integration
*v1alpha1.Integration) erro
if ctx.Status.Phase == v1alpha1.IntegrationContextPhaseError {
target := integration.DeepCopy()
target.Status.Image = ctx.ImageForIntegration()
- target.Spec.Context = ctx.Name
+ target.Status.Context = ctx.Name
target.Status.Phase = v1alpha1.IntegrationPhaseError
target.Status.Digest, err =
digest.ComputeForIntegration(target)
@@ -95,7 +95,7 @@ func (action *buildContextAction) Handle(integration
*v1alpha1.Integration) erro
if ctx.Status.Phase == v1alpha1.IntegrationContextPhaseReady {
target := integration.DeepCopy()
target.Status.Image = ctx.ImageForIntegration()
- target.Spec.Context = ctx.Name
+ target.Status.Context = ctx.Name
dgst, err := digest.ComputeForIntegration(target)
if err != nil {
@@ -113,10 +113,10 @@ func (action *buildContextAction) Handle(integration
*v1alpha1.Integration) erro
return sdk.Update(target)
}
- if integration.Spec.Context == "" {
+ if integration.Status.Context == "" {
// We need to set the context
target := integration.DeepCopy()
- target.Spec.Context = ctx.Name
+ target.Status.Context = ctx.Name
return sdk.Update(target)
}
@@ -137,7 +137,7 @@ func (action *buildContextAction) Handle(integration
*v1alpha1.Integration) erro
// Set the context to have the same dependencies as the integrations
platformCtx.Spec = v1alpha1.IntegrationContextSpec{
- Dependencies: integration.Spec.Dependencies,
+ Dependencies: integration.Status.Dependencies,
Repositories: integration.Spec.Repositories,
Traits: integration.Spec.Traits,
}
@@ -149,7 +149,7 @@ func (action *buildContextAction) Handle(integration
*v1alpha1.Integration) erro
// Set the context name so the next handle loop, will fall through the
// same path as integration with a user defined context
target := integration.DeepCopy()
- target.Spec.Context = platformCtxName
+ target.Status.Context = platformCtxName
return sdk.Update(target)
}
diff --git a/pkg/stub/action/integration/build_image.go
b/pkg/stub/action/integration/build_image.go
index 44440cfb..62058f52 100644
--- a/pkg/stub/action/integration/build_image.go
+++ b/pkg/stub/action/integration/build_image.go
@@ -62,13 +62,13 @@ func (action *buildImageAction) Handle(integration
*v1alpha1.Integration) error
// in this phase the integration need to be associated to a context
whose image
// will be used as base image for the integration images
- if integration.Spec.Context == "" {
+ if integration.Status.Context == "" {
return fmt.Errorf("context is not set for integration: %s",
integration.Name)
}
// look-up the integration context associated to this integration, this
is needed
// to determine the base image
- ctx := v1alpha1.NewIntegrationContext(integration.Namespace,
integration.Spec.Context)
+ ctx := v1alpha1.NewIntegrationContext(integration.Namespace,
integration.Status.Context)
if err := sdk.Get(&ctx); err != nil {
return errors.Wrapf(err, "unable to find integration context
%s, %s", ctx.Name, err)
}
diff --git a/pkg/stub/action/integration/deploy.go
b/pkg/stub/action/integration/deploy.go
index ad0d04ad..7ceaeef4 100644
--- a/pkg/stub/action/integration/deploy.go
+++ b/pkg/stub/action/integration/deploy.go
@@ -43,7 +43,10 @@ func (action *deployAction) CanHandle(integration
*v1alpha1.Integration) bool {
}
func (action *deployAction) Handle(integration *v1alpha1.Integration) error {
- ctxName := integration.Spec.Context
+ ctxName := integration.Status.Context
+ if ctxName == "" {
+ return errors.Errorf("no context set on integration %s",
integration.Name)
+ }
ctx := v1alpha1.NewIntegrationContext(integration.Namespace, ctxName)
if err := sdk.Get(&ctx); err != nil {
diff --git a/pkg/stub/action/integration/initialize.go
b/pkg/stub/action/integration/initialize.go
index eea19574..aa4f5dcb 100644
--- a/pkg/stub/action/integration/initialize.go
+++ b/pkg/stub/action/integration/initialize.go
@@ -19,7 +19,6 @@ package integration
import (
"github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
- "github.com/apache/camel-k/pkg/metadata"
"github.com/apache/camel-k/pkg/platform"
"github.com/apache/camel-k/pkg/trait"
"github.com/apache/camel-k/pkg/util/digest"
@@ -54,18 +53,8 @@ func (action *initializeAction) Handle(integration
*v1alpha1.Integration) error
}
target := integration.DeepCopy()
- // set default values
- if target.Spec.Replicas == nil {
- var defaultReplicas int32 = 1
- target.Spec.Replicas = &defaultReplicas
- }
- for i := range target.Spec.Sources {
- // extract metadata
- s := &target.Spec.Sources[i]
-
- meta := metadata.Extract(*s)
- s.Language = meta.Language
- }
+ // better not changing the spec section of the target because it may be
used for comparison by a
+ // higher level controller (e.g. Knative source controller)
// execute custom initialization
if _, err := trait.Apply(target, nil); err != nil {
@@ -80,6 +69,9 @@ func (action *initializeAction) Handle(integration
*v1alpha1.Integration) error
target.Status.Phase = v1alpha1.IntegrationPhaseBuildingContext
target.Status.Digest = dgst
+ target.Status.Context = integration.Spec.Context
+ target.Status.Dependencies = integration.Spec.Dependencies
+ target.Status.Image = ""
logrus.Info("Integration ", target.Name, " transitioning to state ",
target.Status.Phase)
diff --git a/pkg/stub/action/integration/monitor.go
b/pkg/stub/action/integration/monitor.go
index d0e8107a..7f3bf335 100644
--- a/pkg/stub/action/integration/monitor.go
+++ b/pkg/stub/action/integration/monitor.go
@@ -53,7 +53,7 @@ func (action *monitorAction) Handle(integration
*v1alpha1.Integration) error {
target := integration.DeepCopy()
target.Status.Digest = hash
- target.Status.Phase = v1alpha1.IntegrationPhaseBuildingContext
+ target.Status.Phase = ""
logrus.Info("Integration ", target.Name, " transitioning to
state ", target.Status.Phase)
diff --git a/pkg/stub/action/integration/util.go
b/pkg/stub/action/integration/util.go
index 26c1fd8a..15230c76 100644
--- a/pkg/stub/action/integration/util.go
+++ b/pkg/stub/action/integration/util.go
@@ -27,8 +27,8 @@ import (
// LookupContextForIntegration --
func LookupContextForIntegration(integration *v1alpha1.Integration)
(*v1alpha1.IntegrationContext, error) {
- if integration.Spec.Context != "" {
- name := integration.Spec.Context
+ if integration.Status.Context != "" {
+ name := integration.Status.Context
ctx := v1alpha1.NewIntegrationContext(integration.Namespace,
name)
if err := sdk.Get(&ctx); err != nil {
@@ -46,14 +46,14 @@ func LookupContextForIntegration(integration
*v1alpha1.Integration) (*v1alpha1.I
for _, ctx := range ctxList.Items {
ctx := ctx // pin
if ctx.Labels["camel.apache.org/context.type"] ==
v1alpha1.IntegrationContextTypePlatform {
- ideps := len(integration.Spec.Dependencies)
+ ideps := len(integration.Status.Dependencies)
cdeps := len(ctx.Spec.Dependencies)
if ideps != cdeps {
continue
}
- if util.StringSliceContains(ctx.Spec.Dependencies,
integration.Spec.Dependencies) {
+ if util.StringSliceContains(ctx.Spec.Dependencies,
integration.Status.Dependencies) {
return &ctx, nil
}
}
diff --git a/pkg/trait/classpath.go b/pkg/trait/classpath.go
index 3936584b..619e6b31 100644
--- a/pkg/trait/classpath.go
+++ b/pkg/trait/classpath.go
@@ -54,8 +54,8 @@ func (t *classpathTrait) Configure(e *Environment) (bool,
error) {
func (t *classpathTrait) Apply(e *Environment) error {
ctx := e.Context
- if ctx == nil && e.Integration.Spec.Context != "" {
- name := e.Integration.Spec.Context
+ if ctx == nil && e.Integration.Status.Context != "" {
+ name := e.Integration.Status.Context
c := v1alpha1.NewIntegrationContext(e.Integration.Namespace,
name)
if err := sdk.Get(&c); err != nil {
@@ -66,7 +66,7 @@ func (t *classpathTrait) Apply(e *Environment) error {
}
if ctx == nil {
- return fmt.Errorf("unable to find integration context %s",
e.Integration.Spec.Context)
+ return fmt.Errorf("unable to find integration context %s",
e.Integration.Status.Context)
}
deps := make([]string, 0, 2+len(ctx.Status.Artifacts))
diff --git a/pkg/trait/dependencies.go b/pkg/trait/dependencies.go
index eddee8b3..4052e4cf 100644
--- a/pkg/trait/dependencies.go
+++ b/pkg/trait/dependencies.go
@@ -46,28 +46,35 @@ func (t *dependenciesTrait) Configure(e *Environment)
(bool, error) {
}
func (t *dependenciesTrait) Apply(e *Environment) error {
+ dependencies := make([]string, 0)
+ if e.Integration.Spec.Dependencies != nil {
+ for _, dep := range e.Integration.Spec.Dependencies {
+ util.StringSliceUniqueAdd(&dependencies, dep)
+ }
+ }
for _, s := range e.Integration.Spec.Sources {
meta := metadata.Extract(s)
- switch meta.Language {
+ switch s.InferLanguage() {
case v1alpha1.LanguageGroovy:
-
util.StringSliceUniqueAdd(&e.Integration.Spec.Dependencies, "runtime:groovy")
+ util.StringSliceUniqueAdd(&dependencies,
"runtime:groovy")
case v1alpha1.LanguageKotlin:
-
util.StringSliceUniqueAdd(&e.Integration.Spec.Dependencies, "runtime:kotlin")
+ util.StringSliceUniqueAdd(&dependencies,
"runtime:kotlin")
case v1alpha1.LanguageYamlFlow:
-
util.StringSliceUniqueAdd(&e.Integration.Spec.Dependencies, "runtime:yaml")
+ util.StringSliceUniqueAdd(&dependencies, "runtime:yaml")
}
// jvm runtime and camel-core required by default
- util.StringSliceUniqueAdd(&e.Integration.Spec.Dependencies,
"runtime:jvm")
- util.StringSliceUniqueAdd(&e.Integration.Spec.Dependencies,
"camel:core")
+ util.StringSliceUniqueAdd(&dependencies, "runtime:jvm")
+ util.StringSliceUniqueAdd(&dependencies, "camel:core")
for _, d := range meta.Dependencies {
-
util.StringSliceUniqueAdd(&e.Integration.Spec.Dependencies, d)
+ util.StringSliceUniqueAdd(&dependencies, d)
}
}
// sort the dependencies to get always the same list if they don't
change
- sort.Strings(e.Integration.Spec.Dependencies)
+ sort.Strings(dependencies)
+ e.Integration.Status.Dependencies = dependencies
return nil
}
diff --git a/pkg/trait/deployment.go b/pkg/trait/deployment.go
index ec53ac31..63790c6d 100644
--- a/pkg/trait/deployment.go
+++ b/pkg/trait/deployment.go
@@ -142,7 +142,7 @@ func (t *deploymentTrait) getConfigMapsFor(e *Environment)
[]runtime.Object {
"camel.apache.org/integration":
e.Integration.Name,
},
Annotations: map[string]string{
-
"camel.apache.org/source.language": string(s.Language),
+
"camel.apache.org/source.language": string(s.InferLanguage()),
"camel.apache.org/source.name":
s.Name,
"camel.apache.org/source.compression": strconv.FormatBool(s.Compression),
},
@@ -207,8 +207,8 @@ func (t *deploymentTrait) getSources(e *Environment)
[]string {
src = "file:" + src
params := make([]string, 0)
- if s.Language != "" {
- params = append(params, "language="+string(s.Language))
+ if s.InferLanguage() != "" {
+ params = append(params,
"language="+string(s.InferLanguage()))
}
if s.Compression {
params = append(params, "compression=true")
diff --git a/pkg/trait/knative.go b/pkg/trait/knative.go
index 977d6add..f5f02a3c 100644
--- a/pkg/trait/knative.go
+++ b/pkg/trait/knative.go
@@ -142,8 +142,8 @@ func (t *knativeTrait) getServiceFor(e *Environment)
*serving.Service {
envvar.SetVal(&environment, envName, s.Content)
params := make([]string, 0)
- if s.Language != "" {
- params = append(params, "language="+string(s.Language))
+ if s.InferLanguage() != "" {
+ params = append(params,
"language="+string(s.InferLanguage()))
}
if s.Compression {
params = append(params, "compression=true")
@@ -295,7 +295,9 @@ func (t *knativeTrait) getConfigurationSerialized(e
*Environment) (string, error
func (t *knativeTrait) getConfiguration(e *Environment)
(knativeapi.CamelEnvironment, error) {
env := knativeapi.NewCamelEnvironment()
if t.Configuration != "" {
- env.Deserialize(t.Configuration)
+ if err := env.Deserialize(t.Configuration); err != nil {
+ return knativeapi.CamelEnvironment{}, err
+ }
}
// Sources
diff --git a/pkg/trait/springboot.go b/pkg/trait/springboot.go
index fb280ba2..7c790e53 100644
--- a/pkg/trait/springboot.go
+++ b/pkg/trait/springboot.go
@@ -66,10 +66,10 @@ func (t *springBootTrait) Apply(e *Environment) error {
//
if e.IntegrationInPhase("") {
- util.StringSliceUniqueAdd(&e.Integration.Spec.Dependencies,
"runtime:spring-boot")
+ util.StringSliceUniqueAdd(&e.Integration.Status.Dependencies,
"runtime:spring-boot")
// sort the dependencies to get always the same list if they
don't change
- sort.Strings(e.Integration.Spec.Dependencies)
+ sort.Strings(e.Integration.Status.Dependencies)
}
if e.InPhase(v1alpha1.IntegrationContextPhaseReady,
v1alpha1.IntegrationPhaseDeploying) {
diff --git a/pkg/trait/util.go b/pkg/trait/util.go
index ad6e1d32..f9875a5a 100644
--- a/pkg/trait/util.go
+++ b/pkg/trait/util.go
@@ -26,11 +26,11 @@ import (
// GetIntegrationContext retrieves the context set on the integration
func GetIntegrationContext(integration *v1alpha1.Integration)
(*v1alpha1.IntegrationContext, error) {
- if integration.Spec.Context == "" {
+ if integration.Status.Context == "" {
return nil, nil
}
- name := integration.Spec.Context
+ name := integration.Status.Context
ctx := v1alpha1.NewIntegrationContext(integration.Namespace, name)
err := sdk.Get(&ctx)
return &ctx, err
diff --git a/pkg/util/source/inspector_xml.go b/pkg/util/source/inspector_xml.go
index c13f1e61..b2bd2e8a 100644
--- a/pkg/util/source/inspector_xml.go
+++ b/pkg/util/source/inspector_xml.go
@@ -42,8 +42,7 @@ func (i XMLInspector) FromURIs(source v1alpha1.SourceSpec)
([]string, error) {
break
}
- switch se := t.(type) {
- case xml.StartElement:
+ if se, ok := t.(xml.StartElement); ok {
switch se.Name.Local {
case "from", "fromF":
for _, a := range se.Attr {
@@ -72,8 +71,7 @@ func (i XMLInspector) ToURIs(source v1alpha1.SourceSpec)
([]string, error) {
break
}
- switch se := t.(type) {
- case xml.StartElement:
+ if se, ok := t.(xml.StartElement); ok {
switch se.Name.Local {
case "to", "toD", "toF":
for _, a := range se.Attr {
diff --git a/pkg/util/util.go b/pkg/util/util.go
index 18594ad4..7cd9712b 100644
--- a/pkg/util/util.go
+++ b/pkg/util/util.go
@@ -52,6 +52,10 @@ func StringSliceExists(slice []string, item string) bool {
// StringSliceUniqueAdd append the given item if not already present in the
slice
func StringSliceUniqueAdd(slice *[]string, item string) bool {
+ if slice == nil {
+ newSlice := make([]string, 0)
+ slice = &newSlice
+ }
for _, i := range *slice {
if i == item {
return false
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services