-
Notifications
You must be signed in to change notification settings - Fork 243
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
Implement Starter Projects for devfile #3673
Implement Starter Projects for devfile #3673
Conversation
Not updated sync mechanism and some project references as this PR #3662 already doing that |
2d04d9f
to
2bd9234
Compare
failures
failing as all registry devfile using |
/retest |
@kadel tests would fail, until this PR odo-devfiles/registry#29 gets merged |
return nil | ||
} | ||
|
||
func (d *Devfile100) AddStarterProjects(projects []common.DevfileStarterProject) error { return nil } |
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.
Missing comments
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.
it is devfile V1 package, we are just adding functions to satisfy interface, We are not using them and eventually be removed.
|
||
func (d *Devfile100) AddStarterProjects(projects []common.DevfileStarterProject) error { return nil } | ||
|
||
func (d *Devfile100) UpdateStarterProject(project common.DevfileStarterProject) {} |
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.
Missing comments
@@ -895,8 +887,8 @@ func (co *CreateOptions) downloadProject(projectPassed string) error { | |||
return errors.Errorf("Project type not supported") | |||
} | |||
|
|||
log.Info("\nProject") | |||
downloadSpinner := log.Spinnerf("Downloading project from %s", logUrl) | |||
log.Info("\nStarter Project") |
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.
I think we should keep this as just Project
not Starter Project
. Just my opinion though! I think it would fit the output a bit better.
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.
I guess it might confuse users with projects
.
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.
Okay, we'll keep it as Starter Project. It looks kind of out of place, but that's just me. All below output seems to be starter project related only, so makes sense.
2bd9234
to
9966842
Compare
pkg/devfile/parser/types.go
Outdated
// OverrideStarterProjects overrides the projects of the parent devfile | ||
// overridePatch contains the patches to be applied to the parent's projects |
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.
starterProjects
pkg/devfile/parser/types.go
Outdated
} | ||
} | ||
if !found { | ||
return fmt.Errorf("the command to override is not found in the parent") |
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.
the starterProject to override
return d.StarterProjects | ||
} | ||
|
||
// AddStarterProjects adds the slice of Devfile projects to the Devfile's project list |
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.
Devfile's starterProjects
return nil | ||
} | ||
|
||
// UpdateStarterProject updates the slice of DevfileCommand projects parsed from the Devfile |
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.
Devfile starterProjects
cf44d2c
to
358bfca
Compare
/retest
|
/retest
|
updates tests to use devfile from odo repo /tests/examples/devfile |
|
||
// OverrideStarterProjects overrides the starter projects of the parent devfile | ||
// overridePatch contains the patches to be applied to the parent's starter projects | ||
func (d DevfileObj) OverrideStarterProjects(overridePatch []common.DevfileStarterProject) error { |
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.
unit test for this function
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.
done
pkg/odo/cli/component/ui/ui.go
Outdated
|
||
var download = false | ||
var selectedProject string | ||
prompt := &survey.Confirm{Message: "Do you want to download starter project"} |
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.
download a starter project
type DevfileStarterProject struct { | ||
|
||
// Project name | ||
Name string `json:"name"` |
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.
Please add yaml tags for these fields
@@ -275,6 +275,9 @@ type DevfileParent struct { | |||
|
|||
// Bindings of commands to events. Each command is referred-to by its name. | |||
Events DevfileEvents `json:"events,omitempty" yaml:"events,omitempty"` | |||
|
|||
// StarterProjects is a project that can be used as a starting point when bootstrapping new projects | |||
StarterProjects []DevfileStarterProject `json:"starterProjects,omitempty" yaml:"starterProjects,omitempty"` |
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.
Curious, why do we add the StarterProjects
type to the common package in the parser, rather than under parser/data/2.0.0
?
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.
every devfile struct(1.0, 2.0) needs to satisfy this interface https://github.com/openshift/odo/blob/master/pkg/devfile/parser/data/interface.go#L8
the methods here used everywhere in adapters code, to make the adapters code work on a common type regardless of devfile version passed, it has been done in this way.
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.
You'll need to update:
https://github.com/openshift/odo/blob/master/docs/file-reference/index.md
As well since we're doing a considerable change to the Devfile file reference.
pkg/devfile/parser/types.go
Outdated
|
||
err = json.Unmarshal(merged, &updatedProject) | ||
if err != nil { | ||
return err |
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.
I think you should add a description to append to the error using errors.Wrap(err, "unable to override starter project cannot unmarshal
for example. Since we use json.Unmarshal
in other parts of the Devfile code when unmarshaling and it may be difficult to determine where the error is coming from.
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.
@cdrage json.Unmarshal specifies the field where the error is coming from, I think the returned error gives sufficient information about the fields.
https://github.com/golang/go/blob/master/src/encoding/json/decode.go#L134
e.g.
https://play.golang.org/p/uQUjwN3H35G
json: cannot unmarshal string into Go struct field starterProject.ProjectNo of type int
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.
Yes, but you should ideally wrap it as well since we use json.Unmarshal
in other sections of our code. So having a clear indicator that it's coming from unmarshaling the starter project makes it easier to find where the error is coming from...
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.
Thanks, Done.
pkg/devfile/parser/types_test.go
Outdated
wantErr bool | ||
}{ | ||
{ | ||
name: "case 1: override a starter project's fields", |
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.
nitpick, please capitalize case 1
, etc.
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.
override a starter projects field
@@ -895,8 +887,8 @@ func (co *CreateOptions) downloadProject(projectPassed string) error { | |||
return errors.Errorf("Project type not supported") | |||
} | |||
|
|||
log.Info("\nProject") | |||
downloadSpinner := log.Spinnerf("Downloading project from %s", logUrl) | |||
log.Info("\nStarter Project") |
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.
Okay, we'll keep it as Starter Project. It looks kind of out of place, but that's just me. All below output seems to be starter project related only, so makes sense.
Codecov Report
@@ Coverage Diff @@
## master #3673 +/- ##
==========================================
+ Coverage 44.15% 44.19% +0.04%
==========================================
Files 139 139
Lines 13345 13388 +43
==========================================
+ Hits 5892 5917 +25
- Misses 6874 6888 +14
- Partials 579 583 +4
Continue to review full report at Codecov.
|
6be314c
to
f0fceab
Compare
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.
New changes LGTM! Thanks @adisky
/approve
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: cdrage The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
What type of PR is this?
What does does this PR do / why we need it:
Implement Starter Project, and also interactive mode for the same
Which issue(s) this PR fixes:
Fixes #3263
PR acceptance criteria:
Unit test (Updated project tests for starter project)
Integration test (Tests were already added for
--starter
flag)Documentation
How to test changes / Special notes to the reviewer:
odo create --starter
, should download starter project from devfileodo create
, In interactive mode should ask to download starter projects.