Skip to content
This repository was archived by the owner on Apr 1, 2026. It is now read-only.

Commit 0f2103e

Browse files
authored
Recognize devfile.yml and .devfile.yml as Devfiles (#7130)
1 parent 15f663f commit 0f2103e

70 files changed

Lines changed: 1153 additions & 419 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ require (
99
github.com/Xuanwo/go-locale v1.1.0
1010
github.com/blang/semver v3.5.1+incompatible
1111
github.com/devfile/alizer v1.2.1
12-
github.com/devfile/api/v2 v2.2.1-alpha.0.20230413012049-a6c32fca0dbd
13-
github.com/devfile/library/v2 v2.2.1-0.20230524160049-04a8b3fc66c0
12+
github.com/devfile/api/v2 v2.2.1
13+
github.com/devfile/library/v2 v2.2.2-0.20231102090733-57a7da8b8392
1414
github.com/devfile/registry-support/index/generator v0.0.0-20230322155332-33914affc83b
1515
github.com/devfile/registry-support/registry-library v0.0.0-20221201200738-19293ac0b8ab
1616
github.com/fatih/color v1.15.0

go.sum

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/apiserver-impl/devstate/content.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func (o *DevfileState) GetContent() (DevfileContent, error) {
2424
if err != nil {
2525
return DevfileContent{}, errors.New("error writing file")
2626
}
27-
result, err := o.FS.ReadFile("/devfile.yaml")
27+
result, err := o.FS.ReadFile(o.Devfile.Ctx.GetAbsPath())
2828
if err != nil {
2929
return DevfileContent{}, errors.New("error reading file")
3030
}

pkg/apiserver-impl/devstate/state.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/devfile/library/v2/pkg/devfile/parser"
1010
context "github.com/devfile/library/v2/pkg/devfile/parser/context"
1111
"github.com/devfile/library/v2/pkg/testingutil/filesystem"
12+
1213
. "github.com/redhat-developer/odo/pkg/apiserver-gen/go"
1314

1415
"k8s.io/utils/pointer"
@@ -42,7 +43,7 @@ func (o *DevfileState) SetDevfileContent(content string) (DevfileContent, error)
4243
return DevfileContent{}, fmt.Errorf("error parsing devfile YAML: %w", err)
4344
}
4445
o.Devfile = devfile
45-
o.Devfile.Ctx = context.FakeContext(o.FS, "/devfile.yaml")
46+
o.Devfile.Ctx = context.FakeContext(o.FS, o.Devfile.Ctx.GetAbsPath())
4647
return o.GetContent()
4748
}
4849

pkg/devfile/location/location.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import (
88
"github.com/redhat-developer/odo/pkg/util"
99
)
1010

11-
// possibleDevfileNames contains possivle devfile name that should be checked in the context dir.
12-
var possibleDevfileNames = [...]string{"devfile.yaml", ".devfile.yaml"}
11+
// possibleDevfileNames contains possible devfile name that should be checked in the context dir.
12+
var possibleDevfileNames = [...]string{"devfile.yaml", ".devfile.yaml", "devfile.yml", ".devfile.yml"}
1313

1414
// DevfileFilenamesProvider checks if the context dir contains devfile with possible names from possibleDevfileNames variable,
1515
// else it returns "devfile.yaml" as default value.

tests/integration/cmd_describe_component_test.go

Lines changed: 42 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -230,32 +230,57 @@ var _ = Describe("odo describe component command tests", func() {
230230
})
231231
})
232232

