Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version checks for boolean properties #126

Merged
merged 4 commits into from
Dec 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions pkg/devfile/parser/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,16 @@ func ParseDevfile(args ParserArgs) (d DevfileObj, err error) {
}

d, err = populateAndParseDevfile(d, &resolutionContextTree{}, tool, flattenedDevfile)
if err != nil {
return d, errors.Wrap(err, "failed to populateAndParseDevfile")
}

//set defaults only if we are flattening parent and parsing succeeded
if flattenedDevfile && err == nil {
setDefaults(d)
err = setDefaults(d)
if err != nil {
return d, errors.Wrap(err, "failed to setDefaults")
}
}

return d, err
Expand Down Expand Up @@ -478,6 +484,12 @@ func convertDevWorskapceTemplateToDevObj(dwTemplate v1.DevWorkspaceTemplate) (d

//setDefaults sets the default values for nil boolean properties after the merging of devWorkspaceTemplateSpec is complete
func setDefaults(d DevfileObj) (err error) {

var devfileVersion string
if devfileVersion = d.Ctx.GetApiVersion(); devfileVersion == "" {
devfileVersion = d.Data.GetSchemaVersion()
}

commands, err := d.Data.GetCommands(common.DevfileOptions{})

if err != nil {
Expand Down Expand Up @@ -530,8 +542,8 @@ func setDefaults(d DevfileObj) (err error) {
val := container.GetDedicatedPod()
container.DedicatedPod = &val

val = container.GetMountSources()
container.MountSources = &val
msVal := container.GetMountSources()
container.MountSources = &msVal

endpoints = container.Endpoints

Expand All @@ -542,12 +554,12 @@ func setDefaults(d DevfileObj) (err error) {

endpoints = component.Openshift.Endpoints

} else if component.Volume != nil {
} else if component.Volume != nil && devfileVersion != string(data.APISchemaVersion200) {
volume := component.Volume
val := volume.GetEphemeral()
volume.Ephemeral = &val

} else if component.Image != nil {
} else if component.Image != nil { //we don't need to do a schema version check since Image in v2.2.0. If used in older specs, a parser error would occur
dockerImage := component.Image.Dockerfile
if dockerImage != nil {
val := dockerImage.GetRootRequired()
Expand Down
Loading