Skip to content

Commit

Permalink
Behavior has changed with query/lookup which I believe is due to: ans…
Browse files Browse the repository at this point in the history
…ible-collections/kubernetes.core#147

Get these tests to work again.

part of: kiali/kiali#4417
  • Loading branch information
jmazzitelli committed Oct 9, 2021
1 parent 4ce0c74 commit afc8c44
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 70 deletions.
7 changes: 3 additions & 4 deletions molecule/accessible-namespaces-test/converge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,11 @@
that:
- kiali_configmap.api.namespaces.label_selector == "kiali.io/member-of={{ istio.control_plane_namespace }}"

# TODO kubernetes.core.k8s behaves oddly - query doesn't return a list, but should; lookup returns a list but shouldn't.
# For now, just use lookup since it returns the list which is what we want
- name: Make sure the new label exists, but didn't overwrite any existing labels
vars:
namespacesWithCustomLabel: "{{ lookup('kubernetes.core.k8s', kind='Namespace', label_selector='customLabel=test') }}"
namespacesWithKialiLabel: "{{ lookup('kubernetes.core.k8s', kind='Namespace', label_selector=kiali_configmap.api.namespaces.label_selector) }}"
# Use query - it is the only way to ensure a list is returned; for some reason, lookup/wantList=true is not working
namespacesWithCustomLabel: "{{ query('kubernetes.core.k8s', kind='Namespace', label_selector='customLabel=test') }}"
namespacesWithKialiLabel: "{{ query('kubernetes.core.k8s', kind='Namespace', label_selector=kiali_configmap.api.namespaces.label_selector) }}"
assert:
that:
- namespacesWithCustomLabel | length == 1
Expand Down
2 changes: 1 addition & 1 deletion molecule/common/purge-prometheus-data.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace: "{{ k8s_item.metadata.namespace }}"
name: "{{ k8s_item.metadata.name }}"
with_items:
- "{{ lookup('kubernetes.core.k8s', namespace=istio.control_plane_namespace, kind='Pod', label_selector='app=prometheus', api_version='v1') }}" # TODO this assumes faulty behavior - may need to change in the future. See: https://github.com/ansible-collections/kubernetes.core/issues/147
- "{{ query('kubernetes.core.k8s', namespace=istio.control_plane_namespace, kind='Pod', label_selector='app=prometheus', api_version='v1') }}"
loop_control:
loop_var: k8s_item

Expand Down
5 changes: 4 additions & 1 deletion molecule/common/query-prometheus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@
pod: "{{ kiali_pod.resources[0].metadata.name}}"
command: "curl -skL {{ credentials_arg }} -d query={{ prometheus_request.query}} -d time={{ prometheus_request.time }} {{ url }}"
register: prometheus_query_results_raw
ignore_errors: yes # TODO why is this returning a rc=3? We are getting back good results
vars:
credentials_arg: "{{ ('-u ' + kiali_configmap.external_services.prometheus.auth.username + ':' + kiali_configmap.external_services.prometheus.auth.password) if kiali_configmap.external_services.prometheus.auth.username != '' else '' }}"
url: "{{ kiali_configmap.external_services.prometheus.url }}/api/v1/query }}"

- name: Raw Prometheus query results
vars:
url: "{{ kiali_configmap.external_services.prometheus.url }}/api/v1/query }}"
debug:
msg: "Request: {{ prometheus_request }}; Results: {{ prometheus_query_results_raw }}"
msg: "URL: {{ url }}; Request: {{ prometheus_request }}; Results: {{ prometheus_query_results_raw }}"

- set_fact:
prometheus_query_results:
Expand Down
Loading

0 comments on commit afc8c44

Please sign in to comment.