Skip to content

Commit

Permalink
add support for 2.2.1 and 2.2.2 schema versions (#208)
Browse files Browse the repository at this point in the history
* add support for 2.2.1 and 2.2.2 schema versions

Signed-off-by: Jordan Dubrick <jdubrick@redhat.com>

* update error output msg

Signed-off-by: Jordan Dubrick <jdubrick@redhat.com>

---------

Signed-off-by: Jordan Dubrick <jdubrick@redhat.com>
  • Loading branch information
Jdubrick committed Mar 15, 2024
1 parent d3c2770 commit 44ca18d
Show file tree
Hide file tree
Showing 6 changed files with 4,370 additions and 11 deletions.
64 changes: 58 additions & 6 deletions pkg/devfile/parse_test.go
Expand Up @@ -152,21 +152,26 @@ metadata:
tags:
- Go
version: 1.0.0
schemaVersion: 2.2.0
schemaVersion: 2.2.2
`

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 @@ -262,6 +267,8 @@ spec:
testServer.Start()
defer testServer.Close()

unsupportedSchemaError := `error parsing devfile because of non-compliant data due to unable to find schema for version "2.2.5". The parser supports devfile schema for version 2.0.0, 2.1.0, 2.2.0, 2.2.1, 2.2.2, v1alpha2`

type args struct {
args parser.ParserArgs
}
Expand All @@ -274,6 +281,7 @@ spec:
wantOpenshiftInline string
wantVariables map[string]string
additionalChecks func(parser.DevfileObj) error
wantErrorStr *string
}{
{
name: "with external overriding variables",
Expand All @@ -297,6 +305,7 @@ spec:
Projects: map[string][]string{},
StarterProjects: map[string][]string{},
},
wantErrorStr: nil,
},
{
name: "with new external variables",
Expand All @@ -321,6 +330,7 @@ spec:
Projects: map[string][]string{},
StarterProjects: map[string][]string{},
},
wantErrorStr: nil,
}, {
name: "with new external variables",
args: args{
Expand All @@ -343,6 +353,7 @@ spec:
Projects: map[string][]string{},
StarterProjects: map[string][]string{},
},
wantErrorStr: nil,
}, {
name: "with external variables and covertUriToInline is false",
args: args{
Expand All @@ -364,6 +375,7 @@ spec:
Projects: map[string][]string{},
StarterProjects: map[string][]string{},
},
wantErrorStr: nil,
},
{
name: "with flattening set to false and setBooleanDefaults to true",
Expand All @@ -386,6 +398,7 @@ spec:
Projects: map[string][]string{},
StarterProjects: map[string][]string{},
},
wantErrorStr: nil,
},
{
name: "with setBooleanDefaults to false",
Expand All @@ -408,6 +421,7 @@ spec:
Projects: map[string][]string{},
StarterProjects: map[string][]string{},
},
wantErrorStr: nil,
},
{
name: "get content from path",
Expand All @@ -429,6 +443,7 @@ spec:
Projects: map[string][]string{},
StarterProjects: map[string][]string{},
},
wantErrorStr: nil,
},
{
name: "get content from url",
Expand All @@ -450,6 +465,7 @@ spec:
Projects: map[string][]string{},
StarterProjects: map[string][]string{},
},
wantErrorStr: nil,
},
{
name: "with parent and registry url in devfile",
Expand All @@ -471,6 +487,7 @@ spec:
Projects: map[string][]string{},
StarterProjects: map[string][]string{},
},
wantErrorStr: nil,
},
{
name: "with parent and no registry url in devfile",
Expand All @@ -495,6 +512,7 @@ spec:
Projects: map[string][]string{},
StarterProjects: map[string][]string{},
},
wantErrorStr: nil,
},
{
name: "getting from cluster and setting default namespace",
Expand Down Expand Up @@ -527,6 +545,7 @@ spec:
Projects: map[string][]string{},
StarterProjects: map[string][]string{},
},
wantErrorStr: nil,
},
{
name: "parsing devfile with context path containing multiple devfiles => priority to devfile.yaml",
Expand Down Expand Up @@ -555,6 +574,7 @@ spec:
}
return nil
},
wantErrorStr: nil,
},
{
name: "parsing devfile with context path containing multiple devfiles => priority to .devfile.yaml",
Expand Down Expand Up @@ -583,6 +603,7 @@ spec:
}
return nil
},
wantErrorStr: nil,
},
{
name: "parsing devfile with context path containing multiple devfiles => priority to devfile.yml",
Expand Down Expand Up @@ -611,6 +632,7 @@ spec:
}
return nil
},
wantErrorStr: nil,
},
{
name: "parsing devfile with context path containing multiple devfiles => priority to .devfile.yml",
Expand Down Expand Up @@ -639,6 +661,7 @@ spec:
}
return nil
},
wantErrorStr: nil,
},
{
name: "parsing devfile with .yml extension",
Expand Down Expand Up @@ -667,6 +690,7 @@ spec:
}
return nil
},
wantErrorStr: nil,
},
{
name: "parsing .devfile with .yml extension",
Expand Down Expand Up @@ -695,6 +719,7 @@ spec:
}
return nil
},
wantErrorStr: nil,
},
{
name: "parsing .devfile with .yaml extension",
Expand Down Expand Up @@ -723,6 +748,7 @@ spec:
}
return nil
},
wantErrorStr: nil,
},
{
name: "parsing any valid devfile regardless of extension",
Expand Down Expand Up @@ -751,13 +777,39 @@ spec:
}
return nil
},
wantErrorStr: nil,
},
{
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{},
},
wantErrorStr: &unsupportedSchemaError,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
gotD, gotVarWarning, err := ParseDevfileAndValidate(tt.args.args)
if err != nil {
t.Errorf("ParseDevfileAndValidate() error = %v, wantErr nil", err)
if err != nil && err.Error() == *tt.wantErrorStr {
t.Log("Correctly identified unsupported schema version")
return
} else if err != nil {
t.Errorf("ParseDevfileAndValidate() error = %v, wantErrStr = %v", err, tt.wantErrorStr)
return
}
commands, err := gotD.Data.GetCommands(common.DevfileOptions{})
Expand Down
2 changes: 2 additions & 0 deletions pkg/devfile/parser/data/helper.go
Expand Up @@ -18,6 +18,7 @@ package data
import (
"fmt"
"reflect"
"sort"
"strings"

"k8s.io/klog"
Expand Down Expand Up @@ -51,6 +52,7 @@ func GetDevfileJSONSchema(version string) (string, error) {
for version := range devfileApiVersionToJSONSchema {
supportedVersions = append(supportedVersions, string(version))
}
sort.Strings(supportedVersions)
return "", fmt.Errorf("unable to find schema for version %q. The parser supports devfile schema for version %s", version, strings.Join(supportedVersions, ", "))
}
klog.V(4).Infof("devfile apiVersion '%s' is supported", version)
Expand Down
8 changes: 4 additions & 4 deletions pkg/devfile/parser/data/v2/2.2.0/devfileJsonSchema220.go
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

0 comments on commit 44ca18d

Please sign in to comment.