Skip to content

Commit de570f0

Browse files
authored
Version checks for boolean properties (#126)
* Version checks for boolean properties * Unit Tests * Review feedback, bug fix and additional error handling * refactor helper functions to fix import cycle
1 parent 5a5cbcc commit de570f0

File tree

8 files changed

+664
-18
lines changed

8 files changed

+664
-18
lines changed

pkg/devfile/parser/parse.go

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,16 @@ func ParseDevfile(args ParserArgs) (d DevfileObj, err error) {
112112
}
113113

114114
d, err = populateAndParseDevfile(d, &resolutionContextTree{}, tool, flattenedDevfile)
115+
if err != nil {
116+
return d, errors.Wrap(err, "failed to populateAndParseDevfile")
117+
}
115118

116119
//set defaults only if we are flattening parent and parsing succeeded
117120
if flattenedDevfile && err == nil {
118-
setDefaults(d)
121+
err = setDefaults(d)
122+
if err != nil {
123+
return d, errors.Wrap(err, "failed to setDefaults")
124+
}
119125
}
120126

121127
return d, err
@@ -478,6 +484,12 @@ func convertDevWorskapceTemplateToDevObj(dwTemplate v1.DevWorkspaceTemplate) (d
478484

479485
//setDefaults sets the default values for nil boolean properties after the merging of devWorkspaceTemplateSpec is complete
480486
func setDefaults(d DevfileObj) (err error) {
487+
488+
var devfileVersion string
489+
if devfileVersion = d.Ctx.GetApiVersion(); devfileVersion == "" {
490+
devfileVersion = d.Data.GetSchemaVersion()
491+
}
492+
481493
commands, err := d.Data.GetCommands(common.DevfileOptions{})
482494

483495
if err != nil {
@@ -530,8 +542,8 @@ func setDefaults(d DevfileObj) (err error) {
530542
val := container.GetDedicatedPod()
531543
container.DedicatedPod = &val
532544

533-
val = container.GetMountSources()
534-
container.MountSources = &val
545+
msVal := container.GetMountSources()
546+
container.MountSources = &msVal
535547

536548
endpoints = container.Endpoints
537549

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

543555
endpoints = component.Openshift.Endpoints
544556

545-
} else if component.Volume != nil {
557+
} else if component.Volume != nil && devfileVersion != string(data.APISchemaVersion200) {
546558
volume := component.Volume
547559
val := volume.GetEphemeral()
548560
volume.Ephemeral = &val
549561

550-
} else if component.Image != nil {
562+
} 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
551563
dockerImage := component.Image.Dockerfile
552564
if dockerImage != nil {
553565
val := dockerImage.GetRootRequired()

0 commit comments

Comments
 (0)