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

Preference cleanup (1/n) #5822

Merged
merged 16 commits into from
Jun 23, 2022

Conversation

valaparthvi
Copy link
Contributor

What type of PR is this:
/kind cleanup

What does this PR do / why we need it:
This PR cleans the preference pkg with the following changes:

  1. Use time.Duration instead of int for time related preferences.
  2. Modify the success messages for set, and unset.

Which issue(s) this PR fixes:

Fixes part of #5535

PR acceptance criteria:

  • Unit test

  • Integration test

  • Documentation

How to test changes / Special notes to the reviewer:

  1. odo preference set pushtimeout 4m
  2. odo preference unset pushtimeout

@openshift-ci
Copy link

openshift-ci bot commented Jun 14, 2022

@valaparthvi: The label(s) kind/cleanup cannot be applied, because the repository doesn't have them.

In response to this:

What type of PR is this:
/kind cleanup

What does this PR do / why we need it:
This PR cleans the preference pkg with the following changes:

  1. Use time.Duration instead of int for time related preferences.
  2. Modify the success messages for set, and unset.

Which issue(s) this PR fixes:

Fixes part of #5535

PR acceptance criteria:

  • Unit test

  • Integration test

  • Documentation

How to test changes / Special notes to the reviewer:

  1. odo preference set pushtimeout 4m
  2. odo preference unset pushtimeout

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.

@netlify
Copy link

netlify bot commented Jun 14, 2022

Deploy Preview for odo-docusaurus-preview canceled.

Name Link
🔨 Latest commit ddb6efc
🔍 Latest deploy log https://app.netlify.com/sites/odo-docusaurus-preview/deploys/62b423924bedc60008e932ea

@openshift-ci openshift-ci bot requested review from anandrkskd and rm3l June 14, 2022 05:47
@odo-robot
Copy link

odo-robot bot commented Jun 14, 2022

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

@odo-robot
Copy link

odo-robot bot commented Jun 14, 2022

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

@odo-robot
Copy link

odo-robot bot commented Jun 14, 2022

Windows Tests (OCP) on commit ead48d3 finished successfully.
View logs: TXT HTML

@odo-robot
Copy link

odo-robot bot commented Jun 14, 2022

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

@odo-robot
Copy link

odo-robot bot commented Jun 14, 2022

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

@valaparthvi valaparthvi mentioned this pull request Jun 14, 2022
7 tasks
pkg/odo/cli/preference/view_test.go Outdated Show resolved Hide resolved
pkg/util/defaults.go Outdated Show resolved Hide resolved
@valaparthvi valaparthvi requested review from kadel and dharmit June 14, 2022 13:22
@feloy
Copy link
Contributor

feloy commented Jun 15, 2022

/lgtm

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

/retest-required

@valaparthvi
Copy link
Contributor Author

/test unit

@valaparthvi
Copy link
Contributor Author

/retest-required

@valaparthvi
Copy link
Contributor Author

/override ci/prow/unit
/override ci/prow/v4.10-integration-e2e

IBM tests pass.

@openshift-ci
Copy link

openshift-ci bot commented Jun 16, 2022

@valaparthvi: Overrode contexts on behalf of valaparthvi: ci/prow/unit, ci/prow/v4.10-integration-e2e

In response to this:

/override ci/prow/unit
/override ci/prow/v4.10-integration-e2e

IBM tests pass.

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

feloy commented Jun 17, 2022

When executing:

$ odo preference set PushTimeout 1
 ✗  unable to set "pushtimeout" to "1", value must be an integer

the message doesn't seem correct. It should be instead "value should be a duration"

@openshift-ci openshift-ci bot removed the lgtm Indicates that a PR is ready to be merged. Required by Prow. label Jun 17, 2022
@feloy
Copy link
Contributor

feloy commented Jun 17, 2022

I can see this pattern in several places, which gives the wrong result:

time.Duration(o.clientset.PreferenceClient.GetTimeout()) * time.Second

Is should be:

o.clientset.PreferenceClient.GetTimeout()

