Skip to content

Commit

Permalink
add support for 2.2.1 and 2.2.2 schema versions
Browse files Browse the repository at this point in the history
Signed-off-by: Jordan Dubrick <jdubrick@redhat.com>
  • Loading branch information
Jdubrick committed Mar 14, 2024
1 parent d3c2770 commit f2bbec1
Show file tree
Hide file tree
Showing 5 changed files with 4,364 additions and 9 deletions.
58 changes: 54 additions & 4 deletions pkg/devfile/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,16 +157,21 @@ schemaVersion: 2.2.0

devfileContentWithVariable := devfileContent + `variables:
PARAMS: foo`
devfileContentWithParent := `schemaVersion: 2.2.0
devfileContentWithParent := `schemaVersion: 2.2.2
parent:
id: devfile1
registryUrl: http://127.0.0.1:8080/registry
`
devfileContentWithParentNoRegistry := `schemaVersion: 2.2.0
devfileContentWithUnsupportedSchema := `schemaVersion: 2.2.5
parent:
id: devfile1
registryUrl: http://127.0.0.1:8080/registry
`
devfileContentWithParentNoRegistry := `schemaVersion: 2.2.2
parent:
id: devfile1
`
devfileContentWithCRDParent := `schemaVersion: 2.2.0
devfileContentWithCRDParent := `schemaVersion: 2.2.2
parent:
kubernetes:
name: devfile1
Expand Down Expand Up @@ -274,6 +279,7 @@ spec:
wantOpenshiftInline string
wantVariables map[string]string
additionalChecks func(parser.DevfileObj) error
wantError bool
}{
{
name: "with external overriding variables",
Expand All @@ -297,6 +303,7 @@ spec:
Projects: map[string][]string{},
StarterProjects: map[string][]string{},
},
wantError: false,
},
{
name: "with new external variables",
Expand All @@ -321,6 +328,7 @@ spec:
Projects: map[string][]string{},
StarterProjects: map[string][]string{},
},
wantError: false,
}, {
name: "with new external variables",
args: args{
Expand All @@ -343,6 +351,7 @@ spec:
Projects: map[string][]string{},
StarterProjects: map[string][]string{},
},
wantError: false,
}, {
name: "with external variables and covertUriToInline is false",
args: args{
Expand All @@ -364,6 +373,7 @@ spec:
Projects: map[string][]string{},
StarterProjects: map[string][]string{},
},
wantError: false,
},
{
name: "with flattening set to false and setBooleanDefaults to true",
Expand All @@ -386,6 +396,7 @@ spec:
Projects: map[string][]string{},
StarterProjects: map[string][]string{},
},
wantError: false,
},
{
name: "with setBooleanDefaults to false",
Expand All @@ -408,6 +419,7 @@ spec:
Projects: map[string][]string{},
StarterProjects: map[string][]string{},
},
wantError: false,
},
{
name: "get content from path",
Expand All @@ -429,6 +441,7 @@ spec:
Projects: map[string][]string{},
StarterProjects: map[string][]string{},
},
wantError: false,
},
{
name: "get content from url",
Expand All @@ -450,6 +463,7 @@ spec:
Projects: map[string][]string{},
StarterProjects: map[string][]string{},
},
wantError: false,
},
{
name: "with parent and registry url in devfile",
Expand All @@ -471,6 +485,7 @@ spec:
Projects: map[string][]string{},
StarterProjects: map[string][]string{},
},
wantError: false,
},
{
name: "with parent and no registry url in devfile",
Expand All @@ -495,6 +510,7 @@ spec:
Projects: map[string][]string{},
StarterProjects: map[string][]string{},
},
wantError: false,
},
{
name: "getting from cluster and setting default namespace",
Expand Down Expand Up @@ -527,6 +543,7 @@ spec:
Projects: map[string][]string{},
StarterProjects: map[string][]string{},
},
wantError: false,
},
{
name: "parsing devfile with context path containing multiple devfiles => priority to devfile.yaml",
Expand Down Expand Up @@ -555,6 +572,7 @@ spec:
}
return nil
},
wantError: false,
},
{
name: "parsing devfile with context path containing multiple devfiles => priority to .devfile.yaml",
Expand Down Expand Up @@ -583,6 +601,7 @@ spec:
}
return nil
},
wantError: false,
},
{
name: "parsing devfile with context path containing multiple devfiles => priority to devfile.yml",
Expand Down Expand Up @@ -611,6 +630,7 @@ spec:
}
return nil
},
wantError: false,
},
{
name: "parsing devfile with context path containing multiple devfiles => priority to .devfile.yml",
Expand Down Expand Up @@ -639,6 +659,7 @@ spec:
}
return nil
},
wantError: false,
},
{
name: "parsing devfile with .yml extension",
Expand Down Expand Up @@ -667,6 +688,7 @@ spec:
}
return nil
},
wantError: false,
},
{
name: "parsing .devfile with .yml extension",
Expand Down Expand Up @@ -695,6 +717,7 @@ spec:
}
return nil
},
wantError: false,
},
{
name: "parsing .devfile with .yaml extension",
Expand Down Expand Up @@ -723,6 +746,7 @@ spec:
}
return nil
},
wantError: false,
},
{
name: "parsing any valid devfile regardless of extension",
Expand Down Expand Up @@ -751,12 +775,38 @@ spec:
}
return nil
},
wantError: false,
},
{
name: "with unsupported schema version",
args: args{
args: parser.ParserArgs{
ExternalVariables: map[string]string{
"PARAMS": "baz",
},
Data: []byte(devfileContentWithUnsupportedSchema),
},
},
wantCommandLine: "./main baz",
wantVariables: map[string]string{
"PARAMS": "baz",
},
wantVarWarning: variables.VariableWarning{
Commands: map[string][]string{},
Components: map[string][]string{},
Projects: map[string][]string{},
StarterProjects: map[string][]string{},
},
wantError: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
gotD, gotVarWarning, err := ParseDevfileAndValidate(tt.args.args)
if err != nil {
if err != nil && tt.wantError {
t.Log("Correctly identified unsupported schema version")
return
} else if err != nil {
t.Errorf("ParseDevfileAndValidate() error = %v, wantErr nil", err)
return
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/devfile/parser/data/v2/2.2.0/devfileJsonSchema220.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@

package version220

// https://raw.githubusercontent.com/devfile/api/main/schemas/latest/devfile.json
// https://raw.githubusercontent.com/devfile/api/v2.2.0/schemas/latest/devfile.json
const JsonSchema220 = `{
"description": "Devfile describes the structure of a cloud-native devworkspace and development environment.",
"type": "object",
"title": "Devfile schema - Version 2.2.1-alpha",
"title": "Devfile schema - Version 2.2.0",
"required": [
"schemaVersion"
],
Expand Down Expand Up @@ -212,7 +212,7 @@ const JsonSchema220 = `{
"additionalProperties": false
},
"hotReloadCapable": {
"description": "Specify whether the command is restarted or not when the source code changes. If set to 'true' the command won't be restarted. A *hotReloadCapable* 'run' or 'debug' command is expected to handle file changes on its own and won't be restarted. A *hotReloadCapable* 'build' command is expected to be executed only once and won't be executed again. This field is taken into account only for commands 'build', 'run' and 'debug' with 'isDefault' set to 'true'.\n\nDefault value is 'false'",
"description": "Whether the command is capable to reload itself when source code changes. If set to 'true' the command won't be restarted and it is expected to handle file changes on its own.\n\nDefault value is 'false'",
"type": "boolean"
},
"label": {
Expand Down Expand Up @@ -1104,7 +1104,7 @@ const JsonSchema220 = `{
"additionalProperties": false
},
"hotReloadCapable": {
"description": "Specify whether the command is restarted or not when the source code changes. If set to 'true' the command won't be restarted. A *hotReloadCapable* 'run' or 'debug' command is expected to handle file changes on its own and won't be restarted. A *hotReloadCapable* 'build' command is expected to be executed only once and won't be executed again. This field is taken into account only for commands 'build', 'run' and 'debug' with 'isDefault' set to 'true'.\n\nDefault value is 'false'",
"description": "Whether the command is capable to reload itself when source code changes. If set to 'true' the command won't be restarted and it is expected to handle file changes on its own.\n\nDefault value is 'false'",
"type": "boolean"
},
"label": {
Expand Down
Loading

0 comments on commit f2bbec1

Please sign in to comment.