This is an automated email from the ASF dual-hosted git repository. astefanutti pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit 8f9711875b856aea33692f78022d83f9569c047f Author: Antonin Stefanutti <[email protected]> AuthorDate: Thu Jun 11 17:23:37 2020 +0200 fix: Fix integration Flows as raw extensions --- e2e/knative/knative_platform_test.go | 13 ++++---- pkg/cmd/run.go | 8 ++--- pkg/trait/init.go | 16 ++++------ pkg/util/digest/digest.go | 9 ++---- pkg/util/flows/io.go | 58 ------------------------------------ pkg/util/flows/io_test.go | 46 ---------------------------- 6 files changed, 15 insertions(+), 135 deletions(-) diff --git a/e2e/knative/knative_platform_test.go b/e2e/knative/knative_platform_test.go index 37a7a4a..da40c46 100644 --- a/e2e/knative/knative_platform_test.go +++ b/e2e/knative/knative_platform_test.go @@ -27,10 +27,8 @@ import ( . "github.com/apache/camel-k/e2e/support" "github.com/apache/camel-k/pkg/apis/camel/v1" - "github.com/apache/camel-k/pkg/util/flows" "github.com/apache/camel-k/pkg/util/knative" . "github.com/onsi/gomega" - "github.com/stretchr/testify/assert" corev1 "k8s.io/api/core/v1" ) @@ -55,12 +53,11 @@ func TestKnativePlatformTest(t *testing.T) { // Change something in the integration to produce a redeploy Expect(UpdateIntegration(ns, "yaml", func(it *v1.Integration) { it.Spec.Profile = "" - content, err := flows.Marshal(it.Spec.Flows) - assert.NoError(t, err) - newData := strings.ReplaceAll(string(content), "string!", "string!!!") - newFlows, err := flows.UnmarshalString(newData) - assert.NoError(t, err) - it.Spec.Flows = newFlows + var flows []v1.Flow + for _, flow := range it.Spec.Flows { + flows = append(flows, []byte(strings.ReplaceAll(string(flow), "string!", "string!!!"))) + } + it.Spec.Flows = flows })).To(BeNil()) // Spec profile should be reset by "kamel run" Eventually(IntegrationSpecProfile(ns, "yaml")).Should(Equal(v1.TraitProfile(""))) diff --git a/pkg/cmd/run.go b/pkg/cmd/run.go index b831f0b..e18494d 100644 --- a/pkg/cmd/run.go +++ b/pkg/cmd/run.go @@ -36,7 +36,6 @@ import ( "github.com/apache/camel-k/pkg/client" "github.com/apache/camel-k/pkg/trait" "github.com/apache/camel-k/pkg/util" - "github.com/apache/camel-k/pkg/util/flows" "github.com/apache/camel-k/pkg/util/gzip" "github.com/apache/camel-k/pkg/util/kubernetes" k8slog "github.com/apache/camel-k/pkg/util/kubernetes/log" @@ -472,11 +471,8 @@ func (o *runCmdOptions) updateIntegrationCode(c client.Client, sources []string) } if o.UseFlows && (strings.HasSuffix(source, ".yaml") || strings.HasSuffix(source, ".yml")) { - flows, err := flows.UnmarshalString(data) - if err != nil { - return nil, err - } - integration.Spec.AddFlows(flows...) + flows := []byte(data) + integration.Spec.AddFlows(flows) } else { integration.Spec.AddSources(v1.SourceSpec{ DataSpec: v1.DataSpec{ diff --git a/pkg/trait/init.go b/pkg/trait/init.go index c81cde7..d060021 100644 --- a/pkg/trait/init.go +++ b/pkg/trait/init.go @@ -21,13 +21,13 @@ import ( "fmt" "sort" + "github.com/pkg/errors" + v1 "github.com/apache/camel-k/pkg/apis/camel/v1" "github.com/apache/camel-k/pkg/util" - "github.com/apache/camel-k/pkg/util/flows" - "github.com/pkg/errors" ) -const flowsInternalSourceName = "camel-k-embedded-flow.yaml" +const flowsInternalSourceName = "camel-k-embedded-flow-%d.yaml" // Internal trait type initTrait struct { @@ -52,15 +52,11 @@ func (t *initTrait) Apply(e *Environment) error { if e.IntegrationInPhase(v1.IntegrationPhaseInitialization) { // Flows need to be turned into a generated source - if len(e.Integration.Spec.Flows) > 0 { - content, err := flows.Marshal(e.Integration.Spec.Flows) - if err != nil { - return err - } + for i, flow := range e.Integration.Spec.Flows { e.Integration.Status.AddOrReplaceGeneratedSources(v1.SourceSpec{ DataSpec: v1.DataSpec{ - Name: flowsInternalSourceName, - Content: string(content), + Name: fmt.Sprintf(flowsInternalSourceName, i), + Content: string(flow), }, }) } diff --git a/pkg/util/digest/digest.go b/pkg/util/digest/digest.go index 7488c89..c6dec3c 100644 --- a/pkg/util/digest/digest.go +++ b/pkg/util/digest/digest.go @@ -31,7 +31,6 @@ import ( v1 "github.com/apache/camel-k/pkg/apis/camel/v1" "github.com/apache/camel-k/pkg/util" "github.com/apache/camel-k/pkg/util/defaults" - "github.com/apache/camel-k/pkg/util/flows" ) // ComputeForIntegration a digest of the fields that are relevant for the deployment @@ -68,12 +67,8 @@ func ComputeForIntegration(integration *v1.Integration) (string, error) { } // Integration flows - if len(integration.Spec.Flows) > 0 { - flowData, err := flows.Marshal(integration.Spec.Flows) - if err != nil { - return "", err - } - if _, err := hash.Write(flowData); err != nil { + for _, flow := range integration.Spec.Flows { + if _, err := hash.Write(flow); err != nil { return "", err } } diff --git a/pkg/util/flows/io.go b/pkg/util/flows/io.go deleted file mode 100644 index 9c3e13e..0000000 --- a/pkg/util/flows/io.go +++ /dev/null @@ -1,58 +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 flows - -import ( - "bytes" - "encoding/json" - "io" - "io/ioutil" - - v1 "github.com/apache/camel-k/pkg/apis/camel/v1" - yaml2 "gopkg.in/yaml.v2" - "k8s.io/apimachinery/pkg/util/yaml" -) - -// UnmarshalString reads flows contained in a string -func UnmarshalString(flowsString string) ([]v1.Flow, error) { - return Unmarshal(bytes.NewReader([]byte(flowsString))) -} - -// Unmarshal flows from a stream -func Unmarshal(reader io.Reader) ([]v1.Flow, error) { - buffered, err := ioutil.ReadAll(reader) - if err != nil { - return nil, err - } - var flows []v1.Flow - // Using the Kubernetes decoder to turn them into JSON before unmarshal. - // This avoids having map[interface{}]interface{} objects which are not JSON compatible. - jsonData, err := yaml.ToJSON(buffered) - if err != nil { - return nil, err - } - if err = json.Unmarshal(jsonData, &flows); err != nil { - return nil, err - } - return flows, err -} - -// Marshal flows as byte array -func Marshal(flows []v1.Flow) ([]byte, error) { - return yaml2.Marshal(flows) -} diff --git a/pkg/util/flows/io_test.go b/pkg/util/flows/io_test.go deleted file mode 100644 index cfaf884..0000000 --- a/pkg/util/flows/io_test.go +++ /dev/null @@ -1,46 +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 flows - -import ( - "bytes" - "testing" - - "github.com/stretchr/testify/assert" -) - -func TestReadWriteYaml(t *testing.T) { - // yaml in conventional form as marshalled by the go runtime - yaml := `- from: - steps: - - to: log:info - uri: timer:tick -` - yamlReader := bytes.NewReader([]byte(yaml)) - flows, err := Unmarshal(yamlReader) - assert.NoError(t, err) - assert.NotNil(t, flows) - assert.Len(t, flows, 1) - assert.NotNil(t, flows[0]["from"]) - assert.Nil(t, flows[0]["xx"]) - - clone, err := Marshal(flows) - assert.NoError(t, err) - assert.NotNil(t, clone) - assert.Equal(t, yaml, string(clone)) -}
