@@ -22,6 +22,7 @@ import (
22
22
v1 "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
23
23
apiOverride "github.com/devfile/api/v2/pkg/utils/overriding"
24
24
"github.com/devfile/api/v2/pkg/validation"
25
+ versionpkg "github.com/hashicorp/go-version"
25
26
"github.com/pkg/errors"
26
27
)
27
28
@@ -192,6 +193,18 @@ func ParseFromData(data []byte) (d DevfileObj, err error) {
192
193
193
194
func parseParentAndPlugin (d DevfileObj , resolveCtx * resolutionContextTree , tool resolverTools ) (err error ) {
194
195
flattenedParent := & v1.DevWorkspaceTemplateSpecContent {}
196
+ var mainDevfileVersion , parentDevfileVerson , pluginDevfileVerson * versionpkg.Version
197
+ var devfileVersion string
198
+ if devfileVersion = d .Ctx .GetApiVersion (); devfileVersion == "" {
199
+ devfileVersion = d .Data .GetSchemaVersion ()
200
+ }
201
+
202
+ if devfileVersion != "" {
203
+ mainDevfileVersion , err = versionpkg .NewVersion (devfileVersion )
204
+ if err != nil {
205
+ return fmt .Errorf ("fail to parse version of the main devfile" )
206
+ }
207
+ }
195
208
parent := d .Data .GetParent ()
196
209
if parent != nil {
197
210
if ! reflect .DeepEqual (parent , & v1.Parent {}) {
@@ -210,7 +223,20 @@ func parseParentAndPlugin(d DevfileObj, resolveCtx *resolutionContextTree, tool
210
223
if err != nil {
211
224
return err
212
225
}
226
+ var devfileVersion string
227
+ if devfileVersion = parentDevfileObj .Ctx .GetApiVersion (); devfileVersion == "" {
228
+ devfileVersion = parentDevfileObj .Data .GetSchemaVersion ()
229
+ }
213
230
231
+ if devfileVersion != "" {
232
+ parentDevfileVerson , err = versionpkg .NewVersion (devfileVersion )
233
+ if err != nil {
234
+ return fmt .Errorf ("fail to parse version of parent devfile from: %v" , resolveImportReference (parent .ImportReference ))
235
+ }
236
+ if parentDevfileVerson .GreaterThan (mainDevfileVersion ) {
237
+ return fmt .Errorf ("the parent devfile version from %v is greater than the child devfile version from %v" , resolveImportReference (parent .ImportReference ), resolveImportReference (resolveCtx .importReference ))
238
+ }
239
+ }
214
240
parentWorkspaceContent := parentDevfileObj .Data .GetDevfileWorkspaceSpecContent ()
215
241
// add attribute to parent elements
216
242
err = addSourceAttributesForOverrideAndMerge (parent .ImportReference , parentWorkspaceContent )
@@ -258,6 +284,20 @@ func parseParentAndPlugin(d DevfileObj, resolveCtx *resolutionContextTree, tool
258
284
if err != nil {
259
285
return err
260
286
}
287
+ var devfileVersion string
288
+ if devfileVersion = pluginDevfileObj .Ctx .GetApiVersion (); devfileVersion == "" {
289
+ devfileVersion = pluginDevfileObj .Data .GetSchemaVersion ()
290
+ }
291
+
292
+ if devfileVersion != "" {
293
+ pluginDevfileVerson , err = versionpkg .NewVersion (devfileVersion )
294
+ if err != nil {
295
+ return fmt .Errorf ("fail to parse version of plugin devfile from: %v" , resolveImportReference (component .Plugin .ImportReference ))
296
+ }
297
+ if pluginDevfileVerson .GreaterThan (mainDevfileVersion ) {
298
+ return fmt .Errorf ("the plugin devfile version from %v is greater than the child devfile version from %v" , resolveImportReference (component .Plugin .ImportReference ), resolveImportReference (resolveCtx .importReference ))
299
+ }
300
+ }
261
301
pluginWorkspaceContent := pluginDevfileObj .Data .GetDevfileWorkspaceSpecContent ()
262
302
// add attribute to plugin elements
263
303
err = addSourceAttributesForOverrideAndMerge (plugin .ImportReference , pluginWorkspaceContent )
0 commit comments