-
Notifications
You must be signed in to change notification settings - Fork 244
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Support for Devfile V2 #3216
Changes from 1 commit
59d6a01
9a5b45e
ce9c99e
f9bcff9
0825fcc
8147f76
d2553f5
82b979d
cd8d466
65841d9
b33a348
9132a12
9d8eac5
01d80e1
74d0ebc
53401ea
935b409
e558170
bf8fed0
04838f4
524e70a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,37 @@ | ||
package version100 | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/openshift/odo/pkg/devfile/parser/data/common" | ||
) | ||
|
||
// GetComponents returns the slice of DevfileComponent objects parsed from the Devfile | ||
func (d *Devfile100) GetMetadata() common.DevfileMetadata { | ||
// No GenerateName field in V2 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This part is confusing. There is no GenerateName in V2. But there is in V1. So we would need to still return GenerateName here as this is the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To add There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thats what i said, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Honestly I still think we should add GenerateName here... This is fairly confusing as this is the v1.0.0 parser folder but we are implementing v2 features. |
||
return common.DevfileMetadata{ | ||
Name: *d.Metadata.Name, | ||
//Version: No field in V1 | ||
} | ||
} | ||
|
||
/// GetComponents returns the slice of DevfileComponent objects parsed from the Devfile | ||
func (d *Devfile100) GetComponents() []common.DevfileComponent { | ||
return d.Components | ||
var comps []common.DevfileComponent | ||
for _, v := range d.Components { | ||
comps = append(comps, convertV1ComponentToCommon(v)) | ||
} | ||
return comps | ||
} | ||
|
||
// GetAliasedComponents returns the slice of DevfileComponent objects that each have an alias | ||
func (d *Devfile100) GetAliasedComponents() []common.DevfileComponent { | ||
// TODO(adi): we might not need this for V2 as name is a required field now. | ||
var comps []common.DevfileComponent | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again, see other comment. These sections are all about Version 1. So why are we making changes / breaking backwards compatibility here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @cdrage Aditi can explain in more detail, but I think she had to make changes here to use the new common structs for both v1 and v2; so that v1 doesn't break Like calling func There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @cdrage all v1 integration tests are passing, so it is the first sign we are not breaking anything. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Then we should rename the folder / all mentions of v1.0.0 to something else in this folder as to be honest, we are implementing v2 features where v1 is.. |
||
for _, v := range d.Components { | ||
comps = append(comps, convertV1ComponentToCommon(v)) | ||
} | ||
|
||
var aliasedComponents = []common.DevfileComponent{} | ||
for _, comp := range d.Components { | ||
if comp.Alias != nil { | ||
for _, comp := range comps { | ||
if comp.Container.Name != "" { | ||
aliasedComponents = append(aliasedComponents, comp) | ||
} | ||
} | ||
|
@@ -24,17 +40,157 @@ func (d *Devfile100) GetAliasedComponents() []common.DevfileComponent { | |
|
||
// GetProjects returns the slice of DevfileProject objects parsed from the Devfile | ||
func (d *Devfile100) GetProjects() []common.DevfileProject { | ||
return d.Projects | ||
|
||
var projects []common.DevfileProject | ||
for _, v := range d.Projects { | ||
// We are only supporting ProjectType git in V1 | ||
if v.Source.Type == ProjectTypeGit { | ||
projects = append(projects, convertV1ProjectToCommon(v)) | ||
} | ||
} | ||
|
||
return projects | ||
} | ||
|
||
// GetCommands returns the slice of DevfileCommand objects parsed from the Devfile | ||
func (d *Devfile100) GetCommands() []common.DevfileCommand { | ||
|
||
var commands []common.DevfileCommand | ||
for _, v := range d.Commands { | ||
cmd := convertV1CommandToCommon(v) | ||
|
||
for _, command := range d.Commands { | ||
command.Name = strings.ToLower(command.Name) | ||
commands = append(commands, command) | ||
commands = append(commands, cmd) | ||
} | ||
|
||
return commands | ||
} | ||
|
||
func (d *Devfile100) GetParent() common.DevfileParent { | ||
return common.DevfileParent{} | ||
|
||
} | ||
|
||
func (d *Devfile100) GetEvents() common.DevfileEvents { | ||
return common.DevfileEvents{} | ||
|
||
} | ||
|
||
func convertV1CommandToCommon(c Command) (d common.DevfileCommand) { | ||
var exec common.Exec | ||
|
||
for _, action := range c.Actions { | ||
|
||
if *action.Type == DevfileCommandTypeExec { | ||
exec = common.Exec{ | ||
Attributes: c.Attributes, | ||
CommandLine: *action.Command, | ||
Component: *action.Component, | ||
Group: getGroup(c.Name), | ||
Id: c.Name, | ||
WorkingDir: action.Workdir, | ||
// Env: | ||
// Label: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shouldn't we remove these? |
||
} | ||
} | ||
|
||
} | ||
|
||
// TODO: Previewurl | ||
return common.DevfileCommand{ | ||
//TODO(adi): Type | ||
Exec: &exec, | ||
} | ||
} | ||
|
||
func convertV1ComponentToCommon(c Component) (d common.DevfileComponent) { | ||
girishramnani marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
var endpoints []*common.Endpoint | ||
for _, v := range c.ComponentDockerimage.Endpoints { | ||
endpoints = append(endpoints, convertV1EndpointsToCommon(v)) | ||
} | ||
|
||
var envs []*common.Env | ||
for _, v := range c.ComponentDockerimage.Env { | ||
envs = append(envs, convertV1EnvToCommon(v)) | ||
} | ||
|
||
var volumes []*common.VolumeMount | ||
for _, v := range c.ComponentDockerimage.Volumes { | ||
volumes = append(volumes, convertV1VolumeToCommon(v)) | ||
} | ||
|
||
container := common.Container{ | ||
Name: *c.Alias, | ||
Endpoints: endpoints, | ||
Env: envs, | ||
Image: *c.ComponentDockerimage.Image, | ||
girishramnani marked this conversation as resolved.
Show resolved
Hide resolved
|
||
MemoryLimit: *c.ComponentDockerimage.MemoryLimit, | ||
MountSources: c.MountSources, | ||
VolumeMounts: volumes, | ||
// SourceMapping: Not present in V1 | ||
} | ||
|
||
d = common.DevfileComponent{Container: &container} | ||
|
||
return d | ||
} | ||
|
||
func convertV1EndpointsToCommon(e DockerimageEndpoint) *common.Endpoint { | ||
return &common.Endpoint{ | ||
// Attributes: | ||
// Configuration: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we remove these commented attributes? |
||
Name: *e.Name, | ||
TargetPort: *e.Port, | ||
} | ||
} | ||
|
||
func convertV1EnvToCommon(e DockerimageEnv) *common.Env { | ||
return &common.Env{ | ||
Name: *e.Name, | ||
Value: *e.Value, | ||
} | ||
} | ||
|
||
func convertV1VolumeToCommon(v DockerimageVolume) *common.VolumeMount { | ||
return &common.VolumeMount{ | ||
Name: *v.Name, | ||
Path: *v.ContainerPath, | ||
} | ||
} | ||
|
||
func convertV1ProjectToCommon(p Project) common.DevfileProject { | ||
|
||
git := common.Git{ | ||
Branch: *p.Source.Branch, | ||
Location: p.Source.Location, | ||
SparseCheckoutDir: *p.Source.SparseCheckoutDir, | ||
StartPoint: *p.Source.StartPoint, | ||
} | ||
|
||
return common.DevfileProject{ | ||
ClonePath: p.ClonePath, | ||
Name: p.Name, | ||
Git: &git, | ||
} | ||
|
||
} | ||
|
||
func getGroup(name string) *common.Group { | ||
var kind common.DevfileCommandGroupType | ||
|
||
switch name { | ||
case "devRun": | ||
kind = common.RunCommandGroupType | ||
case "devBuild": | ||
kind = common.BuildCommandGroupType | ||
case "devInit": | ||
kind = common.InitCommandGroupType | ||
default: | ||
kind = "" | ||
} | ||
|
||
return &common.Group{ | ||
// TODO(adi): IsDefault: | ||
Kind: kind, | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what happens if both are provided, apiVersion and schemaVersion?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there is no field
apiVersion
for V2 and no fieldschemaVersion
for V1, so they cannot be provided together, json validation would fail for such case.