Skip to content

Commit a103cab

Browse files
committed
Check devfile schemaVersion via regexp to support all 2.x devfiles
Signed-off-by: Angel Misevski <[email protected]>
1 parent 8e46c07 commit a103cab

File tree

3 files changed

+6
-7
lines changed

3 files changed

+6
-7
lines changed

Diff for: pkg/library/flatten/network/devfile.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,22 @@ package network
1414

1515
import (
1616
"fmt"
17+
"regexp"
1718

1819
dw "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
1920
devfilev2 "github.com/devfile/api/v2/pkg/devfile"
2021
)
2122

22-
const (
23-
SupportedDevfileSchemaVersion = "2.0.0" // TODO what should this actually be at this point?
24-
)
23+
var SupportedSchemaVersionRegexp = regexp.MustCompile(`^2\..+`)
2524

2625
type Devfile struct {
2726
devfilev2.DevfileHeader
2827
dw.DevWorkspaceTemplateSpec
2928
}
3029

3130
func ConvertDevfileToDevWorkspaceTemplate(devfile *Devfile) (*dw.DevWorkspaceTemplate, error) {
32-
if devfile.SchemaVersion != SupportedDevfileSchemaVersion {
33-
return nil, fmt.Errorf("could not process devfile: supported schemaVersion is %s", SupportedDevfileSchemaVersion)
31+
if !SupportedSchemaVersionRegexp.MatchString(devfile.SchemaVersion) {
32+
return nil, fmt.Errorf("could not process devfile: unsupported schemaVersion '%s'", devfile.SchemaVersion)
3433
}
3534
dwt := &dw.DevWorkspaceTemplate{}
3635
dwt.Spec = devfile.DevWorkspaceTemplateSpec

Diff for: pkg/library/flatten/testdata/plugin-id/error_invalid-schema-version.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ input:
1919
image: test-image
2020

2121
output:
22-
errRegexp: "could not process devfile: supported schemaVersion is .*"
22+
errRegexp: "could not process devfile: unsupported schemaVersion '1.0.0'"

Diff for: pkg/library/flatten/testdata/plugin-uri/error_invalid-schema-version.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ input:
1818
image: test-image
1919

2020
output:
21-
errRegexp: "could not process devfile: supported schemaVersion is .*"
21+
errRegexp: "could not process devfile: unsupported schemaVersion '1.0.0'"

0 commit comments

Comments
 (0)