From fa7970bb639f768c5236fd56e5be4f8806dce64b Mon Sep 17 00:00:00 2001 From: Philippe Martin Date: Thu, 18 Aug 2022 17:46:24 +0200 Subject: [PATCH] Revert "Watch for devfile dependencies (#6020)" This reverts commit 04dec8529e80efb964f0f13b06987eeebaa634a9. --- pkg/libdevfile/generator/component.go | 20 - .../testdata/child-devfile-commands-only.yaml | 22 - .../testdata/child-devfile-complete.yaml | 34 -- .../child-devfile-components-only.yaml | 17 - pkg/libdevfile/testdata/child-devfile.yaml | 5 - .../parent/parent-devfile-commands-only.yaml | 20 - .../parent-devfile-components-only.yaml | 15 - .../testdata/parent/parent-devfile-empty.yaml | 3 - .../testdata/parent/parent-devfile.yaml | 32 -- pkg/libdevfile/uris.go | 123 ---- pkg/libdevfile/uris_test.go | 527 ------------------ pkg/watch/watch.go | 13 +- .../source/devfiles/nodejs/devfile-child.yaml | 5 - .../devfiles/nodejs/devfile-parent.yaml | 61 -- tests/helper/helper_filesystem.go | 12 - tests/integration/cmd_dev_test.go | 36 -- 16 files changed, 3 insertions(+), 942 deletions(-) delete mode 100644 pkg/libdevfile/testdata/child-devfile-commands-only.yaml delete mode 100644 pkg/libdevfile/testdata/child-devfile-complete.yaml delete mode 100644 pkg/libdevfile/testdata/child-devfile-components-only.yaml delete mode 100644 pkg/libdevfile/testdata/child-devfile.yaml delete mode 100644 pkg/libdevfile/testdata/parent/parent-devfile-commands-only.yaml delete mode 100644 pkg/libdevfile/testdata/parent/parent-devfile-components-only.yaml delete mode 100644 pkg/libdevfile/testdata/parent/parent-devfile-empty.yaml delete mode 100644 pkg/libdevfile/testdata/parent/parent-devfile.yaml delete mode 100644 pkg/libdevfile/uris.go delete mode 100644 pkg/libdevfile/uris_test.go delete mode 100644 tests/examples/source/devfiles/nodejs/devfile-child.yaml delete mode 100644 tests/examples/source/devfiles/nodejs/devfile-parent.yaml diff --git a/pkg/libdevfile/generator/component.go b/pkg/libdevfile/generator/component.go index 1644e4c5e13..d7a2703d177 100644 --- a/pkg/libdevfile/generator/component.go +++ b/pkg/libdevfile/generator/component.go @@ -70,23 +70,3 @@ func GetKubernetesComponent(params KubernetesComponentParams) v1alpha2.Component } return cmp } - -type OpenshiftComponentParams struct { - Name string - Attributes *attributes.Attributes - - Openshift *v1alpha2.OpenshiftComponent -} - -func GetOpenshiftComponent(params OpenshiftComponentParams) v1alpha2.Component { - cmp := v1alpha2.Component{ - Name: params.Name, - ComponentUnion: v1alpha2.ComponentUnion{ - Openshift: params.Openshift, - }, - } - if params.Attributes != nil { - cmp.Attributes = *params.Attributes - } - return cmp -} diff --git a/pkg/libdevfile/testdata/child-devfile-commands-only.yaml b/pkg/libdevfile/testdata/child-devfile-commands-only.yaml deleted file mode 100644 index 06f503bb3fc..00000000000 --- a/pkg/libdevfile/testdata/child-devfile-commands-only.yaml +++ /dev/null @@ -1,22 +0,0 @@ -schemaVersion: 2.1.0 -metadata: - name: child -parent: - uri: parent/parent-devfile-components-only.yaml -commands: -- exec: - commandLine: GOCACHE=${PROJECT_SOURCE}/.cache go build main.go - component: runtime - group: - isDefault: true - kind: build - workingDir: ${PROJECT_SOURCE} - id: build -- exec: - commandLine: ./main - component: runtime - group: - isDefault: true - kind: run - workingDir: ${PROJECT_SOURCE} - id: run diff --git a/pkg/libdevfile/testdata/child-devfile-complete.yaml b/pkg/libdevfile/testdata/child-devfile-complete.yaml deleted file mode 100644 index 54f9c873278..00000000000 --- a/pkg/libdevfile/testdata/child-devfile-complete.yaml +++ /dev/null @@ -1,34 +0,0 @@ -commands: -- exec: - commandLine: GOCACHE=${PROJECT_SOURCE}/.cache go build main.go - component: runtime - group: - isDefault: true - kind: build - workingDir: ${PROJECT_SOURCE} - id: build -- exec: - commandLine: ./main - component: runtime - group: - isDefault: true - kind: run - workingDir: ${PROJECT_SOURCE} - id: run -components: -- container: - endpoints: - - name: http - targetPort: 8080 - image: quay.io/devfile/golang:latest - memoryLimit: 1024Mi - mountSources: true - name: runtime -- kubernetes: - uri: "manifest.yaml" - name: kube-cmp -metadata: - name: my-go-app -schemaVersion: 2.1.0 -parent: - uri: parent/parent-devfile-empty.yaml diff --git a/pkg/libdevfile/testdata/child-devfile-components-only.yaml b/pkg/libdevfile/testdata/child-devfile-components-only.yaml deleted file mode 100644 index fcc0bcd2231..00000000000 --- a/pkg/libdevfile/testdata/child-devfile-components-only.yaml +++ /dev/null @@ -1,17 +0,0 @@ -schemaVersion: 2.1.0 -metadata: - name: child -parent: - uri: "parent/parent-devfile-commands-only.yaml" -components: -- container: - endpoints: - - name: http - targetPort: 8080 - image: quay.io/devfile/golang:latest - memoryLimit: 1024Mi - mountSources: true - name: runtime -- kubernetes: - uri: "manifest.yaml" - name: kube-cmp diff --git a/pkg/libdevfile/testdata/child-devfile.yaml b/pkg/libdevfile/testdata/child-devfile.yaml deleted file mode 100644 index 30d8df54325..00000000000 --- a/pkg/libdevfile/testdata/child-devfile.yaml +++ /dev/null @@ -1,5 +0,0 @@ -schemaVersion: 2.1.0 -metadata: - name: child -parent: - uri: "parent/parent-devfile.yaml" \ No newline at end of file diff --git a/pkg/libdevfile/testdata/parent/parent-devfile-commands-only.yaml b/pkg/libdevfile/testdata/parent/parent-devfile-commands-only.yaml deleted file mode 100644 index 206682178dc..00000000000 --- a/pkg/libdevfile/testdata/parent/parent-devfile-commands-only.yaml +++ /dev/null @@ -1,20 +0,0 @@ -commands: -- exec: - commandLine: GOCACHE=${PROJECT_SOURCE}/.cache go build main.go - component: runtime - group: - isDefault: true - kind: build - workingDir: ${PROJECT_SOURCE} - id: build -- exec: - commandLine: ./main - component: runtime - group: - isDefault: true - kind: run - workingDir: ${PROJECT_SOURCE} - id: run -schemaVersion: 2.1.0 -metadata: - name: parent diff --git a/pkg/libdevfile/testdata/parent/parent-devfile-components-only.yaml b/pkg/libdevfile/testdata/parent/parent-devfile-components-only.yaml deleted file mode 100644 index 74d64ff35bf..00000000000 --- a/pkg/libdevfile/testdata/parent/parent-devfile-components-only.yaml +++ /dev/null @@ -1,15 +0,0 @@ -components: -- container: - endpoints: - - name: http - targetPort: 8080 - image: quay.io/devfile/golang:latest - memoryLimit: 1024Mi - mountSources: true - name: runtime -- kubernetes: - uri: "manifest.yaml" - name: kube-cmp -metadata: - name: my-go-app -schemaVersion: 2.1.0 diff --git a/pkg/libdevfile/testdata/parent/parent-devfile-empty.yaml b/pkg/libdevfile/testdata/parent/parent-devfile-empty.yaml deleted file mode 100644 index a3e59f1af10..00000000000 --- a/pkg/libdevfile/testdata/parent/parent-devfile-empty.yaml +++ /dev/null @@ -1,3 +0,0 @@ -metadata: - name: my-go-app -schemaVersion: 2.1.0 diff --git a/pkg/libdevfile/testdata/parent/parent-devfile.yaml b/pkg/libdevfile/testdata/parent/parent-devfile.yaml deleted file mode 100644 index 08824612b9b..00000000000 --- a/pkg/libdevfile/testdata/parent/parent-devfile.yaml +++ /dev/null @@ -1,32 +0,0 @@ -commands: -- exec: - commandLine: GOCACHE=${PROJECT_SOURCE}/.cache go build main.go - component: runtime - group: - isDefault: true - kind: build - workingDir: ${PROJECT_SOURCE} - id: build -- exec: - commandLine: ./main - component: runtime - group: - isDefault: true - kind: run - workingDir: ${PROJECT_SOURCE} - id: run -components: -- container: - endpoints: - - name: http - targetPort: 8080 - image: quay.io/devfile/golang:latest - memoryLimit: 1024Mi - mountSources: true - name: runtime -- kubernetes: - uri: "manifest.yaml" - name: kube-cmp -metadata: - name: my-go-app -schemaVersion: 2.1.0 diff --git a/pkg/libdevfile/uris.go b/pkg/libdevfile/uris.go deleted file mode 100644 index 0c4d1366943..00000000000 --- a/pkg/libdevfile/uris.go +++ /dev/null @@ -1,123 +0,0 @@ -package libdevfile - -import ( - "errors" - "net/url" - "sort" - "strings" - - "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2" - "github.com/devfile/api/v2/pkg/attributes" - "github.com/devfile/api/v2/pkg/validation" - "github.com/devfile/library/pkg/devfile/parser" - "github.com/devfile/library/pkg/devfile/parser/data/v2/common" -) - -const _importSourceAttributeUriPrefix = "uri: " - -// GetReferencedLocalFiles returns the local files referenced by the Devfile. This includes: -// - the non-inlined Kubernetes and Openshift components -// - the Dockerfiles of Image components -// - the parent devfile -// - resursively, the local files referenced by the parent Devfile -// The passed Devfile must be flattened -func GetReferencedLocalFiles(devfileObj parser.DevfileObj) (result []string, err error) { - - setResult := map[string]struct{}{} - - parent := devfileObj.Data.GetParent() - if parent != nil { - return nil, errors.New("devfile must be flattened") - } - - components, err := devfileObj.Data.GetComponents(common.DevfileOptions{}) - if err != nil { - return nil, err - } - - for _, component := range components { - var componentType v1alpha2.ComponentType - componentType, err = common.GetComponentType(component) - if err != nil { - return nil, err - } - - switch componentType { - case v1alpha2.KubernetesComponentType: - setResult, err = appendUriIfFile(setResult, component.Kubernetes.Uri) - if err != nil { - return nil, err - } - - case v1alpha2.OpenshiftComponentType: - setResult, err = appendUriIfFile(setResult, component.Openshift.Uri) - if err != nil { - return nil, err - } - - case v1alpha2.ImageComponentType: - if component.Image.Dockerfile != nil { - setResult, err = appendUriIfFile(setResult, component.Image.Dockerfile.Uri) - if err != nil { - return nil, err - } - } - } - - setResult, err = getFromAttributes(setResult, component.Attributes) - if err != nil { - return nil, err - } - } - - commands, err := devfileObj.Data.GetCommands(common.DevfileOptions{}) - if err != nil { - return nil, err - } - for _, command := range commands { - setResult, err = getFromAttributes(setResult, command.Attributes) - if err != nil { - return nil, err - } - } - - result = make([]string, 0, len(setResult)) - for k := range setResult { - result = append(result, k) - } - sort.Strings(result) - return result, nil -} - -// appendUriIfFile appends uri to the result if the uri is a local path -func appendUriIfFile(result map[string]struct{}, uri string) (map[string]struct{}, error) { - if uri != "" { - u, err := url.Parse(uri) - if err != nil { - return nil, err - } - if u.Scheme == "" { - result[uri] = struct{}{} - } - } - return result, nil -} - -// getFromAttributes extracts paths from attributes entries with key "api.devfile.io/imported-from" -// containing a uri reference as a local path -func getFromAttributes(result map[string]struct{}, attributes attributes.Attributes) (map[string]struct{}, error) { - if val, ok := attributes[validation.ImportSourceAttribute]; ok { - strVal := string(val.Raw) - strVal = strings.Trim(strVal, `"`) - if strings.HasPrefix(strVal, _importSourceAttributeUriPrefix) { - parentUri := strings.TrimLeft(strVal, _importSourceAttributeUriPrefix) - var err error - result, err = appendUriIfFile(result, parentUri) - if err != nil { - return nil, err - } - } - } - - return result, nil -} diff --git a/pkg/libdevfile/uris_test.go b/pkg/libdevfile/uris_test.go deleted file mode 100644 index ac90b3e37a5..00000000000 --- a/pkg/libdevfile/uris_test.go +++ /dev/null @@ -1,527 +0,0 @@ -package libdevfile - -import ( - "reflect" - "testing" - - "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2" - "github.com/devfile/api/v2/pkg/attributes" - "github.com/devfile/api/v2/pkg/validation" - "github.com/devfile/library/pkg/devfile" - "github.com/devfile/library/pkg/devfile/parser" - context "github.com/devfile/library/pkg/devfile/parser/context" - "github.com/devfile/library/pkg/devfile/parser/data" - "github.com/devfile/library/pkg/testingutil/filesystem" - - "github.com/redhat-developer/odo/pkg/libdevfile/generator" - - apiext "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" - "k8s.io/utils/pointer" -) - -func TestGetReferencedLocalFiles(t *testing.T) { - - imageComponentNoDockerfile := generator.GetImageComponent(generator.ImageComponentParams{ - Name: "image-component", - Image: v1alpha2.Image{ - ImageName: "an-image-name", - }, - }) - imageComponentWithHTTPDockerfile := generator.GetImageComponent(generator.ImageComponentParams{ - Name: "image-component", - Image: v1alpha2.Image{ - ImageName: "an-image-name", - ImageUnion: v1alpha2.ImageUnion{ - Dockerfile: &v1alpha2.DockerfileImage{ - DockerfileSrc: v1alpha2.DockerfileSrc{ - Uri: "http://example.com", - }, - }, - }, - }, - }) - imageComponentWithLocalDockerfile := generator.GetImageComponent(generator.ImageComponentParams{ - Name: "image-component", - Image: v1alpha2.Image{ - ImageName: "an-image-name", - ImageUnion: v1alpha2.ImageUnion{ - Dockerfile: &v1alpha2.DockerfileImage{ - DockerfileSrc: v1alpha2.DockerfileSrc{ - Uri: "path/to/Dockerfile", - }, - }, - }, - }, - }) - - kubeComponentInlined := generator.GetKubernetesComponent(generator.KubernetesComponentParams{ - Name: "kube-component", - Kubernetes: &v1alpha2.KubernetesComponent{ - K8sLikeComponent: v1alpha2.K8sLikeComponent{ - K8sLikeComponentLocation: v1alpha2.K8sLikeComponentLocation{ - Inlined: "", - }, - }, - }, - }) - kubeComponentHTTPUri := generator.GetKubernetesComponent(generator.KubernetesComponentParams{ - Name: "kube-component", - Kubernetes: &v1alpha2.KubernetesComponent{ - K8sLikeComponent: v1alpha2.K8sLikeComponent{ - K8sLikeComponentLocation: v1alpha2.K8sLikeComponentLocation{ - Uri: "http://example.com", - }, - }, - }, - }) - kubeComponentLocalUri := generator.GetKubernetesComponent(generator.KubernetesComponentParams{ - Name: "kube-component", - Kubernetes: &v1alpha2.KubernetesComponent{ - K8sLikeComponent: v1alpha2.K8sLikeComponent{ - K8sLikeComponentLocation: v1alpha2.K8sLikeComponentLocation{ - Uri: "path/to/manifest", - }, - }, - }, - }) - - openshiftComponentInlined := generator.GetOpenshiftComponent(generator.OpenshiftComponentParams{ - Name: "openshift-component", - Openshift: &v1alpha2.OpenshiftComponent{ - K8sLikeComponent: v1alpha2.K8sLikeComponent{ - K8sLikeComponentLocation: v1alpha2.K8sLikeComponentLocation{ - Inlined: "", - }, - }, - }, - }) - openshiftComponentHTTPUri := generator.GetOpenshiftComponent(generator.OpenshiftComponentParams{ - Name: "openshift-component", - Openshift: &v1alpha2.OpenshiftComponent{ - K8sLikeComponent: v1alpha2.K8sLikeComponent{ - K8sLikeComponentLocation: v1alpha2.K8sLikeComponentLocation{ - Uri: "http://example.com", - }, - }, - }, - }) - openshiftComponentLocalUri := generator.GetOpenshiftComponent(generator.OpenshiftComponentParams{ - Name: "openshift-component", - Openshift: &v1alpha2.OpenshiftComponent{ - K8sLikeComponent: v1alpha2.K8sLikeComponent{ - K8sLikeComponentLocation: v1alpha2.K8sLikeComponentLocation{ - Uri: "path/to/manifest", - }, - }, - }, - }) - - type args struct { - devfileObj func(fs filesystem.Filesystem) parser.DevfileObj - } - tests := []struct { - name string - args args - wantResult []string - wantErr bool - }{ - { - name: "image without Dockerfile", - args: args{ - devfileObj: func(fs filesystem.Filesystem) parser.DevfileObj { - dData, _ := data.NewDevfileData(string(data.APISchemaVersion200)) - _ = dData.AddComponents([]v1alpha2.Component{imageComponentNoDockerfile}) - return parser.DevfileObj{ - Data: dData, - } - }, - }, - wantResult: []string{}, - wantErr: false, - }, - { - name: "image with HTTP Dockerfile", - args: args{ - devfileObj: func(fs filesystem.Filesystem) parser.DevfileObj { - dData, _ := data.NewDevfileData(string(data.APISchemaVersion200)) - _ = dData.AddComponents([]v1alpha2.Component{imageComponentWithHTTPDockerfile}) - return parser.DevfileObj{ - Data: dData, - } - }, - }, - wantResult: []string{}, - wantErr: false, - }, - { - name: "image with local Dockerfile", - args: args{ - devfileObj: func(fs filesystem.Filesystem) parser.DevfileObj { - dData, _ := data.NewDevfileData(string(data.APISchemaVersion200)) - _ = dData.AddComponents([]v1alpha2.Component{imageComponentWithLocalDockerfile}) - return parser.DevfileObj{ - Data: dData, - } - }, - }, - wantResult: []string{"path/to/Dockerfile"}, - wantErr: false, - }, - - { - name: "inlined Kubernetes component", - args: args{ - devfileObj: func(fs filesystem.Filesystem) parser.DevfileObj { - dData, _ := data.NewDevfileData(string(data.APISchemaVersion200)) - _ = dData.AddComponents([]v1alpha2.Component{kubeComponentInlined}) - return parser.DevfileObj{ - Data: dData, - } - }, - }, - wantResult: []string{}, - wantErr: false, - }, - { - name: "Kubernetes component with HTTP uri", - args: args{ - devfileObj: func(fs filesystem.Filesystem) parser.DevfileObj { - dData, _ := data.NewDevfileData(string(data.APISchemaVersion200)) - _ = dData.AddComponents([]v1alpha2.Component{kubeComponentHTTPUri}) - return parser.DevfileObj{ - Data: dData, - } - }, - }, - wantResult: []string{}, - wantErr: false, - }, - { - name: "Kubernetes component with local uri", - args: args{ - devfileObj: func(fs filesystem.Filesystem) parser.DevfileObj { - dData, _ := data.NewDevfileData(string(data.APISchemaVersion200)) - _ = dData.AddComponents([]v1alpha2.Component{kubeComponentLocalUri}) - return parser.DevfileObj{ - Data: dData, - } - }, - }, - wantResult: []string{"path/to/manifest"}, - wantErr: false, - }, - - { - name: "inlined Openshift component", - args: args{ - devfileObj: func(fs filesystem.Filesystem) parser.DevfileObj { - dData, _ := data.NewDevfileData(string(data.APISchemaVersion200)) - _ = dData.AddComponents([]v1alpha2.Component{openshiftComponentInlined}) - return parser.DevfileObj{ - Data: dData, - } - }, - }, - wantResult: []string{}, - wantErr: false, - }, - { - name: "Openshift component with HTTP uri", - args: args{ - devfileObj: func(fs filesystem.Filesystem) parser.DevfileObj { - dData, _ := data.NewDevfileData(string(data.APISchemaVersion200)) - _ = dData.AddComponents([]v1alpha2.Component{openshiftComponentHTTPUri}) - return parser.DevfileObj{ - Data: dData, - } - }, - }, - wantResult: []string{}, - wantErr: false, - }, - { - name: "Openshift component with local uri", - args: args{ - devfileObj: func(fs filesystem.Filesystem) parser.DevfileObj { - dData, _ := data.NewDevfileData(string(data.APISchemaVersion200)) - _ = dData.AddComponents([]v1alpha2.Component{openshiftComponentLocalUri}) - return parser.DevfileObj{ - Data: dData, - } - }, - }, - wantResult: []string{"path/to/manifest"}, - wantErr: false, - }, - - { - name: "With parent Devfile, non flattened", - args: args{ - devfileObj: func(fs filesystem.Filesystem) parser.DevfileObj { - parentData, _ := data.NewDevfileData(string(data.APISchemaVersion200)) - parentObj := parser.DevfileObj{ - Data: parentData, - Ctx: context.FakeContext(fs, "/path/to/parent/devfile.yaml"), - } - _ = parentObj.WriteYamlDevfile() - - dData, _ := data.NewDevfileData(string(data.APISchemaVersion200)) - dData.SetParent(&v1alpha2.Parent{ - ImportReference: v1alpha2.ImportReference{ - ImportReferenceUnion: v1alpha2.ImportReferenceUnion{ - Uri: "/path/to/parent/devfile.yaml", - }, - }, - }) - return parser.DevfileObj{ - Data: dData, - } - }, - }, - wantResult: nil, - wantErr: true, - }, - { - name: "With parent Devfile, flattened", - args: args{ - devfileObj: func(fs filesystem.Filesystem) parser.DevfileObj { - obj, _, _ := devfile.ParseDevfileAndValidate(parser.ParserArgs{ - Path: "testdata/child-devfile.yaml", - FlattenedDevfile: pointer.Bool(true), - }) - return obj - }, - }, - wantResult: []string{ - "manifest.yaml", // TODO should be parent/manifest.yaml (see https://github.com/devfile/api/issues/904) - "parent/parent-devfile.yaml", - }, - wantErr: false, - }, - { - name: "With parent Devfile containing only commands, flattened", - args: args{ - devfileObj: func(fs filesystem.Filesystem) parser.DevfileObj { - obj, _, _ := devfile.ParseDevfileAndValidate(parser.ParserArgs{ - Path: "testdata/child-devfile-components-only.yaml", - FlattenedDevfile: pointer.Bool(true), - }) - return obj - }, - }, - wantResult: []string{ - "manifest.yaml", // TODO should be parent/manifest.yaml (see https://github.com/devfile/api/issues/904) - "parent/parent-devfile-commands-only.yaml", - }, - wantErr: false, - }, - { - name: "With parent Devfile containing only components, flattened", - args: args{ - devfileObj: func(fs filesystem.Filesystem) parser.DevfileObj { - obj, _, _ := devfile.ParseDevfileAndValidate(parser.ParserArgs{ - Path: "testdata/child-devfile-commands-only.yaml", - FlattenedDevfile: pointer.Bool(true), - }) - return obj - }, - }, - wantResult: []string{ - "manifest.yaml", // TODO should be parent/manifest.yaml (see https://github.com/devfile/api/issues/904) - "parent/parent-devfile-components-only.yaml", - }, - wantErr: false, - }, - { - name: "With empty parent Devfile, flattened. TODO find a way to detect the parent", - args: args{ - devfileObj: func(fs filesystem.Filesystem) parser.DevfileObj { - obj, _, _ := devfile.ParseDevfileAndValidate(parser.ParserArgs{ - Path: "testdata/child-devfile-complete.yaml", - FlattenedDevfile: pointer.Bool(true), - }) - return obj - }, - }, - wantResult: []string{ - "manifest.yaml", // TODO should be parent/manifest.yaml (see https://github.com/devfile/api/issues/904) - }, - wantErr: false, - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - fs := filesystem.NewFakeFs() - gotResult, err := GetReferencedLocalFiles(tt.args.devfileObj(fs)) - if (err != nil) != tt.wantErr { - t.Errorf("GetReferencedLocalFiles() error = %v, wantErr %v", err, tt.wantErr) - return - } - if !reflect.DeepEqual(gotResult, tt.wantResult) { - t.Errorf("GetReferencedLocalFiles() = %v, want %v", gotResult, tt.wantResult) - } - }) - } -} - -func Test_appendUriIfFile(t *testing.T) { - type args struct { - result map[string]struct{} - uri string - } - tests := []struct { - name string - args args - want map[string]struct{} - wantErr bool - }{ - { - name: "empty uri", - args: args{ - result: map[string]struct{}{}, - uri: "", - }, - want: map[string]struct{}{}, - wantErr: false, - }, - { - name: "http uri", - args: args{ - result: map[string]struct{}{}, - uri: "http://example.com", - }, - want: map[string]struct{}{}, - wantErr: false, - }, - { - name: "file uri", - args: args{ - result: map[string]struct{}{}, - uri: "path/to/file", - }, - want: map[string]struct{}{ - "path/to/file": {}, - }, - wantErr: false, - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - got, err := appendUriIfFile(tt.args.result, tt.args.uri) - if (err != nil) != tt.wantErr { - t.Errorf("appendUriIfFile() error = %v, wantErr %v", err, tt.wantErr) - return - } - if !reflect.DeepEqual(got, tt.want) { - t.Errorf("appendUriIfFile() = %v, want %v", got, tt.want) - } - }) - } -} - -/* -func Test_getFromAttributes(t *testing.T) { - type args struct { - result map[string]struct{} - attributes attributes.Attributes - } - tests := []struct { - name string - args args - }{ - { - name: "todo", - args: args{ - result: map[string]struct{}{}, - attributes: attributes.Attributes{ - validation.ImportSourceAttribute: apiext.JSON{ - Raw: []byte("uri: path/to/devfile.yaml"), - }, - }, - }, - }, - // TODO: Add test cases. - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - getFromAttributes(tt.args.result, tt.args.attributes) - }) - } -} -*/ - -func Test_getFromAttributes(t *testing.T) { - type args struct { - result map[string]struct{} - attributes attributes.Attributes - } - tests := []struct { - name string - args args - want map[string]struct{} - wantErr bool - }{ - { - name: "uri is local file", - args: args{ - result: map[string]struct{}{}, - attributes: attributes.Attributes{ - validation.ImportSourceAttribute: apiext.JSON{ - Raw: []byte("uri: path/to/devfile.yaml"), - }, - }, - }, - want: map[string]struct{}{ - "path/to/devfile.yaml": {}, - }, - }, - { - name: "uri is http file", - args: args{ - result: map[string]struct{}{}, - attributes: attributes.Attributes{ - validation.ImportSourceAttribute: apiext.JSON{ - Raw: []byte("uri: http://example.com/devfile.yaml"), - }, - }, - }, - want: map[string]struct{}{}, - }, - { - name: "id and registryURL", - args: args{ - result: map[string]struct{}{}, - attributes: attributes.Attributes{ - validation.ImportSourceAttribute: apiext.JSON{ - Raw: []byte("id: my-id, registryURL: http://myregistry.com"), - }, - }, - }, - want: map[string]struct{}{}, - }, - { - name: "name and namespace", - args: args{ - result: map[string]struct{}{}, - attributes: attributes.Attributes{ - validation.ImportSourceAttribute: apiext.JSON{ - Raw: []byte("name: aname, namespace: anamespace"), - }, - }, - }, - want: map[string]struct{}{}, - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - got, err := getFromAttributes(tt.args.result, tt.args.attributes) - if (err != nil) != tt.wantErr { - t.Errorf("getFromAttributes() error = %v, wantErr %v", err, tt.wantErr) - return - } - if !reflect.DeepEqual(got, tt.want) { - t.Errorf("getFromAttributes() = %v, want %v", got, tt.want) - } - }) - } -} diff --git a/pkg/watch/watch.go b/pkg/watch/watch.go index 43105260a3b..a0ccf8401ff 100644 --- a/pkg/watch/watch.go +++ b/pkg/watch/watch.go @@ -16,7 +16,6 @@ import ( "github.com/redhat-developer/odo/pkg/devfile/adapters" "github.com/redhat-developer/odo/pkg/kclient" "github.com/redhat-developer/odo/pkg/labels" - "github.com/redhat-developer/odo/pkg/libdevfile" "github.com/redhat-developer/odo/pkg/log" "github.com/redhat-developer/odo/pkg/state" @@ -221,6 +220,7 @@ func (o *WatchClient) WatchAndPush(out io.Writer, parameters WatchParameters, ct var sourcesWatcher *fsnotify.Watcher var err error if parameters.WatchFiles { + // TODO(feloy) ignore files included by Devfile? sourcesWatcher, err = getFullSourcesWatcher(parameters.Path, parameters.FileIgnores) if err != nil { return err @@ -239,23 +239,16 @@ func (o *WatchClient) WatchAndPush(out io.Writer, parameters WatchParameters, ct return fmt.Errorf("error watching deployment: %v", err) } + // TODO(feloy) watch files included by Devfile devfileWatcher, err := fsnotify.NewWatcher() if err != nil { return err } if parameters.WatchFiles { - var devfileFiles []string - devfileFiles, err = libdevfile.GetReferencedLocalFiles(parameters.InitialDevfileObj) + err = devfileWatcher.Add(parameters.DevfilePath) if err != nil { return err } - devfileFiles = append(devfileFiles, parameters.DevfilePath) - for _, f := range devfileFiles { - err = devfileWatcher.Add(f) - if err != nil { - klog.V(4).Infof("error adding watcher for path %s: %v", f, err) - } - } } podWatcher, err := o.kubeClient.PodWatcher(ctx, selector) diff --git a/tests/examples/source/devfiles/nodejs/devfile-child.yaml b/tests/examples/source/devfiles/nodejs/devfile-child.yaml deleted file mode 100644 index 0c6562533b1..00000000000 --- a/tests/examples/source/devfiles/nodejs/devfile-child.yaml +++ /dev/null @@ -1,5 +0,0 @@ -schemaVersion: 2.1.0 -metadata: - name: child -parent: - uri: devfile-parent.yaml diff --git a/tests/examples/source/devfiles/nodejs/devfile-parent.yaml b/tests/examples/source/devfiles/nodejs/devfile-parent.yaml deleted file mode 100644 index cd58a029ed3..00000000000 --- a/tests/examples/source/devfiles/nodejs/devfile-parent.yaml +++ /dev/null @@ -1,61 +0,0 @@ -commands: -- exec: - commandLine: npm install - component: runtime - group: - isDefault: true - kind: build - workingDir: /project - id: install -- exec: - commandLine: npm start - component: runtime - group: - isDefault: true - kind: run - workingDir: /project - id: run -- exec: - commandLine: npm run debug - component: runtime - group: - isDefault: true - kind: debug - workingDir: /project - id: debug -- exec: - commandLine: npm test - component: runtime - group: - isDefault: true - kind: test - workingDir: /project - id: test -components: -- container: - endpoints: - - name: http-3000 - targetPort: 3000 - image: registry.access.redhat.com/ubi8/nodejs-14:latest - memoryLimit: 1024Mi - mountSources: true - sourceMapping: /project - name: runtime -metadata: - description: Stack with Node.js 14 - displayName: Node.js Runtime - icon: https://nodejs.org/static/images/logos/nodejs-new-pantone-black.svg - language: javascript - name: nodejs-prj1-api-abhz - projectType: nodejs - tags: - - NodeJS - - Express - - ubi8 - version: 1.0.1 -schemaVersion: 2.0.0 -starterProjects: -- git: - remotes: - origin: https://github.com/odo-devfiles/nodejs-ex.git - name: nodejs-starter diff --git a/tests/helper/helper_filesystem.go b/tests/helper/helper_filesystem.go index f5772c4ed74..09fb34df2ac 100644 --- a/tests/helper/helper_filesystem.go +++ b/tests/helper/helper_filesystem.go @@ -273,15 +273,3 @@ func CreateSimpleFile(context, filePrefix, fileExtension string) (string, string return FilePath, string(content) } - -func AppendToFile(filepath string, s string) error { - f, err := os.OpenFile(filepath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0600) - if err != nil { - return err - } - defer f.Close() // #nosec G307 - if _, err := f.WriteString(s); err != nil { - return err - } - return nil -} diff --git a/tests/integration/cmd_dev_test.go b/tests/integration/cmd_dev_test.go index 52b71c1e78d..87002a9f8f4 100644 --- a/tests/integration/cmd_dev_test.go +++ b/tests/integration/cmd_dev_test.go @@ -2215,40 +2215,4 @@ CMD ["npm", "start"] }) }) }) - - When("a devfile with a local parent is used for odo dev and the parent is not synced", func() { - var devSession helper.DevSession - BeforeEach(func() { - helper.CopyExampleDevFile(filepath.Join("source", "devfiles", "nodejs", "devfile-child.yaml"), filepath.Join(commonVar.Context, "devfile.yaml")) - helper.CopyExampleDevFile(filepath.Join("source", "devfiles", "nodejs", "devfile-parent.yaml"), filepath.Join(commonVar.Context, "devfile-parent.yaml")) - helper.CopyExample(filepath.Join("source", "nodejs"), commonVar.Context) - var err error - devSession, _, _, _, err = helper.StartDevMode(nil) - Expect(err).ToNot(HaveOccurred()) - - gitignorePath := filepath.Join(commonVar.Context, ".gitignore") - err = helper.AppendToFile(gitignorePath, "\n/devfile-parent.yaml\n") - Expect(err).ToNot(HaveOccurred()) - }) - - AfterEach(func() { - // We stop the process so the process does not remain after the end of the tests - devSession.Kill() - devSession.WaitEnd() - }) - - When("updating the parent", func() { - BeforeEach(func() { - helper.ReplaceString("devfile-parent.yaml", "1024Mi", "1023Mi") - }) - - It("should update the component", func() { - Eventually(func() string { - stdout, _, _, err := devSession.GetInfo() - Expect(err).ToNot(HaveOccurred()) - return string(stdout) - }, 180, 10).Should(ContainSubstring("Updating Component")) - }) - }) - }) })