@@ -63,7 +64,7 @@ func (o *VersionOptions) Complete(cmdline cmdline.Cmdline, args []string) (err e
// checking the value of timeout in preference
var timeout time.Duration
if o.clientset.PreferenceClient != nil {
timeout = time.Duration(o.clientset.PreferenceClient.GetTimeout()) * time.Second
timeout = o.clientset.PreferenceClient.GetTimeout() * time.Second
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think you need to multiply by 1s (same in line 70)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right, I missed this one.

@valaparthvi valaparthvi force-pushed the preference-cleanup branch 2 times, most recently from 397e472 to d21547f Compare June 17, 2022 11:03
@feloy feloy closed this Jun 17, 2022
@feloy feloy reopened this Jun 17, 2022
@valaparthvi
Copy link
Contributor Author

/override ci/prow/v4.10-integration-e2e
/override ci/prow/unit

@openshift-ci
Copy link

openshift-ci bot commented Jun 20, 2022

@valaparthvi: Overrode contexts on behalf of valaparthvi: ci/prow/unit, ci/prow/v4.10-integration-e2e

In response to this:

/override ci/prow/v4.10-integration-e2e
/override ci/prow/unit

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.

@valaparthvi valaparthvi requested review from rm3l and feloy June 21, 2022 06:20
}
if typedval < 0 {
return errors.New("cannot set timeout to less than 0")
typedval, err := time.ParseDuration(value)
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 convert the old value (in seconds) to the new one (in duration), you could test if the value is a pure integer here. If it is, you could consider it is an old value, and convert it in n* second duration.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, you could factorize the code for all the duration fields with a function

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right, this is what you meant by the migration plan? Thanks for catching this!

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, that's about the migration plan I was talking about

return errors.New("cannot set timeout to less than 0")
typedval, err := time.ParseDuration(value)
if err != nil || typedval < minimumDurationValue {
return fmt.Errorf("unable to set %q to %q, value must be a positive Duration (e.g. 4s, 5m, 1h); minimum value: 1s", parameter, value)
Copy link
Member

@rm3l rm3l Jun 21, 2022

Choose a reason for hiding this comment

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

Wondering if the error we return here should not also wrap the original err returned by time.ParseDuration, if any. This way, it would be reported to the user. What do you think?

Because if I enter a duration but with a unit suffix (like days) not supported by time.ParseDuration, I find our error message not much helpful in understanding the issue:

❯ odo preference set PushTimeout 1d 
 ✗  unable to set "pushtimeout" to "1d", value must be a positive Duration (e.g. 4s, 5m, 1h); minimum value: 1s

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Wondering if the error we return here should not also wrap the original err returned by time.ParseDuration, if any. This way, it would be reported to the user. What do you think?

You're right, I'll get to this.


// PushTimeoutSettingDescription adds a description for PushTimeout
var PushTimeoutSettingDescription = fmt.Sprintf("PushTimeout (in seconds) for waiting for a Pod to come up (Default: %d)", DefaultPushTimeout)
var PushTimeoutSettingDescription = fmt.Sprintf("PushTimeout (in Duration) for waiting for a Pod to come up (Default: %s)", DefaultPushTimeout)
Copy link
Member

Choose a reason for hiding this comment

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

Surely nitpicking ^^, but would it be possible to change the format string? I found it a bit weird that this shows up as 4m0s in the help message. Same thing for the default values of the other durations, except for Timeout:

❯ odo help preference                                                                                                                                                                                                                                                            
Modifies odo specific configuration settings within the global preference file.                                                                                                                                                                                                  
                                                                                                                                                                                                                                                                                 
                                                                                                                                                                                                                                                                                 
Available Global Parameters:                                                                                                                                                                                                                                                     
 ConsentTelemetry - If true, odo will collect telemetry for the user's odo usage (Default: false)                                                                                                                                                                                
                    For more information: https://developers.redhat.com/article/tool-data-collection                                                                                                                                                                             
 Ephemeral - If true, odo will create an emptyDir volume to store source code (Default: true)                                                                                                                                                                                    
 PushTimeout - PushTimeout (in Duration) for waiting for a Pod to come up (Default: 4m0s)                                                                                                                                                                                        
 RegistryCacheTime - For how long (in Duration) odo will cache information from the Devfile registry (Default: 15m0s)                                                                                                                                                            
 Timeout - Timeout (in Duration) for cluster server connection check (Default: 1s)                                                                                                                                                                                               
 UpdateNotification - Flag to control if an update notification is shown or not (Default: true)                                                                                                                                                                     

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That format is how golang parses duration. I'll have to see if that can be modified, but another way would be to parse everything into second.

@valaparthvi
Copy link
Contributor Author

valaparthvi commented Jun 23, 2022

ddb6efc includes

  • @feloy - a warning as a migration plan from v2 to v3, see the integration test on how to reproduce it; it still takes the value as a ns, and prints out warning a bunch of times since newPreferenceInfo is called at least 4 times, I understand that it is annoying and not a good user experience, but I think the more annoyed you are, the more likely you are to make the change. I also did not implement the part about checking if the value is an int while setting preference, because I think it's counterintuitive to the first part of this statement. If we do not want to parse the existing int value, it also makes sense to not accept it in the first place even if it eventually converted to a time.Second.

  • @rm3l - a better error message when setting the preference value fails due to an incompatible format or any other cause

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

No Coverage information No Coverage information
0.4% 0.4% Duplication

@feloy
Copy link
Contributor

feloy commented Jun 23, 2022

/approve

@openshift-ci
Copy link

openshift-ci bot commented Jun 23, 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 Jun 23, 2022
@valaparthvi
Copy link
Contributor Author

/override ci/prow/v4.10-integration-e2e

@openshift-ci
Copy link

openshift-ci bot commented Jun 23, 2022

@valaparthvi: Overrode contexts on behalf of valaparthvi: ci/prow/v4.10-integration-e2e

In response to this:

/override ci/prow/v4.10-integration-e2e

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.

@valaparthvi valaparthvi requested a review from rm3l June 23, 2022 11:33
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.

Thanks for the changes!

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

feloy commented Jun 23, 2022

/override ci/prow/unit
Pass on IBM

@openshift-ci
Copy link

openshift-ci bot commented Jun 23, 2022

@feloy: Overrode contexts on behalf of feloy: ci/prow/unit

In response to this:

/override ci/prow/unit
Pass on IBM

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-ci openshift-ci bot merged commit b1fbfaa into redhat-developer:main Jun 23, 2022
cdrage pushed a commit to cdrage/odo that referenced this pull request Aug 31, 2022
* Preference(Timeout) int > time.Duration

* Fix odo preference --help for unset examples

* Preference(PushTimeout) int > time.Duration

* Change set, and unset messages

* Preference(RegistryCacheTime) int > time.Duration

* use cobra.ExactArgs for set, and unset

* mockgen

* Unit tests and integration tests

* Fix unit test failure

* Update k8s.io/utils pkg

* Philippe's review

* Fix error message

* Philippe's review

Signed-off-by: Parthvi Vala <[email protected]>

* Add minimum acceptable value for preferences accepting time.Difference type

* Fix unit test failure

Signed-off-by: Parthvi Vala <[email protected]>

* Add migration plan with a warning, add better error message for incompatible formats

Signed-off-by: Parthvi Vala <[email protected]>
@dharmit dharmit mentioned this pull request Sep 9, 2022
3 tasks
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. 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.

3 participants