-
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
Personalize devfile #5467
Personalize devfile #5467
Conversation
✔️ Deploy Preview for odo-docusaurus-preview canceled. 🔨 Explore the source changes: ff7726c 🔍 Inspect the deploy log: https://app.netlify.com/sites/odo-docusaurus-preview/deploys/62171b946465700007c2e1e0 |
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 really like how this code is articulated 🚀
Some remarks around documenting and testing it
pkg/init/asker/asker.go
Outdated
return selectContainerAnswer, nil | ||
} | ||
|
||
type ContainerConfiguration struct { |
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 would be helpful to have these types definitions into the asker/interface.go
file, as they are part of the interface definition, and to document them, so the documentation reader can understand how data is exchanged with the methods.
pkg/init/backend/interactive.go
Outdated
return err | ||
} | ||
|
||
if configOps.Ops == "Delete" && configOps.Kind == "Port" { |
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.
Could we do this switch with switch/case instead of if/else, so the reader is sure there is no other parameters than Ops and 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.
I am not sure if f3c7cf4 is what you meant, let me know if not.
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.
this syntax is pretty similar to the if/else, as the content of the case
is free.
I was thinking of this form, which reduces the possibilities in the cases (pseudo-code):
switch Ops {
case "Delete":
switch Kind:
case "Port":
[...]
case "EnvVar":
[...]
pkg/init/asker/asker.go
Outdated
Envs map[string]string | ||
} | ||
|
||
type ContainerMap struct { |
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.
This name is not speaking to me, could it be something similar to OperationOnContainer
instead?
pkg/init/asker/asker.go
Outdated
|
||
// AskPersonalizeConfiguration asks the configuration user wants to change | ||
func (o *Survey) AskPersonalizeConfiguration(configuration ContainerConfiguration) (ContainerMap, error) { | ||
options := []string{ |
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.
If you want to run unit test on building the options/tracker, it would be helpful to extract the first part of this method to a specific method that builds options/tracker based on configuration
, so you can test the options/tracker content based on different ports/envs.
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.
So, writing a method proved to be a pain for me while writing unit test for PersonalizeDevfileconfig
method of interactive.go
. Since it's purely logical/mathematical, I decided to write a function, and testing shouldn't be difficult.
Signed-off-by: Parthvi Vala <[email protected]>
Signed-off-by: Parthvi Vala <[email protected]>
0e8e1f5
to
eaab1fe
Compare
😄 I can't take the whole credit, Tomas's prototype did most work. @feloy I am having a hard time getting env var related unit tests to pass, can you help me with those? |
eaab1fe
to
963904c
Compare
You seem pretty close. The function For example:
|
I would prefer explicit args and calls because we return different result for different set of args. What I don;t understand is why it works for Port, but not Env Var! Edit: But you're right, using |
Signed-off-by: Parthvi Vala <[email protected]>
963904c
to
823d5b5
Compare
…is interactive mode
Signed-off-by: Parthvi Vala <[email protected]>
2a790fa
to
8410eae
Compare
pkg/init/backend/interactive.go
Outdated
func PrintConfiguration(config asker.DevfileConfiguration) { | ||
color.New(color.Bold, color.FgGreen).Println("Current component configuration:") | ||
|
||
for key, container := range config { |
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.
config
being a map, the elements will be rendered in a random order every time. I think it could be more readable by sorting the keys first
@@ -104,3 +106,149 @@ func (o *InteractiveBackend) PersonalizeName(devfile parser.DevfileObj, flags ma | |||
} | |||
return devfile.SetMetadataName(name) | |||
} | |||
|
|||
func (o *InteractiveBackend) PersonalizeDevfileconfig(devfileobj parser.DevfileObj) 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.
As discussed with Tomas on Slack, could you pass the devfile data only here, and execute devfileobj.WriteYamlDevfile()
at the CLI level, so we remove the Filesystem dependency for this method?
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 feel it makes more sense to keep things as is. There is PersonalizeName
as well that has filesystem dependency, to be consistent with it, I think current code should work just fine.
pkg/init/backend/interactive.go
Outdated
@@ -211,12 +212,18 @@ func (o *InteractiveBackend) PersonalizeDevfileconfig(devfileobj parser.DevfileO | |||
func PrintConfiguration(config asker.DevfileConfiguration) { | |||
color.New(color.Bold, color.FgGreen).Println("Current component configuration:") | |||
|
|||
for key, container := range config { | |||
keys := make([]string, len(config)) |
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.
Doing this, you get a slice with n elemens already on it, and later with append you add new ones: you will finish with 2*n elements.
Either you keep this make and use keys[i] = key, or you can use make([]string, 0, len(config))
to use append.
Signed-off-by: Parthvi Vala <[email protected]>
ad3f8ad
to
ff7726c
Compare
Kudos, SonarCloud Quality Gate passed! 0 Bugs No Coverage information |
/retest
|
Thanks for this work @valaparthvi |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: feloy 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 |
* Fix: Ask for devfile personalization * Update devfile library Signed-off-by: Parthvi Vala <[email protected]> * Add todo * Print live configuration, make it work * Run mockgen script Signed-off-by: Parthvi Vala <[email protected]> * TODO * Add missing mock methods * Add review suggestions * Add mock methods * Add unit tests * Add mock methods post rebase * Fixes post rebase Signed-off-by: Parthvi Vala <[email protected]> * Review, only run devfile personalization if the dir is not empty and is interactive mode * Mock methods * Fix unit tests Signed-off-by: Parthvi Vala <[email protected]> * Review Signed-off-by: Parthvi Vala <[email protected]>
What type of PR is this:
/kind feature
What does this PR do / why we need it:
This PR allows user to personalize their devfile by adding/removing port, and environment variable.
Which issue(s) this PR fixes:
Fixes #5423
PR acceptance criteria:
Unit test
Integration test
Documentation
How to test changes / Special notes to the reviewer: