-
Notifications
You must be signed in to change notification settings - Fork 140
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
lookup and query behavior differ when using resource_name vs label_selector #147
Comments
Here is what I see: a. query when using label_selector returns a list-in-a-list (works incorrectly) Reading https://docs.ansible.com/ansible/latest/plugins/lookup.html#forcing-lookups-to-return-lists-query-and-wantlist-true I conclude:
I used this playbook to see this:
Here are the results I see:
|
And I just realized I have code that depends upon this odd (probably incorrect) behavior - and I do not know how to re-implement it based on how I think it should work after this issue is "fixed". So maybe we should not fix this. LOL Background: "Ingress" kind has changed in newer versions of kubernetes. If you use v1beta1, you will see warnings like this: To see if Ingress v1 is available or not, I have this kind of code (this example is in a template, but similar lookups are done elsewhere, too):
This utilizes the "probably incorrect" behavior of lookup. If the cluster does not have that api_version at all, that lookup results in an error which is ignored and results in an empty string (""). But if there is that API (even if there are no Ingress resources), that lookup returns a list which is iterable. This can be generic - this is how you can look for any API in a cluster (doesn't have to be Ingress). I do not know how to do this kind of check otherwise. Here's a simple playbook that illustrates the behavior that is currently happening with lookup. I think this is really incorrect because according to the docs, lookup should always return a string. I can't switch to query because query (according to the docs) always results in an iterable array. The trick I use above is "if an iterable array is returned, the API exists; if a string is returned, that means the API does not exist". If this issue is fixed, I do not think this trick will work and we would need some other way to perform such a API existence check:
|
Hi @jmazzitelli Thanks for reporting this issue.
|
@jmazzitelli Thanks for reporting this. I think you are mostly correct. The only things I would argue otherwise are that In most cases I would generally recommend using |
To provide consistent interface for k8s lookup plugin, add recommendation for `query` or `lookup` with `wantlist=True`. Fixes: ansible-collections#147 Signed-off-by: Abhijeet Kasurde <[email protected]>
@jmazzitelli I updated the code and documentation to match |
@Akasurde what is the behavior now if I use This was my only concern with backwards compatibility issues (at least for code I have). In other words, what will these two return now?
The alternative mentioned above in #147 (comment) would work, however, I'm concerned with the amount of time |
Thanks for updating on |
the response time for the |
To provide consistent interface for k8s lookup plugin, add recommendation for `query` or `lookup` with `wantlist=True`. Fixes: ansible-collections#147 Signed-off-by: Abhijeet Kasurde <[email protected]>
@jmazzitelli I checked, |
To provide consistent interface for k8s lookup plugin, add recommendation for `query` or `lookup` with `wantlist=True`. Fixes: ansible-collections#147 Signed-off-by: Abhijeet Kasurde <[email protected]>
…ible-collections/kubernetes.core#147 Get these tests to work again. part of: kiali/kiali#4417
…ible-collections/kubernetes.core#147 Get these tests to work again. part of: kiali/kiali#4417
…ible-collections/kubernetes.core#147 Get these tests to work again. part of: kiali/kiali#4417
…ible-collections/kubernetes.core#147 Get these tests to work again. part of: kiali/kiali#4417
…ible-collections/kubernetes.core#147 Get these tests to work again. part of: kiali/kiali#4417
…ible-collections/kubernetes.core#147 Get these tests to work again. part of: kiali/kiali#4417
…ible-collections/kubernetes.core#147 (#436) Get these tests to work again. part of: kiali/kiali#4417
…ible-collections/kubernetes.core#147 (#435) Get these tests to work again. part of: kiali/kiali#4417
Run this playbook:
Here I have a pair of
query
and a pair oflookup
invocations. In each pair, one is looking up the namespace by name (usingresource_name
) and one is looking up the namespace by label (usinglabel_selector
).Each assert is verifying the same thing - that the first element in the returned list has
metadata.name == "testns"
(thus verifying the results include the namespace resource in the first element of the list).The asserts with "ignore_errors: yes" are the ones that are failing (but I don't think they should be failing).
When using
query
, looking up by resource_name is OK, but an error occurs using label_selector.It is the reverse when using
lookup
(looking up by label_selector is OK, but an error occurs using resource_name).Here's the full results output:
Ansible version:
Collection version:
The text was updated successfully, but these errors were encountered: