-
Notifications
You must be signed in to change notification settings - Fork 152
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
Using env variable to set vmware timeout value #1078
Conversation
pkg/blockstorage/vmware/vmware.go
Outdated
if err == nil { | ||
return iv | ||
} |
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.
Suggest:
if err == nil || iv > 0 {
return iv
}
To avoid invalid values.
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.
&&
os.Setenv(vmWareTimeoutMinEnv, "7") | ||
timeout = time.Duration(getEnvAsIntOrDefault(vmWareTimeoutMinEnv, int(defaultWaitTime/time.Minute))) * time.Minute | ||
c.Assert(timeout, Equals, 7*time.Minute) | ||
|
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 test for "0" or "-1". What values would you expect?
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.
Protect against 0 and negative values
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.
Usability related non-nit.
|
||
func getEnvAsIntOrDefault(envKey string, def int) int { | ||
if v, ok := os.LookupEnv(envKey); ok { | ||
iv, err := strconv.Atoi(v) |
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.
Log error. Defaulting on hidden failures are difficult to diagnose. It will help if you log a warning, or similar, to stderr
Another option - log Info to stdout
whenever you default.
Message must include the environment variable and the value you are defaulting to.
If checking error, then return non-default value whenever err == nil
, otherwise you are ignoring legitimate integer values - this all relates to my first point: someone set a legitimate integer value, but its silently being ignored when supplied, why?
While the code will work for the application, it seems as though the current implementation could cause frustration in operation.
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.
@aaron-kasten logging the case where an invalid option was provided
@@ -350,3 +358,14 @@ func (p *FcdProvider) VolumesList(ctx context.Context, tags map[string]string, z | |||
func (p *FcdProvider) SnapshotsList(ctx context.Context, tags map[string]string) ([]*blockstorage.Snapshot, error) { | |||
return nil, errors.New("Not implemented") | |||
} | |||
|
|||
func getEnvAsIntOrDefault(envKey string, def int) int { | |||
if v, ok := os.LookupEnv(envKey); ok { |
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.
nit: Personal bias toward less nesting. if ...; !ok { return def }
, then return def
again below if you have a reason to.
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.
Looks good.
Change Overview
The following PR adds a vmWare specific environment variable to set the timeout of vmware calls.
Pull request type
Please check the type of change your PR introduces:
Issues
Test Plan
Will manual test as well.