-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
Bugfix: Retention period is being sent to the API as 0 #5706
Conversation
It was failing with 0 context about which particular scenario failed and it wasn't logging the errors returned by the scenarios
Hi! Thanks for the pull request. Please ensure that this change is linked to an issue by mentioning an issue number in the description of the pull request. If this pull request would close the issue, please put the word 'Fixes' before the issue number somewhere in the pull request body. If this is a tiny change like fixing a typo, feel free to ignore this message. |
@@ -32,7 +32,7 @@ type createOptions struct { | |||
permissionsOptOut bool | |||
devContainerPath string | |||
idleTimeout time.Duration | |||
retentionPeriod time.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.
could you use a *time.Duration
instead? using pointers is a common pattern for optional types
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'm not sure if I can because the default argument of DurationVar
from the pflag library is of type time.Duration
so I can't pass in nil
. I'm open to suggestions if you have an idea of how this could be refactored.
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.
This is true but the library provides what you need to define flag funcs for your own types: https://pkg.go.dev/github.com/spf13/pflag#Var
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.
Here's how we approach *string
and *bool
flag value receivers in the codebase already:
Lines 12 to 16 in ec12d27
// NilStringFlag defines a new flag with a string pointer receiver. This is useful for differentiating | |
// between the flag being set to a blank value and the flag not being passed at all. | |
func NilStringFlag(cmd *cobra.Command, p **string, name string, shorthand string, usage string) *pflag.Flag { | |
return cmd.Flags().VarPF(newStringValue(p), name, shorthand, usage) | |
} |
While a pointer receiver is a valid way of differentiating between explicit empty value vs. flag not being set by the user, @reybard makes a good point that a custom flag receiver can be defined. If dealing with pointers proves to be convoluted, do not hesitate to make a custom value that wraps an underlying time.Duration
value in an object that also keeps track of whether the flag was explicitly set or not. 👍
a3124a7
to
ac42656
Compare
I think this makes parsing the duration from it and supporting a nil-duration easier.
ac42656
to
8b4c859
Compare
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.
very gopher to use the interface 👍
return nil | ||
} | ||
|
||
func (d *NullableDuration) Type() string { |
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.
Why is this needed?
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.
It's part of the Value
interface
Co-authored-by: Jose Garcia <josebalius@github.com>
The initialized value of
time.Duration
is 0. There is support fornil
retention period at the API interface, but we missed support for this at the parameters. Thus, the API request is being made with0
as the retention period.This PR switches the argument type to a string and treats an empty string as a no-retention-period scenario and attempts to parse the string as a duration if the string is non-empty.