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

Changed log.info to tidy up using fmt.sprintf #2246

Merged
merged 19 commits into from
Dec 9, 2019
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
### Removed

### Bug Fixes
- Fixed log formatting issue that occurred while loading the configuration for Ansible-based operators. ([#2246](https://github.com/operator-framework/operator-sdk/pull/2246))
- Fix issue faced in the Ansible based operators when `jmespath` queries are used because it was not installed. ([#2252](https://github.com/operator-framework/operator-sdk/pull/2252))

## v0.12.0
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ require (
github.com/ziutek/mymysql v1.5.4 // indirect
go.uber.org/zap v1.10.0
golang.org/x/tools v0.0.0-20191018212557-ed542cd5b28a
google.golang.org/genproto v0.0.0-20181016170114-94acd270e44e // indirect
gopkg.in/gorp.v1 v1.7.2 // indirect
gopkg.in/yaml.v2 v2.2.4
k8s.io/api v0.0.0
Expand Down
35 changes: 19 additions & 16 deletions pkg/ansible/watches/watches.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,17 +272,7 @@ func getMaxWorkers(gvk schema.GroupVersionKind, defValue int) int {
"_",
-1,
))
maxWorkers, err := strconv.Atoi(os.Getenv(envVar))
if err != nil {
// we don't care why we couldn't parse it just use default
log.Info("Failed to parse %v from environment. Using default %v", envVar, defValue)
return defValue
}

if maxWorkers <= 0 {
log.Info("Value %v not valid. Using default %v", maxWorkers, defValue)
return defValue
}
maxWorkers := getIntegerEnvWithDefault(envVar, defValue)
return maxWorkers
}

Expand All @@ -295,11 +285,8 @@ func getAnsibleVerbosity(gvk schema.GroupVersionKind, defValue int) int {
"_",
-1,
))
ansibleVerbosity, err := strconv.Atoi(os.Getenv(envVar))
if err != nil {
log.Info("Failed to parse %v from environment. Using default %v", envVar, defValue)
return defValue
}

Copy link
Member

Choose a reason for hiding this comment

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

Nit: this extraneous empty line can be removed.

ansibleVerbosity := getIntegerEnvWithDefault(envVar, defValue)

// Use default value when value doesn't make sense
if ansibleVerbosity < 0 {
Expand All @@ -312,3 +299,19 @@ func getAnsibleVerbosity(gvk schema.GroupVersionKind, defValue int) int {
}
return ansibleVerbosity
}

// Returns value for MaxWorkers/Ansibleverbosity based on if envVar is set or a defvalue is used.
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Go doc convention is to use the identifier name (in this case the function name) as the first word of the comment. Not a huge deal since this function is unexported, but a good habit nonetheless.

func getIntegerEnvWithDefault(envVar string, defValue int) int {
val := defValue
if envVal, ok := os.LookupEnv(envVar); ok {
if i, err := strconv.Atoi(envVal); err != nil {
log.Info("could not parse environment variable as an integer; using default value", "envVar", envVar, "default", defValue)

} else {
val = i
}
} else if ok==false {
Copy link
Member

Choose a reason for hiding this comment

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

Nit:

Suggested change
} else if ok==false {
} else if !ok {

log.Info("environment variable not set; using default value", "envVar", envVar, "default", defValue)
Copy link
Member

Choose a reason for hiding this comment

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

Looks like the sanity test is complaining that these log.Info messages don't start with an upper case letter.

So we need:
Could not parse environment variable... and Environment variable not set...

}
return val
}