Skip to content

Commit 44ca18d

Browse files
authored
add support for 2.2.1 and 2.2.2 schema versions (#208)
* add support for 2.2.1 and 2.2.2 schema versions Signed-off-by: Jordan Dubrick <[email protected]> * update error output msg Signed-off-by: Jordan Dubrick <[email protected]> --------- Signed-off-by: Jordan Dubrick <[email protected]>
1 parent d3c2770 commit 44ca18d

File tree

6 files changed

+4370
-11
lines changed

6 files changed

+4370
-11
lines changed

pkg/devfile/parse_test.go

Lines changed: 58 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,21 +152,26 @@ metadata:
152152
tags:
153153
- Go
154154
version: 1.0.0
155-
schemaVersion: 2.2.0
155+
schemaVersion: 2.2.2
156156
`
157157

158158
devfileContentWithVariable := devfileContent + `variables:
159159
PARAMS: foo`
160-
devfileContentWithParent := `schemaVersion: 2.2.0
160+
devfileContentWithParent := `schemaVersion: 2.2.2
161161
parent:
162162
id: devfile1
163163
registryUrl: http://127.0.0.1:8080/registry
164164
`
165-
devfileContentWithParentNoRegistry := `schemaVersion: 2.2.0
165+
devfileContentWithUnsupportedSchema := `schemaVersion: 2.2.5
166+
parent:
167+
id: devfile1
168+
registryUrl: http://127.0.0.1:8080/registry
169+
`
170+
devfileContentWithParentNoRegistry := `schemaVersion: 2.2.2
166171
parent:
167172
id: devfile1
168173
`
169-
devfileContentWithCRDParent := `schemaVersion: 2.2.0
174+
devfileContentWithCRDParent := `schemaVersion: 2.2.2
170175
parent:
171176
kubernetes:
172177
name: devfile1
@@ -262,6 +267,8 @@ spec:
262267
testServer.Start()
263268
defer testServer.Close()
264269

270+
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`
271+
265272
type args struct {
266273
args parser.ParserArgs
267274
}
@@ -274,6 +281,7 @@ spec:
274281
wantOpenshiftInline string
275282
wantVariables map[string]string
276283
additionalChecks func(parser.DevfileObj) error
284+
wantErrorStr *string
277285
}{
278286
{
279287
name: "with external overriding variables",
@@ -297,6 +305,7 @@ spec:
297305
Projects: map[string][]string{},
298306
StarterProjects: map[string][]string{},
299307
},
308+
wantErrorStr: nil,
300309
},
301310
{
302311
name: "with new external variables",
@@ -321,6 +330,7 @@ spec:
321330
Projects: map[string][]string{},
322331
StarterProjects: map[string][]string{},
323332
},
333+
wantErrorStr: nil,
324334
}, {
325335
name: "with new external variables",
326336
args: args{
@@ -343,6 +353,7 @@ spec:
343353
Projects: map[string][]string{},
344354
StarterProjects: map[string][]string{},
345355
},
356+
wantErrorStr: nil,
346357
}, {
347358
name: "with external variables and covertUriToInline is false",
348359
args: args{
@@ -364,6 +375,7 @@ spec:
364375
Projects: map[string][]string{},
365376
StarterProjects: map[string][]string{},
366377
},
378+
wantErrorStr: nil,
367379
},
368380
{
369381
name: "with flattening set to false and setBooleanDefaults to true",
@@ -386,6 +398,7 @@ spec:
386398
Projects: map[string][]string{},
387399
StarterProjects: map[string][]string{},
388400
},
401+
wantErrorStr: nil,
389402
},
390403
{
391404
name: "with setBooleanDefaults to false",
@@ -408,6 +421,7 @@ spec:
408421
Projects: map[string][]string{},
409422
StarterProjects: map[string][]string{},
410423
},
424+
wantErrorStr: nil,
411425
},
412426
{
413427
name: "get content from path",
@@ -429,6 +443,7 @@ spec:
429443
Projects: map[string][]string{},
430444
StarterProjects: map[string][]string{},
431445
},
446+
wantErrorStr: nil,
432447
},
433448
{
434449
name: "get content from url",
@@ -450,6 +465,7 @@ spec:
450465
Projects: map[string][]string{},
451466
StarterProjects: map[string][]string{},
452467
},
468+
wantErrorStr: nil,
453469
},
454470
{
455471
name: "with parent and registry url in devfile",
@@ -471,6 +487,7 @@ spec:
471487
Projects: map[string][]string{},
472488
StarterProjects: map[string][]string{},
473489
},
490+
wantErrorStr: nil,
474491
},
475492
{
476493
name: "with parent and no registry url in devfile",
@@ -495,6 +512,7 @@ spec:
495512
Projects: map[string][]string{},
496513
StarterProjects: map[string][]string{},
497514
},
515+
wantErrorStr: nil,
498516
},
499517
{
500518
name: "getting from cluster and setting default namespace",
@@ -527,6 +545,7 @@ spec:
527545
Projects: map[string][]string{},
528546
StarterProjects: map[string][]string{},
529547
},
548+
wantErrorStr: nil,
530549
},
531550
{
532551
name: "parsing devfile with context path containing multiple devfiles => priority to devfile.yaml",
@@ -555,6 +574,7 @@ spec:
555574
}
556575
return nil
557576
},
577+
wantErrorStr: nil,
558578
},
559579
{
560580
name: "parsing devfile with context path containing multiple devfiles => priority to .devfile.yaml",
@@ -583,6 +603,7 @@ spec:
583603
}
584604
return nil
585605
},
606+
wantErrorStr: nil,
586607
},
587608
{
588609
name: "parsing devfile with context path containing multiple devfiles => priority to devfile.yml",
@@ -611,6 +632,7 @@ spec:
611632
}
612633
return nil
613634
},
635+
wantErrorStr: nil,
614636
},
615637
{
616638
name: "parsing devfile with context path containing multiple devfiles => priority to .devfile.yml",
@@ -639,6 +661,7 @@ spec:
639661
}
640662
return nil
641663
},
664+
wantErrorStr: nil,
642665
},
643666
{
644667
name: "parsing devfile with .yml extension",
@@ -667,6 +690,7 @@ spec:
667690
}
668691
return nil
669692
},
693+
wantErrorStr: nil,
670694
},
671695
{
672696
name: "parsing .devfile with .yml extension",
@@ -695,6 +719,7 @@ spec:
695719
}
696720
return nil
697721
},
722+
wantErrorStr: nil,
698723
},
699724
{
700725
name: "parsing .devfile with .yaml extension",
@@ -723,6 +748,7 @@ spec:
723748
}
724749
return nil
725750
},
751+
wantErrorStr: nil,
726752
},
727753
{
728754
name: "parsing any valid devfile regardless of extension",
@@ -751,13 +777,39 @@ spec:
751777
}
752778
return nil
753779
},
780+
wantErrorStr: nil,
781+
},
782+
{
783+
name: "with unsupported schema version",
784+
args: args{
785+
args: parser.ParserArgs{
786+
ExternalVariables: map[string]string{
787+
"PARAMS": "baz",
788+
},
789+
Data: []byte(devfileContentWithUnsupportedSchema),
790+
},
791+
},
792+
wantCommandLine: "./main baz",
793+
wantVariables: map[string]string{
794+
"PARAMS": "baz",
795+
},
796+
wantVarWarning: variables.VariableWarning{
797+
Commands: map[string][]string{},
798+
Components: map[string][]string{},
799+
Projects: map[string][]string{},
800+
StarterProjects: map[string][]string{},
801+
},
802+
wantErrorStr: &unsupportedSchemaError,
754803
},
755804
}
756805
for _, tt := range tests {
757806
t.Run(tt.name, func(t *testing.T) {
758807
gotD, gotVarWarning, err := ParseDevfileAndValidate(tt.args.args)
759-
if err != nil {
760-
t.Errorf("ParseDevfileAndValidate() error = %v, wantErr nil", err)
808+
if err != nil && err.Error() == *tt.wantErrorStr {
809+
t.Log("Correctly identified unsupported schema version")
810+
return
811+
} else if err != nil {
812+
t.Errorf("ParseDevfileAndValidate() error = %v, wantErrStr = %v", err, tt.wantErrorStr)
761813
return
762814
}
763815
commands, err := gotD.Data.GetCommands(common.DevfileOptions{})

pkg/devfile/parser/data/helper.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package data
1818
import (
1919
"fmt"
2020
"reflect"
21+
"sort"
2122
"strings"
2223

2324
"k8s.io/klog"
@@ -51,6 +52,7 @@ func GetDevfileJSONSchema(version string) (string, error) {
5152
for version := range devfileApiVersionToJSONSchema {
5253
supportedVersions = append(supportedVersions, string(version))
5354
}
55+
sort.Strings(supportedVersions)
5456
return "", fmt.Errorf("unable to find schema for version %q. The parser supports devfile schema for version %s", version, strings.Join(supportedVersions, ", "))
5557
}
5658
klog.V(4).Infof("devfile apiVersion '%s' is supported", version)

pkg/devfile/parser/data/v2/2.2.0/devfileJsonSchema220.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515

1616
package version220
1717

18-
// https://raw.githubusercontent.com/devfile/api/main/schemas/latest/devfile.json
18+
// https://raw.githubusercontent.com/devfile/api/v2.2.0/schemas/latest/devfile.json
1919
const JsonSchema220 = `{
2020
"description": "Devfile describes the structure of a cloud-native devworkspace and development environment.",
2121
"type": "object",
22-
"title": "Devfile schema - Version 2.2.1-alpha",
22+
"title": "Devfile schema - Version 2.2.0",
2323
"required": [
2424
"schemaVersion"
2525
],
@@ -212,7 +212,7 @@ const JsonSchema220 = `{
212212
"additionalProperties": false
213213
},
214214
"hotReloadCapable": {
215-
"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'",
215+
"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'",
216216
"type": "boolean"
217217
},
218218
"label": {
@@ -1104,7 +1104,7 @@ const JsonSchema220 = `{
11041104
"additionalProperties": false
11051105
},
11061106
"hotReloadCapable": {
1107-
"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'",
1107+
"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'",
11081108
"type": "boolean"
11091109
},
11101110
"label": {

0 commit comments

Comments
 (0)