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 1 commit
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
5 changes: 3 additions & 2 deletions pkg/devfile/parser/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,7 @@ 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) {
schemaVersion := d.Data.GetSchemaVersion()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DevfileObj.Ctx.GetApiVersion() should take higher priority than Data.GetSchemaVersion().

	if devfileVersion = DevfileObj.Ctx.GetApiVersion(); devfileVersion == "" {
		devfileVersion = DevfileObj.Data.GetSchemaVersion()
	}

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

if err != nil {
Expand Down Expand Up @@ -542,12 +543,12 @@ func setDefaults(d DevfileObj) (err error) {

endpoints = component.Openshift.Endpoints

} else if component.Volume != nil {
} else if component.Volume != nil && schemaVersion != 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
78 changes: 78 additions & 0 deletions tests/v2/devfiles/samples/Test_200.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
commands:
- exec:
commandLine: npm install
component: runtime
group:
isDefault: true
kind: build
hotReloadCapable: false
workingDir: /project
id: install
- exec:
commandLine: npm start
component: runtime
group:
isDefault: true
kind: run
hotReloadCapable: false
workingDir: /project
id: run
- exec:
commandLine: npm run debug
component: runtime
group:
isDefault: true
kind: debug
hotReloadCapable: false
workingDir: /project
id: debug
- exec:
commandLine: npm test
component: runtime
group:
isDefault: true
kind: test
hotReloadCapable: false
workingDir: /project
id: test
components:
- container:
dedicatedPod: true
endpoints:
- name: http-3000
secure: false
targetPort: 3000
image: registry.access.redhat.com/ubi8/nodejs-14:latest
memoryLimit: 1024Mi
mountSources: true
sourceMapping: /project
volumeMounts:
- name: v1
path: /v1
- name: v2
path: /v2
name: runtime
- name: v1
volume:
size: 1Gi
- name: v2
volume:
size: 1Gi
metadata:
description: Stack with Node.js 14
displayName: Node.js Runtime
icon: https://nodejs.org/static/images/logos/nodejs-new-pantone-black.svg
language: javascript
name: nodejs-defect-pcbx
projectType: nodejs
tags:
- NodeJS
- Express
- ubi8
version: 1.0.1
schemaVersion: 2.0.0
starterProjects:
- git:
remotes:
origin: https://github.com/odo-devfiles/nodejs-ex.git
name: nodejs-starter
78 changes: 78 additions & 0 deletions tests/v2/devfiles/samples/Test_210.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
commands:
- exec:
commandLine: npm install
component: runtime
group:
isDefault: true
kind: build
hotReloadCapable: false
workingDir: /project
id: install
- exec:
commandLine: npm start
component: runtime
group:
isDefault: true
kind: run
hotReloadCapable: false
workingDir: /project
id: run
- exec:
commandLine: npm run debug
component: runtime
group:
isDefault: true
kind: debug
hotReloadCapable: false
workingDir: /project
id: debug
- exec:
commandLine: npm test
component: runtime
group:
isDefault: true
kind: test
hotReloadCapable: false
workingDir: /project
id: test
components:
- container:
dedicatedPod: true
endpoints:
- name: http-3000
secure: false
targetPort: 3000
image: registry.access.redhat.com/ubi8/nodejs-14:latest
memoryLimit: 1024Mi
mountSources: true
sourceMapping: /project
volumeMounts:
- name: v1
path: /v1
- name: v2
path: /v2
name: runtime
- name: v1
volume:
size: 1Gi
- name: v2
volume:
size: 1Gi
metadata:
description: Stack with Node.js 14
displayName: Node.js Runtime
icon: https://nodejs.org/static/images/logos/nodejs-new-pantone-black.svg
language: javascript
name: nodejs-defect-pcbx
projectType: nodejs
tags:
- NodeJS
- Express
- ubi8
version: 1.0.1
schemaVersion: 2.1.0
starterProjects:
- git:
remotes:
origin: https://github.com/odo-devfiles/nodejs-ex.git
name: nodejs-starter
83 changes: 83 additions & 0 deletions tests/v2/devfiles/samples/Test_220.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
commands:
- exec:
commandLine: npm install
component: runtime
group:
isDefault: true
kind: build
hotReloadCapable: false
workingDir: /project
id: install
- exec:
commandLine: npm start
component: runtime
group:
isDefault: true
kind: run
hotReloadCapable: false
workingDir: /project
id: run
- exec:
commandLine: npm run debug
component: runtime
group:
isDefault: true
kind: debug
hotReloadCapable: false
workingDir: /project
id: debug
- exec:
commandLine: npm test
component: runtime
group:
isDefault: true
kind: test
hotReloadCapable: false
workingDir: /project
id: test
components:
- name: outerloop-build
image:
imageName: nodejs-image:latest
dockerfile:
uri: Dockerfile
- container:
dedicatedPod: true
endpoints:
- name: http-3000
secure: false
targetPort: 3000
image: registry.access.redhat.com/ubi8/nodejs-14:latest
memoryLimit: 1024Mi
mountSources: true
sourceMapping: /project
volumeMounts:
- name: v1
path: /v1
- name: v2
path: /v2
name: runtime
- name: v1
volume:
size: 1Gi
- name: v2
volume:
size: 1Gi
metadata:
description: Stack with Node.js 14
displayName: Node.js Runtime
icon: https://nodejs.org/static/images/logos/nodejs-new-pantone-black.svg
language: javascript
name: nodejs-defect-pcbx
projectType: nodejs
tags:
- NodeJS
- Express
- ubi8
version: 1.0.1
schemaVersion: 2.2.0
starterProjects:
- git:
remotes:
origin: https://github.com/odo-devfiles/nodejs-ex.git
name: nodejs-starter
42 changes: 36 additions & 6 deletions tests/v2/libraryTest/library_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,38 @@ func Test_Parent_Local_URI(t *testing.T) {
testContent.FileName = "Test_Parent_LocalURI.yaml"
//copy the parent and main devfile from devfiles/samples
libraryUtils.CopyDevfileSamples(t, []string{testContent.FileName, "Parent.yaml"})
libraryUtils.RunParentTest(testContent, t)
libraryUtils.RunMultiThreadedParentTest(testContent, t)
libraryUtils.RunStaticTest(testContent, t)
libraryUtils.RunMultiThreadedStaticTest(testContent, t)
}

func Test_v200_Devfile(t *testing.T) {
testContent := commonUtils.TestContent{}
testContent.AddParent = false
testContent.EditContent = false
testContent.FileName = "Test_200.yaml"
libraryUtils.CopyDevfileSamples(t, []string{testContent.FileName})
libraryUtils.RunStaticTest(testContent, t)
libraryUtils.RunMultiThreadedStaticTest(testContent, t)
}

func Test_v210_Devfile(t *testing.T) {
testContent := commonUtils.TestContent{}
testContent.AddParent = false
testContent.EditContent = false
testContent.FileName = "Test_210.yaml"
libraryUtils.CopyDevfileSamples(t, []string{testContent.FileName})
libraryUtils.RunStaticTest(testContent, t)
libraryUtils.RunMultiThreadedStaticTest(testContent, t)
}

func Test_v220_Devfile(t *testing.T) {
testContent := commonUtils.TestContent{}
testContent.AddParent = false
testContent.EditContent = false
testContent.FileName = "Test_220.yaml"
libraryUtils.CopyDevfileSamples(t, []string{testContent.FileName})
libraryUtils.RunStaticTest(testContent, t)

}

//Create kube client and context and set as ParserArgs for Parent Kubernetes reference test. Corresponding main devfile is ../devfile/samples/TestParent_KubeCRD.yaml
Expand Down Expand Up @@ -328,8 +358,8 @@ func Test_Parent_KubeCRD(t *testing.T) {
parserArgs := setClientAndContextParserArgs()
libraryUtils.CopyDevfileSamples(t, []string{testContent.FileName})
libraryUtils.SetParserArgs(*parserArgs)
libraryUtils.RunParentTest(testContent, t)
libraryUtils.RunMultiThreadedParentTest(testContent, t)
libraryUtils.RunStaticTest(testContent, t)
libraryUtils.RunMultiThreadedStaticTest(testContent, t)
}

func Test_Parent_RegistryURL(t *testing.T) {
Expand All @@ -338,8 +368,8 @@ func Test_Parent_RegistryURL(t *testing.T) {
testContent.EditContent = false
testContent.FileName = "Test_Parent_RegistryURL.yaml"
libraryUtils.CopyDevfileSamples(t, []string{testContent.FileName})
libraryUtils.RunParentTest(testContent, t)
libraryUtils.RunMultiThreadedParentTest(testContent, t)
libraryUtils.RunStaticTest(testContent, t)
libraryUtils.RunMultiThreadedStaticTest(testContent, t)
}

func Test_Everything(t *testing.T) {
Expand Down
Loading