-
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
Preference cleanup (1/n) #5822
Preference cleanup (1/n) #5822
Conversation
@valaparthvi: The label(s) In response to this:
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. |
✅ Deploy Preview for odo-docusaurus-preview canceled.
|
/lgtm |
/retest-required |
/test unit |
/retest-required |
/override ci/prow/unit IBM tests pass. |
@valaparthvi: Overrode contexts on behalf of valaparthvi: ci/prow/unit, ci/prow/v4.10-integration-e2e In response to this:
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. |
When executing:
the message doesn't seem correct. It should be instead "value should be a duration" |
I can see this pattern in several places, which gives the wrong result:
Is should be:
|
pkg/odo/cli/version/version.go
Outdated
@@ -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 |
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 don't think you need to multiply by 1s (same in line 70)
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.
You're right, I missed this one.
397e472
to
d21547f
Compare
d21547f
to
36cc352
Compare
Signed-off-by: Parthvi Vala <[email protected]>
Signed-off-by: Parthvi Vala <[email protected]>
5335bf0
to
51cae65
Compare
/override ci/prow/v4.10-integration-e2e |
@valaparthvi: Overrode contexts on behalf of valaparthvi: ci/prow/unit, ci/prow/v4.10-integration-e2e In response to this:
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. |
pkg/preference/implem.go
Outdated
} | ||
if typedval < 0 { | ||
return errors.New("cannot set timeout to less than 0") | ||
typedval, err := time.ParseDuration(value) |
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 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.
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.
Also, you could factorize the code for all the duration fields with a function
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.
You're right, this is what you meant by the migration plan? Thanks for catching this!
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.
Yes, that's about the migration plan I was talking about
pkg/preference/implem.go
Outdated
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) |
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.
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
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.
Wondering if the error we return here should not also wrap the original
err
returned bytime.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) |
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.
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)
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.
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
.
ddb6efc includes
|
…patible formats Signed-off-by: Parthvi Vala <[email protected]>
3f53cdf
to
ddb6efc
Compare
Kudos, SonarCloud Quality Gate passed!
|
/approve |
[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 |
/override ci/prow/v4.10-integration-e2e |
@valaparthvi: Overrode contexts on behalf of valaparthvi: ci/prow/v4.10-integration-e2e In response to this:
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. |
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.
Thanks for the changes!
/override ci/prow/unit |
@feloy: Overrode contexts on behalf of feloy: ci/prow/unit In response to this:
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. |
* 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]>
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:
time.Duration
instead ofint
for time related preferences.set
, andunset
.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:
odo preference set pushtimeout 4m
odo preference unset pushtimeout