-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Error Failed to parse %v from environment. is faced when we start the Ansible Operators upgraded to 0.12 #2186
Comments
c/c @djzager |
Looking into this today. |
One question. Are either of these environment variables being set? |
Looking at the code for maxWorkers (same thing for the ansible verbosity): 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
} Looks like we are trying to get the environment variable and simply returning the default when we can't convert it to an Is there a value add in additionally checking if the environment variable is set? |
Hi @djzager, Thank you for check it as well. See that default values are attributed to it here: operator-sdk/pkg/ansible/flags/flag.go Lines 44 to 57 in d94ad3e
The problem is that after #2087 the code impl is face an issue to parse them: (just covert the int to string should solve that)
So, IHMO following what we need to here to close this issue:
operator-sdk/pkg/ansible/watches/watches.go Lines 291 to 312 in bad0ca5
|
I think there may be a bit of a misunderstanding about what is happening here. Let's start with the log message that you shared.
Going back to the code:
and:
Specifically, operator-sdk/pkg/ansible/flags/flag.go Lines 44 to 57 in d94ad3e
To recap:
Well, in the logs what you are seeing is we are trying to parse workers/ansibleVerbosity from an environment variable. We haven't failed to parse the default values.
We haven't failed, we are returning the default because we couldn't get a legit value from the environment (either because the environment variable wasn't set or the value inside was bogus).
We are returning the default value. |
There is one bug here. The log line: log.Info("Failed to parse %v from environment. Using default %v", envVar, defValue) is not correct (it doesn't support Info(msg string, keysAndValues ...interface{}) |
@camilamacedo86 @djzager the logic is correct. This is behaving exactly as expected. The log should be info because it is not a failure but information. We failed to see or parse anything from the environment variable. But if you did not set them then you can ignore this message and move on. If you did set them this should alert you that this might be your problem. The failure is really what @joelanford just posted above. I would change the log statement to be the following:
That is the only problem with this bug. |
Hi @jmrodri. @joelanford @djzager, I understood what is happening now. Thank you for the clarification. The goal is just to inform that the default values were used because not ENV VARs were found. So, I would suggest the msg be changed to avoid misunderstandings. So, IHMO it could be something as |
Okay fair enough. I suggest we use the original message I used when I wrote the first iteration of envvar := formatEnvVar(gvk.Kind, gvk.Group)
maxWorkers, err := strconv.Atoi(os.Getenv(envvar))
if err != nil {
// we don't care why we couldn't parse it just use one.
// maybe we should log that we are defaulting to 1.
logf.Log.WithName("manager").V(0).Info("Using default value for workers %d", defvalue) |
So the fix for this is:
|
/assign @bharathi-tenneti |
Bug Report
What did you do?
Upgrade the sample to use the SDK O.12
What did you expect to see?
All worked without issues
What did you see instead? Under which circumstances?
The following error when we run the project
Environment
operator-sdk version: 0.12
go version: 1.13.4
Kubernetes version information:
Kubernetes cluster kind:minikube
Are you writing your operator in ansible, helm, or go?
/ansible-operator
Possible Solution
Additional context
Following the steps to reproduce
Shows that it was introduced in : #2087
The text was updated successfully, but these errors were encountered: