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 preference not taken into account for odo version #6415

Merged
merged 4 commits into from
Dec 15, 2022

Conversation

feloy
Copy link
Contributor

@feloy feloy commented Dec 15, 2022

What type of PR is this:

/kind bug

What does this PR do / why we need it:

This PR adds the PREFERNECE dependency to odo version, and creates a CommandGroup abstraction to avoid this error occurs again.

Which issue(s) this PR fixes:

odo version can use the Timeout value defined in the odo preferences, but this value were never taken into account, because the PREFERENCE dependency were overwritten when setting the command group.

Fixes #6417

PR acceptance criteria:

  • Unit test

  • Integration test

  • Documentation

How to test changes / Special notes to the reviewer:

@netlify
Copy link

netlify bot commented Dec 15, 2022

Deploy Preview for odo-docusaurus-preview ready!

Name Link
🔨 Latest commit c934f19
🔍 Latest deploy log https://app.netlify.com/sites/odo-docusaurus-preview/deploys/639b154836789000071e99bf
😎 Deploy Preview https://deploy-preview-6415--odo-docusaurus-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@openshift-ci openshift-ci bot added the kind/bug Categorizes issue or PR as related to a bug. label Dec 15, 2022
@openshift-ci openshift-ci bot requested review from kadel and valaparthvi December 15, 2022 09:57
@odo-robot
Copy link

odo-robot bot commented Dec 15, 2022

OpenShift Tests on commit e96f123 finished with errors.
View logs: TXT HTML

@odo-robot
Copy link

odo-robot bot commented Dec 15, 2022

NoCluster Tests on commit e96f123 finished successfully.
View logs: TXT HTML

@odo-robot
Copy link

odo-robot bot commented Dec 15, 2022

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

@odo-robot
Copy link

odo-robot bot commented Dec 15, 2022

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

@odo-robot
Copy link

odo-robot bot commented Dec 15, 2022

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

@odo-robot
Copy link

odo-robot bot commented Dec 15, 2022

Kubernetes Tests on commit e96f123 finished successfully.
View logs: TXT HTML

Copy link
Member

@rm3l rm3l left a comment

Choose a reason for hiding this comment

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

Good catch - thanks!

I'm wondering in this case if we shouldn't make the preference client a mandatory dependency, and explicitly fail if this is not the case.
I can see that preferenceInfo#GetTimeout() already falls back to DefaultTimeout if there is no timeout setting defined. So we could be more strict by expecting the Preference client dependency to be there in VersionOptions#Complete.
To be clear, I am just thinking of the following diff:

diff --git a/pkg/odo/cli/version/version.go b/pkg/odo/cli/version/version.go
index 180c8b58a..e31226808 100644
--- a/pkg/odo/cli/version/version.go
+++ b/pkg/odo/cli/version/version.go
@@ -5,13 +5,11 @@ import (
        "fmt"
        "os"
        "strings"
-       "time"
 
        "github.com/redhat-developer/odo/pkg/kclient"
        "github.com/redhat-developer/odo/pkg/odo/cmdline"
        "github.com/redhat-developer/odo/pkg/odo/genericclioptions"
        "github.com/redhat-developer/odo/pkg/odo/genericclioptions/clientset"
-       "github.com/redhat-developer/odo/pkg/preference"
        odoversion "github.com/redhat-developer/odo/pkg/version"
 
        "github.com/spf13/cobra"
@@ -63,16 +61,7 @@ func (o *VersionOptions) Complete(ctx context.Context, cmdline cmdline.Cmdline,
                client, err := kclient.New()
 
                if err == nil {
-                       // checking the value of timeout in preference
-                       var timeout time.Duration
-                       if o.clientset.PreferenceClient != nil {
-                               timeout = o.clientset.PreferenceClient.GetTimeout()
-                       } else {
-                               // the default timeout will be used
-                               // when the value is not readable from preference
-                               timeout = preference.DefaultTimeout
-                       }
-                       o.serverInfo, err = client.GetServerVersion(timeout)
+                       o.serverInfo, err = client.GetServerVersion(o.clientset.PreferenceClient.GetTimeout())
                        if err != nil {
                                klog.V(4).Info("unable to fetch the server version: ", err)
                        }

At least, this would explicitly panic if the Preference Client is not there and allow to catch this issue if it occurs again, IMO.

What do you think?

@feloy
Copy link
Contributor Author

feloy commented Dec 15, 2022

Good catch - thanks!

I'm wondering in this case if we shouldn't make the preference client a mandatory dependency, and explicitly fail if this is not the case. I can see that preferenceInfo#GetTimeout() already falls back to DefaultTimeout if there is no timeout setting defined. So we could be more strict by expecting the Preference client dependency to be there in VersionOptions#Complete. To be clear, I am just thinking of the following diff:

diff --git a/pkg/odo/cli/version/version.go b/pkg/odo/cli/version/version.go
index 180c8b58a..e31226808 100644
--- a/pkg/odo/cli/version/version.go
+++ b/pkg/odo/cli/version/version.go
@@ -5,13 +5,11 @@ import (
        "fmt"
        "os"
        "strings"
-       "time"
 
        "github.com/redhat-developer/odo/pkg/kclient"
        "github.com/redhat-developer/odo/pkg/odo/cmdline"
        "github.com/redhat-developer/odo/pkg/odo/genericclioptions"
        "github.com/redhat-developer/odo/pkg/odo/genericclioptions/clientset"
-       "github.com/redhat-developer/odo/pkg/preference"
        odoversion "github.com/redhat-developer/odo/pkg/version"
 
        "github.com/spf13/cobra"
@@ -63,16 +61,7 @@ func (o *VersionOptions) Complete(ctx context.Context, cmdline cmdline.Cmdline,
                client, err := kclient.New()
 
                if err == nil {
-                       // checking the value of timeout in preference
-                       var timeout time.Duration
-                       if o.clientset.PreferenceClient != nil {
-                               timeout = o.clientset.PreferenceClient.GetTimeout()
-                       } else {
-                               // the default timeout will be used
-                               // when the value is not readable from preference
-                               timeout = preference.DefaultTimeout
-                       }
-                       o.serverInfo, err = client.GetServerVersion(timeout)
+                       o.serverInfo, err = client.GetServerVersion(o.clientset.PreferenceClient.GetTimeout())
                        if err != nil {
                                klog.V(4).Info("unable to fetch the server version: ", err)
                        }

At least, this would explicitly panic if the Preference Client is not there and allow to catch this issue if it occurs again, IMO.

What do you think?

You are right, I'm also annoyed by this test on the client, which was hiding the error.

I'll apply your patch.
Thanks

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

No Coverage information No Coverage information
0.0% 0.0% Duplication

`
)

func TestOdoHelp(t *testing.T) {
Copy link
Member

@rm3l rm3l Dec 15, 2022

Choose a reason for hiding this comment

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

Thanks for this test 😍 💯

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. Required by Prow. label Dec 15, 2022
@feloy
Copy link
Contributor Author

feloy commented Dec 15, 2022

/override windows-integration-test/Windows-test
Flaky e2e test

 [FAILED] [208.773 seconds]
E2E Test
C:/Users/Administrator.ANSIBLE-TEST-VS/2778/tests/e2escenarios/e2e_test.go:19
  starting with non-empty Directory add Binding
  C:/Users/Administrator.ANSIBLE-TEST-VS/2778/tests/e2escenarios/e2e_test.go:279
    [It] should verify developer workflow of using binding as env in innerloop
    C:/Users/Administrator.ANSIBLE-TEST-VS/2778/tests/e2escenarios/e2e_test.go:321

@openshift-ci
Copy link

openshift-ci bot commented Dec 15, 2022

@feloy: Overrode contexts on behalf of feloy: windows-integration-test/Windows-test

In response to this:

/override windows-integration-test/Windows-test
Flaky e2e test

[FAILED] [208.773 seconds]
E2E Test
C:/Users/Administrator.ANSIBLE-TEST-VS/2778/tests/e2escenarios/e2e_test.go:19
 starting with non-empty Directory add Binding
 C:/Users/Administrator.ANSIBLE-TEST-VS/2778/tests/e2escenarios/e2e_test.go:279
   [It] should verify developer workflow of using binding as env in innerloop
   C:/Users/Administrator.ANSIBLE-TEST-VS/2778/tests/e2escenarios/e2e_test.go:321

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@feloy
Copy link
Contributor Author

feloy commented Dec 15, 2022

/override OpenShift-Integration-tests/OpenShift-Integration-tests
Unrelated flaky test

[FAILED] [238.740 seconds]
odo dev command tests
/go/odo_1/tests/integration/cmd_dev_test.go:31
  port-forwarding for the component
  /go/odo_1/tests/integration/cmd_dev_test.go:595
    when devfile has single endpoint
    /go/odo_1/tests/integration/cmd_dev_test.go:596
      when running odo dev
      /go/odo_1/tests/integration/cmd_dev_test.go:605
        when modifying memoryLimit for container in Devfile [BeforeEach]
        /go/odo_1/tests/integration/cmd_dev_test.go:639
          should expose the endpoint on localhost
          /go/odo_1/tests/integration/cmd_dev_test.go:655

@openshift-ci
Copy link

openshift-ci bot commented Dec 15, 2022

@feloy: Overrode contexts on behalf of feloy: OpenShift-Integration-tests/OpenShift-Integration-tests

In response to this:

/override OpenShift-Integration-tests/OpenShift-Integration-tests
Unrelated flaky test

[FAILED] [238.740 seconds]
odo dev command tests
/go/odo_1/tests/integration/cmd_dev_test.go:31
 port-forwarding for the component
 /go/odo_1/tests/integration/cmd_dev_test.go:595
   when devfile has single endpoint
   /go/odo_1/tests/integration/cmd_dev_test.go:596
     when running odo dev
     /go/odo_1/tests/integration/cmd_dev_test.go:605
       when modifying memoryLimit for container in Devfile [BeforeEach]
       /go/odo_1/tests/integration/cmd_dev_test.go:639
         should expose the endpoint on localhost
         /go/odo_1/tests/integration/cmd_dev_test.go:655

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@openshift-merge-robot openshift-merge-robot merged commit 1807939 into redhat-developer:main Dec 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

Timeout not taken into account during odo version
3 participants