Skip to content
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

Merged

Conversation

valaparthvi
Copy link
Contributor

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:

@openshift-ci openshift-ci bot added the kind/feature Categorizes issue as a feature request. For PRs, that means that the PR is the implementation label Feb 17, 2022
@netlify
Copy link

netlify bot commented Feb 17, 2022

✔️ 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

@valaparthvi valaparthvi marked this pull request as draft February 17, 2022 16:52
@openshift-ci openshift-ci bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. Required by Prow. label Feb 17, 2022
@odo-robot
Copy link

odo-robot bot commented Feb 17, 2022

Validate Tests on commit 58a3b27 finished successfully.
View logs: TXT HTML

@odo-robot
Copy link

odo-robot bot commented Feb 17, 2022

Unit Tests on commit 58a3b27 finished successfully.
View logs: TXT HTML

@odo-robot
Copy link

odo-robot bot commented Feb 17, 2022

OpenShift Tests on commit 58a3b27 finished successfully.
View logs: TXT HTML

@odo-robot
Copy link

odo-robot bot commented Feb 17, 2022

Kubernetes Tests on commit 58a3b27 finished with errors.
View logs: TXT HTML

@odo-robot
Copy link

odo-robot bot commented Feb 17, 2022

Windows Tests (OCP) on commit 58a3b27 finished with errors.
View logs: TXT HTML

@valaparthvi valaparthvi marked this pull request as ready for review February 22, 2022 12:03
@openshift-ci openshift-ci bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. Required by Prow. label Feb 22, 2022
@openshift-ci openshift-ci bot requested review from cdrage and dharmit February 22, 2022 12:03
Copy link
Contributor

@feloy feloy left a 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

return selectContainerAnswer, nil
}

type ContainerConfiguration struct {
Copy link
Contributor

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.

return err
}

if configOps.Ops == "Delete" && configOps.Kind == "Port" {
Copy link
Contributor

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

Copy link
Contributor Author

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.

Copy link
Contributor

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":
        [...]

Envs map[string]string
}

type ContainerMap struct {
Copy link
Contributor

@feloy feloy Feb 22, 2022

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?


// AskPersonalizeConfiguration asks the configuration user wants to change
func (o *Survey) AskPersonalizeConfiguration(configuration ContainerConfiguration) (ContainerMap, error) {
options := []string{
Copy link
Contributor

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.

Copy link
Contributor Author

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.

@openshift-ci openshift-ci bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. Required by Prow. label Feb 23, 2022
@openshift-ci openshift-ci bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. Required by Prow. label Feb 23, 2022
@valaparthvi
Copy link
Contributor Author

valaparthvi commented Feb 23, 2022

I really like how this code is articulated rocket

😄 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?

@feloy
Copy link
Contributor

feloy commented Feb 23, 2022

I really like how this code is articulated rocket

smile 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?

You seem pretty close. The function gomock.Any() will help if you don't need to assert what is passed to the method you are mocking:

For example:

client.EXPECT().AskPersonalizeConfiguration(gomock.Any())

@valaparthvi
Copy link
Contributor Author

valaparthvi commented Feb 23, 2022

I really like how this code is articulated rocket

smile 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?

You seem pretty close. The function gomock.Any() will help if you don't need to assert what is passed to the method you are mocking:

For example:

client.EXPECT().AskPersonalizeConfiguration(gomock.Any())

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 gomock.Any() second time fixed the failing tests. I have my doubts about it being a false positive, but then checkResults work as expected, so I will go with it for now.

Signed-off-by: Parthvi Vala <[email protected]>
func PrintConfiguration(config asker.DevfileConfiguration) {
color.New(color.Bold, color.FgGreen).Println("Current component configuration:")

for key, container := range config {
Copy link
Contributor

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 {
Copy link
Contributor

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?

Copy link
Contributor Author

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.

@@ -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))
Copy link
Contributor

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]>
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 4 Code Smells

No Coverage information No Coverage information
0.5% 0.5% Duplication

@valaparthvi
Copy link
Contributor Author

/retest

�[32m•�[0m�[32m•�[0m�[32m•�[0m�[32m•�[0m�[32m•�[0m�[32m•�[0m�[32m•�[0m�[32m•�[0m�[32m•�[0m�[32m•�[0m�[32m•�[0m�[32m•�[0m�[32m•�[0m�[32m•�[0m�[32m•�[0m�[32m•�[0m�[32m•�[0m�[32m•�[0m�[32m•�[0m
�[90m------------------------------�[0m
�[91m�[1m• Failure [45.731 seconds]�[0m
odo devfile push command tests
�[90m/go/src/github.com/redhat-developer/odo/tests/integration/devfile/cmd_devfile_push_test.go:18�[0m
  when Create and push java-springboot component
  �[90m/go/src/github.com/redhat-developer/odo/tests/integration/devfile/cmd_devfile_push_test.go:791�[0m
    �[91m�[1mshould execute default build and run commands correctly [It]�[0m
    �[90m/go/src/github.com/redhat-developer/odo/tests/integration/devfile/cmd_devfile_push_test.go:800�[0m

    �[91mUnexpected error:
        <*errors.errorString | 0xc00061c510>: {
            s: "cmd [ps -ef] failed with error Signal 23 (URG) caught by ps (3.3.15).\nps:ps/display.c:66: please report this bug\ncommand terminated with exit code 1\n on pod loyezq-app-5cc8599984-glff7",
        }
        cmd [ps -ef] failed with error Signal 23 (URG) caught by ps (3.3.15).
        ps:ps/display.c:66: please report this bug
        command terminated with exit code 1
         on pod loyezq-app-5cc8599984-glff7
    occurred�[0m

    /go/src/github.com/redhat-developer/odo/tests/integration/devfile/cmd_devfile_push_test.go:824

@feloy
Copy link
Contributor

feloy commented Feb 24, 2022

Thanks for this work @valaparthvi
/lgtm
/approve

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. Required by Prow. label Feb 24, 2022
@openshift-ci
Copy link

openshift-ci bot commented Feb 24, 2022

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. Required by Prow. label Feb 24, 2022
@openshift-merge-robot openshift-merge-robot merged commit 39c8e40 into redhat-developer:main Feb 24, 2022
cdrage pushed a commit to cdrage/odo that referenced this pull request Aug 31, 2022
* 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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. Required by Prow. kind/feature Categorizes issue as a feature request. For PRs, that means that the PR is the implementation lgtm Indicates that a PR is ready to be merged. Required by Prow.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ask for devfile personalization
3 participants