Skip to content

Devfile Parser should not set default values when flattening is true #1067

Closed
@rm3l

Description

@rm3l

Which area this feature is related to?

/kind bug

Which area this bug is related to?

/area library

What versions of software are you using?

Go project

Operating System and version:
Fedora 37

Go Pkg Version:
github.com/devfile/library/v2@f87c6926afe80be8abb9fbb83ebfa751f6f93430

Bug Summary

Describe the bug:

While working on adding support for autoBuild and deployByDefault in odo (redhat-developer/odo#5694), I needed to handle the case where those fields are not explicitly set in the Devfile and the components are not referenced by any apply commands (see #852 (comment)).
But currently, the parser automatically sets unset fields to their default values (false here) when called with the option to flatten the Devfile:

https://github.com/devfile/library/blob/bd4a12f272573de1ab254f3e138a9b55904af620/pkg/devfile/parser/parse.go#L147-L153

On the other hand, parsing without flattening makes our tests using child and parent Devfiles fail (mainly because the child Devfile was missing other definitions like commands or components - see the logs here).

To Reproduce:
See this sample project that highlights the issue: https://github.com/rm3l/bug-devfile-parser-fields-not-set

Expected behavior

As discussed during the community call (on March 20, 2023), flattening should not dictate whether default values should be set or not. It should be up to the clients of the library to decide how to handle unset fields. This is especially necessary since fields like autoBuild and deployByDefault have 3 states (true, false, and nil) with different behaviors that need to be implemented client-side.

Any logs, error output, screenshots etc? Provide the devfile that sees this bug, if applicable

https://github.com/rm3l/bug-devfile-parser-fields-not-set/actions

Additional context

Any workaround?

Suggestion on how to fix the bug

Metadata

Metadata

Assignees

Labels

area/libraryCommon devfile library for interacting with devfileskind/bugSomething isn't workingseverity/blockerIssues that prevent developers from working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions