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

Fix odo config view #5234

Merged

Conversation

anandrkskd
Copy link
Contributor

@anandrkskd anandrkskd commented Nov 18, 2021

Signed-off-by: anandrkskd anandrkskd@gmail.com

What type of PR is this?
/kind bug

What does this PR do / why we need it:
Current odo config view fails if we run this command in a dir not containing devfile.
This PR fixes odo config view command for any directory not containing devfile.

Which issue(s) this PR fixes:

Fixes #?

PR acceptance criteria:

How to test changes / Special notes to the reviewer:
Steps to test changes

make install
cd /path/to/dir
odo config view

How to Reproduce the failure

neo@matrix [11:07:42 PM] [~/work/demo] 
-> % ls    
nodejs-ex
neo@matrix [11:07:43 PM] [~/work/demo] 
-> % odo config view
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0xb8 pc=0x2832c23]

goroutine 1 [running]:
github.com/devfile/library/pkg/devfile/parser.DevfileObj.GetMetadataName(...)
   /builddir/build/BUILD/gocode/src/github.com/openshift/odo/vendor/github.com/devfile/library/pkg/devfile/parser/configurables.go:147
github.com/openshift/odo/pkg/component.ToDevfileRepresentation(0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
   /builddir/build/BUILD/gocode/src/github.com/openshift/odo/pkg/component/devfile_repr.go:12 +0xa3
github.com/openshift/odo/pkg/odo/cli/config.(*ViewOptions).Run(0xc0000220b0, 0xc0001afb80, 0x0, 0x0)
   /builddir/build/BUILD/gocode/src/github.com/openshift/odo/pkg/odo/cli/config/view.go:62 +0x145
github.com/openshift/odo/pkg/odo/genericclioptions.GenericRun(0x35c0680, 0xc0000220b0, 0xc0001afb80, 0x49a2488, 0x0, 0x0)
   /builddir/build/BUILD/gocode/src/github.com/openshift/odo/pkg/odo/genericclioptions/runnable.go:97 +0x479
github.com/openshift/odo/pkg/odo/cli/config.NewCmdView.func1(0xc0001afb80, 0x49a2488, 0x0, 0x0)
   /builddir/build/BUILD/gocode/src/github.com/openshift/odo/pkg/odo/cli/config/view.go:89 +0x5e
github.com/spf13/cobra.(*Command).execute(0xc0001afb80, 0x49a2488, 0x0, 0x0, 0xc0001afb80, 0x49a2488)
   /builddir/build/BUILD/gocode/src/github.com/openshift/odo/vendor/github.com/spf13/cobra/command.go:856 +0x2c2
github.com/spf13/cobra.(*Command).ExecuteC(0xc0003ee280, 0xc00005c0d8, 0x2ec1ec0, 0x49a2488)
   /builddir/build/BUILD/gocode/src/github.com/openshift/odo/vendor/github.com/spf13/cobra/command.go:960 +0x375
github.com/spf13/cobra.(*Command).Execute(...)
   /builddir/build/BUILD/gocode/src/github.com/openshift/odo/vendor/github.com/spf13/cobra/command.go:897
github.com/spf13/cobra.(*Command).ExecuteContext(...)
   /builddir/build/BUILD/gocode/src/github.com/openshift/odo/vendor/github.com/spf13/cobra/command.go:890
main.main()
   /builddir/build/BUILD/gocode/src/github.com/openshift/odo/cmd/odo/odo.go:70 +0x426
neo@matrix [11:07:51 PM] [~/work/demo] 

Signed-off-by: anandrkskd <anandrkskd@gmail.com>
@openshift-ci openshift-ci bot added the kind/bug Categorizes issue or PR as related to a bug. label Nov 18, 2021
@openshift-ci openshift-ci bot requested review from dharmit and feloy November 18, 2021 17:38
@dharmit
Copy link
Member

dharmit commented Nov 19, 2021

@anandrkskd that's a nice catch and looks like an elegant fix to me. I have just one question - do you think adding a test would help so that we don't end up having a regression some day? I am inclined to a "yes", but I'll leave it up to you.

And thanks for the code contribution! 👍🏾

@anandrkskd
Copy link
Contributor Author

do you think adding a test would help so that we don't end up having a regression some day?

I agree, I will add a test for this ASAP.

Signed-off-by: anandrkskd <anandrkskd@gmail.com>
Comment on lines +55 to +61
It("should pass if devfile is present in current dir", func() {
helper.Chdir(commonVar.Context)
cmpName := helper.RandString(6)
helper.Cmd("odo", "create", cmpName, "--devfile", helper.GetExamplePath("source", "devfiles", "nodejs", "devfile.yaml")).ShouldPass()
out := helper.Cmd("odo", "config", "view").ShouldPass().Out()
helper.MatchAllInOutput(out, []string{"runtime", "Memory: 1024Mi"})
})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO, it's sufficient to have failure test in this case because other parts of this test file are executing odo config view in some form, and hence the success case is being implicitly tested.

I'm more of "explicit is better than implicit" person, but every extra integration test adds to our already slow integration test suite, so I'm fine with implicit nature here.

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 think we should have this case as this is different from what we are testing in the other test case. Also, this test case will not take much time to execute, for me, it passed withing 6-8 seconds.

pkg/odo/cli/config/view.go Outdated Show resolved Hide resolved
Signed-off-by: anandrkskd <anandrkskd@gmail.com>
Signed-off-by: anandrkskd <anandrkskd@gmail.com>
pkg/odo/cli/config/view.go Outdated Show resolved Hide resolved
Signed-off-by: anandrkskd <anandrkskd@gmail.com>
@sonarcloud
Copy link

sonarcloud bot commented Nov 22, 2021

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 0 Code Smells

No Coverage information No Coverage information
2.3% 2.3% Duplication

@feloy
Copy link
Contributor

feloy commented Nov 22, 2021

/lgtm
/approve

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

openshift-ci bot commented Nov 22, 2021

[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 Nov 22, 2021
@openshift-merge-robot openshift-merge-robot merged commit 7f8efcc into redhat-developer:main Nov 22, 2021
anandrkskd added a commit to anandrkskd/odo that referenced this pull request Dec 7, 2021
* fix odo config view

Signed-off-by: anandrkskd <anandrkskd@gmail.com>

* add test for odo config view

Signed-off-by: anandrkskd <anandrkskd@gmail.com>

* use genericclioptions.New

Signed-off-by: anandrkskd <anandrkskd@gmail.com>

* update failcase check

Signed-off-by: anandrkskd <anandrkskd@gmail.com>

* remove commented code

Signed-off-by: anandrkskd <anandrkskd@gmail.com>
@anandrkskd anandrkskd deleted the fix-odo-config-view branch October 13, 2022 11:10
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/bug Categorizes issue or PR as related to a bug. 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.

None yet

4 participants