-
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
feat(ansible): make ansible verbosity configurable #1852
Conversation
/test e2e-aws-ansible |
1 similar comment
/test e2e-aws-ansible |
I thought we said that the maxworkers were an operational item and shouldn't be in the watches file. That was the case when I added maxworkers. Unless things have changed since then. The idea was that the author of the operator would set it as a flag during deployment, then the operator/admin would override it via the environment variable based on their clusters needs/capabilities. |
/retest |
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.
/lgtm
/lgtm |
HI @djzager, Really great work here 👍 . However, shows that it is missing update the docs regards these changes.. could you please add this part in the PR? |
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.
The primary objective of this change is to make the verbosity of individual `ansible-runner` command invocations configurable (not just "-vv"). In order to accomplish this: * A new flag was added to the AnsibleOperatorFlags (ansible-verbosity) with a default value of 2. * The entire flagset is given to the watches pkg Load() to provide one place for handling command line arguments, watches config values, and environment variables. This makes an individual watch more useful when creating a runner and adding a GVK to the controller. Also, this puts new fields on the Watch struct (MaxWorkers and AnsibleVerbosity). * New functions were added to the watches pkg -- New(gvk) instantiates a Watch with sensible defaults. Validate() is used to verify a given watch meets certain criteria (legit path to playbook/role and proper finalizer). This makes it possible for someone who only knows their GVK and role/playbook to easily create a watch that can be used with the runner pkg. * When creating a runner from a watch, we will now validate it using watches.Validate(). Essentially the watches pkg should know what is and isn't a valid watch. * New helper functions in the runner pkg -- ansibleVerbosityString to convert an integer AnsibleVerbosity to a string (ie. 2 becomes "-vv"), playbookCmdFunc, and roleCmdFunc consolidate the logic for creating the cmdFund.
Prevent configuration of ansible verbosity or max worker from watches.yaml
Since there are no tests added to the file, remove the file so it's obvious there are no tests for the Ansible operator's run function.
New changes are detected. LGTM label has been removed. |
@camilamacedo86 I'm looking through to see if there is any more documenting that I need to do. |
@@ -8,6 +8,7 @@ | |||
- Ansible based operators now gather and serve metrics about each custom resource on port 8686 of the metrics service. ([#1723](https://github.com/operator-framework/operator-sdk/pull/1723)) | |||
- Added the Go version, OS, and architecture to the output of `operator-sdk version` ([#1863](https://github.com/operator-framework/operator-sdk/pull/1863)) | |||
- Added support for `ppc64le-linux` for the `operator-sdk` binary and the Helm operator base image. ([#1533](https://github.com/operator-framework/operator-sdk/pull/1533)) | |||
- Ansible based operators now support verbosity configuration via the `ansible-verbosity` flag at the command line. ([#1852](https://github.com/operator-framework/operator-sdk/pull/1852)) |
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.
- Ansible based operators now support verbosity configuration via the `ansible-verbosity` flag at the command line. ([#1852](https://github.com/operator-framework/operator-sdk/pull/1852)) | |
- Added support of verbosity configuration for Ansible-based Operators via the `ansible-verbosity` flag. ([#1852](https://github.com/operator-framework/operator-sdk/pull/1852)) |
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.
Is not this change cable of to cause break changes in the current projects?
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.
The proposed changes should not break current projects or require any changes in those projects. If you have a scenario or code path in mind I should certainly fix it.
@@ -107,7 +105,7 @@ func Run(flags *aoflags.AnsibleOperatorFlags) error { | |||
GVK: w.GroupVersionKind, | |||
Runner: runner, | |||
ManageStatus: w.ManageStatus, | |||
MaxWorkers: getMaxWorkers(w.GroupVersionKind, flags.MaxWorkers), |
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.
So, currently, we can define the MaxWorkers by CRD. Am I right? Why should we change it?
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.
The two places to set MaxWorkers
are on the command line or via an environment variable. The only changes made here are to put the resolution of those values in the watches package + storing those values on the watches struct to be reused throughout execution.
@@ -52,56 +52,65 @@ type Runner interface { | |||
GetFinalizer() (string, bool) | |||
} | |||
|
|||
func ansibleVerbosityString(verbosity int) string { | |||
if verbosity > 0 { |
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.
Would not it can be as v, or vv, or vvv, or vvvv? See https://docs.ansible.com/ansible/latest/cli/ansible-playbook.html#cmdoption-ansible-playbook-v
So, wdyt about your solution allow the user to inform it?
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.
- To me it made more sense to make this the integer value of the verbosity level. I don't believe this would be too surprising to Ansible users as that is how
debug
works. I also wanted to avoid any possible confusion with the operator-sdk's own verbosity.
testCases := []struct { | ||
name string | ||
watch watches.Watch |
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 it was removed? Are the watches still working well after this change? I mean, is possible to define the resources which should be watched after this PR?
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 certain I follow. The structure of the testCase struct was modified so that the watch could be constructed as it is here
gvk schema.GroupVersionKind | ||
playbook string | ||
role string | ||
finalizer *watches.Finalizer |
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 required change the watches and add the finalizer to add support to users defined the verbose level of the ansible container?
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.
Since I am creating the watch
below, I need all of the things that could be meaningfully define on a watch to be a part of each test case.
for _, tc := range testCases { | ||
gotString := ansibleVerbosityString(tc.verbosity) | ||
if tc.expectedString != gotString { | ||
t.Fatalf("Unexpected string %v expected %v", gotString, tc.expectedString) |
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.
Should not possible to add a test to ensure that if the -vv, for example, be used then the logs are with this verbose? Could we not check that the output which jut will occur in this scenario was not printed?
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 think it would be possible to add a functional test to do this, yes. I do not believe it would be easy to construct a test in runner_test.go
that does as you describe.
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.
Wdyt about using the e2e tests for it?
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.
Hi @djzager,
I looked better this PR and is not clear for me why was required to do some changes? Could we not just add the support which shows the goal of this PR and leave the rest of the impl as it is? To add the support would not just be required get the env var with the verbosity level and use it? Also, it is missing add the info over it in the doc
So, it shows for me that you are trying to address here more changes than what you described in the changelog. In this way, could you split your goals in PRs?
Part of the "additional" changes are from the fact that this is a continuation of my previous PRs to refactor the Ansible Operator: That is an important point because, you are correct, more than just making it possible to control Ansible's verbosity is happening here. However, I would argue that as it currently stands where values are coming from is not straightforward...some are being handled in the What this pull request aims to do, in addition to the verbosity stuff, was to centralize:
This I need to update. Should I leave the discussion of using |
HI @djzager, IMHO this PR has more than one purpose which makes hard to track these changes in the changelog, review and etc ... since it is not only about to add the flag as described there. Also, it has many changes in the tests as well which make harder we ensure that all still working properly. So, IMHO you should have a PR for each purpose instead of merging this one in order to help us rewview, ensure the quality, test and etc ... However, I will leave the decision to the team. Hi @fabianvf, |
/test sanity |
@djzager: The following test failed, say
Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here. |
I do not disagree that there is more going on here than just "make ansible verbosity configurable". I do not particularly want to break this PR up into the 3-5 pieces but I will if that's what you need from me to review this PR. I will wait on feedback from @camilamacedo86, @fabianvf, @jmrodri before doing any more work on this PR (specifically fixing the broken sanity test and addressing some of the remaining comments). |
Hi @djzager, Really thank you for comprehension and I think is a good approach wait for the others review. Maybe they have more knowledge on this part and are ok with move in this way. |
Without a good reason not to break up this work I have decided to go ahead and break this PR up into it's proper pieces. |
Really thank you @djzager for your contribution and understanding in this matter. |
The primary objective of this change is to make the verbosity of
individual
ansible-runner
command invocations configurable (not just"-vv"). In order to accomplish this:
with a default value of 2.
place for handling command line arguments, watches config values, and
environment variables. This makes an individual watch more useful when
creating a runner and adding a GVK to the controller. Also, this puts
new fields on the Watch struct (MaxWorkers and AnsibleVerbosity).
Watch with sensible defaults. Validate() is used to verify a given
watch meets certain criteria (legit path to playbook/role and proper
finalizer). This makes it possible for someone who only knows their
GVK and role/playbook to easily create a watch that can be used with
the runner pkg.
watches.Validate(). Essentially the watches pkg should know what is
and isn't a valid watch.
convert an integer AnsibleVerbosity to a string (ie. 2 becomes "-vv"),
playbookCmdFunc, and roleCmdFunc consolidate the logic for creating
the cmdFund.