233-
When("renaming to hide devfile.yaml file", Label(label), func() {
233+
for _, devfileName := range []string{".devfile.yaml", "devfile.yml", ".devfile.yml"} {
234+
devfileName := devfileName
235+
When(fmt.Sprintf("renaming devfile.yaml into a recognized file name: %s", devfileName), Label(label), func() {
236+
BeforeEach(func() {
237+
err := os.Rename("devfile.yaml", devfileName)
238+
Expect(err).NotTo(HaveOccurred())
239+
})
240+
241+
It("should describe the component in the current directory using the acceptable devfile filename", func() {
242+
By("running with json output", func() {
243+
res := helper.Cmd("odo", "describe", "component", "-o", "json").ShouldPass()
244+
stdout, stderr := res.Out(), res.Err()
245+
Expect(helper.IsJSON(stdout)).To(BeTrue())
246+
Expect(stderr).To(BeEmpty())
247+
checkDevfileJSONDescription(stdout, devfileName)
248+
helper.JsonPathContentIs(stdout, "runningIn", "")
249+
helper.JsonPathContentIs(stdout, "devForwardedPorts", "")
250+
helper.JsonPathDoesNotExist(stdout, "runningOn") // Deprecated
251+
helper.JsonPathDoesNotExist(stdout, "platform")
252+
})
253+
254+
By("running with default output", func() {
255+
res := helper.Cmd("odo", "describe", "component").ShouldPass()
256+
stdout := res.Out()
257+
checkDevfileDescription(stdout, false)
258+
Expect(stdout).To(ContainSubstring("Running in: None"))
259+
Expect(stdout).ToNot(ContainSubstring("Forwarded ports"))
260+
Expect(stdout).ToNot(ContainSubstring("Running on:"))
261+
})
262+
})
263+
})
264+
}
265+
266+
When("renaming devfile.yaml into a non-recognized file name", Label(label), func() {
234267
BeforeEach(func() {
235-
err := os.Rename("devfile.yaml", ".devfile.yaml")
268+
err := os.Rename("devfile.yaml", "some-random-file-as-devfile")
236269
Expect(err).NotTo(HaveOccurred())
237270
})
238271

239-
It("should describe the component in the current directory using the hidden devfile", func() {
272+
It("should not describe the component in the current directory using the acceptable devfile filename", func() {
240273
By("running with json output", func() {
241-
res := helper.Cmd("odo", "describe", "component", "-o", "json").ShouldPass()
274+
res := helper.Cmd("odo", "describe", "component", "-o", "json").ShouldFail()
242275
stdout, stderr := res.Out(), res.Err()
243-
Expect(helper.IsJSON(stdout)).To(BeTrue())
244-
Expect(stderr).To(BeEmpty())
245-
checkDevfileJSONDescription(stdout, ".devfile.yaml")
246-
helper.JsonPathContentIs(stdout, "runningIn", "")
247-
helper.JsonPathContentIs(stdout, "devForwardedPorts", "")
248-
helper.JsonPathDoesNotExist(stdout, "runningOn") // Deprecated
249-
helper.JsonPathDoesNotExist(stdout, "platform")
276+
Expect(helper.IsJSON(stderr)).To(BeTrue())
277+
Expect(stdout).To(BeEmpty())
278+
helper.JsonPathContentContain(stderr, "message", "The current directory does not represent an odo component")
250279
})
251280

252281
By("running with default output", func() {
253-
res := helper.Cmd("odo", "describe", "component").ShouldPass()
254-
stdout := res.Out()
255-
checkDevfileDescription(stdout, false)
256-
Expect(stdout).To(ContainSubstring("Running in: None"))
257-
Expect(stdout).ToNot(ContainSubstring("Forwarded ports"))
258-
Expect(stdout).ToNot(ContainSubstring("Running on:"))
282+
_, stderr := helper.Cmd("odo", "describe", "component").ShouldFail().OutAndErr()
283+
Expect(stderr).Should(ContainSubstring("The current directory does not represent an odo component"))
259284
})
260285
})
261286
})

tests/integration/cmd_devfile_init_test.go

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ var _ = Describe("odo devfile init command tests", func() {
4343
label := label
4444
var _ = Context("label "+label, Label(label), func() {
4545

46-
It("should fail", func() {
46+
It("odo init should fail", func() {
4747
By("running odo init with incomplete flags", func() {
4848
helper.Cmd("odo", "init", "--name", "aname").ShouldFail()
4949
})
@@ -76,25 +76,19 @@ var _ = Describe("odo devfile init command tests", func() {
7676
By("using an invalid devfile name", func() {
7777
helper.Cmd("odo", "init", "--name", "aname", "--devfile", "invalid").ShouldFail()
7878
})
79-
By("running odo init in a directory containing a devfile.yaml", func() {
80-
helper.CopyExampleDevFile(
81-
filepath.Join("source", "devfiles", "nodejs", "devfile-registry.yaml"),
82-
filepath.Join(commonVar.Context, "devfile.yaml"),
83-
"")
84-
defer os.Remove(filepath.Join(commonVar.Context, "devfile.yaml"))
85-
err := helper.Cmd("odo", "init").ShouldFail().Err()
86-
Expect(err).To(ContainSubstring("a devfile already exists in the current directory"))
87-
})
88-
89-
By("running odo init in a directory containing a .devfile.yaml", func() {
90-
helper.CopyExampleDevFile(
91-
filepath.Join("source", "devfiles", "nodejs", "devfile-registry.yaml"),
92-
filepath.Join(commonVar.Context, ".devfile.yaml"),
93-
"")
94-
defer helper.DeleteFile(filepath.Join(commonVar.Context, ".devfile.yaml"))
95-
err := helper.Cmd("odo", "init").ShouldFail().Err()
96-
Expect(err).To(ContainSubstring("a devfile already exists in the current directory"))
97-
})
79+
80+
for _, devfileName := range []string{"devfile.yaml", ".devfile.yaml", "devfile.yml", ".devfile.yml"} {
81+
devfileName := devfileName
82+
By("running odo init in a directory containing a "+devfileName, func() {
83+
helper.CopyExampleDevFile(
84+
filepath.Join("source", "devfiles", "nodejs", "devfile-registry.yaml"),
85+
filepath.Join(commonVar.Context, devfileName),
86+
"")
87+
defer os.Remove(filepath.Join(commonVar.Context, devfileName))
88+
err := helper.Cmd("odo", "init").ShouldFail().Err()
89+
Expect(err).To(ContainSubstring("a devfile already exists in the current directory"))
90+
})
91+
}
9892

9993
By("running odo init with wrong local file path given to --devfile-path", func() {
10094
err := helper.Cmd("odo", "init", "--name", "aname", "--devfile-path", "/some/path/devfile.yaml").ShouldFail().Err()

vendor/github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2/commands.go

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2/component_container.go

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2/component_contribution.go

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)