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

Using env variable to set vmware timeout value #1078

Merged
merged 6 commits into from
Aug 28, 2021
Merged

Conversation

bathina2
Copy link
Contributor

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:

  • 🚧 Work in Progress
  • 🌈 Refactoring (no functional changes, no api changes)
  • 🐹 Trivial/Minor
  • 🐛 Bugfix
  • 🌻 Feature
  • 🗺️ Documentation
  • 🤖 Test

Issues

  • #XXX

Test Plan

Will manual test as well.

  • 💪 Manual
  • ⚡ Unit test
  • 💚 E2E

Comment on lines 365 to 367
if err == nil {
return iv
}
Copy link
Contributor

@carlbraganza carlbraganza Aug 27, 2021

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

&&

Comment on lines +67 to +70
os.Setenv(vmWareTimeoutMinEnv, "7")
timeout = time.Duration(getEnvAsIntOrDefault(vmWareTimeoutMinEnv, int(defaultWaitTime/time.Minute))) * time.Minute
c.Assert(timeout, Equals, 7*time.Minute)

Copy link
Contributor

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?

Copy link
Contributor

@carlbraganza carlbraganza left a 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

Copy link
Contributor

@aaron-kasten aaron-kasten left a 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)
Copy link
Contributor

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.

Copy link
Contributor Author

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 {
Copy link
Contributor

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.

Copy link
Contributor

@aaron-kasten aaron-kasten left a comment

Choose a reason for hiding this comment

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

Looks good.

@bathina2 bathina2 added the kueue label Aug 27, 2021
@mergify mergify bot merged commit 49a8ce0 into master Aug 28, 2021
@mergify mergify bot deleted the vmware_timeout_changes branch August 28, 2021 00:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants