Skip to content

Commit

Permalink
Version checks for boolean properties (#126)
Browse files Browse the repository at this point in the history
* Version checks for boolean properties

* Unit Tests

* Review feedback, bug fix and additional error handling

* refactor helper functions to fix import cycle
  • Loading branch information
kim-tsao committed Dec 7, 2021
1 parent 5a5cbcc commit de570f0
Show file tree
Hide file tree
Showing 8 changed files with 664 additions and 18 deletions.
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

0 comments on commit de570f0

Please sign in to comment.