Skip to content

Commit

Permalink
molecule test
Browse files Browse the repository at this point in the history
  • Loading branch information
jmazzitelli committed Oct 30, 2024
1 parent a6f6591 commit c54806b
Show file tree
Hide file tree
Showing 8 changed files with 399 additions and 13 deletions.
37 changes: 24 additions & 13 deletions molecule/common/tasks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@
- debug:
msg: "Present Kiali CR: {{ kiali_cr }}"

- name: Get Kiali Configmap
vars:
instance_name: "{{ kiali.instance_name | default('kiali') }}"
set_fact:
kiali_configmap_resource: "{{ lookup('kubernetes.core.k8s', api_version='v1', kind='ConfigMap', namespace=kiali.install_namespace, resource_name=instance_name) }}"

- name: Format Configmap
set_fact:
kiali_configmap: "{{ kiali_configmap_resource.data['config.yaml'] | from_yaml }}"
- debug:
msg: "Present Kiali ConfigMap: {{ kiali_configmap }}"

- name: Get Kiali Operator Pod
k8s_info:
api_version: v1
Expand All @@ -33,18 +45,8 @@
label_selectors:
- "app.kubernetes.io/instance={{ instance_name }}"
register: kiali_pod

- name: Get Kiali Configmap
vars:
instance_name: "{{ kiali.instance_name | default('kiali') }}"
set_fact:
kiali_configmap_resource: "{{ lookup('kubernetes.core.k8s', api_version='v1', kind='ConfigMap', namespace=kiali.install_namespace, resource_name=instance_name) }}"

- name: Format Configmap
set_fact:
kiali_configmap: "{{ kiali_configmap_resource.data['config.yaml'] | from_yaml }}"
- debug:
msg: "Present Kiali ConfigMap: {{ kiali_configmap }}"
when:
- kiali_configmap.deployment.remote_cluster_resources_only == False

- name: Get Kiali Deployment
vars:
Expand All @@ -56,6 +58,8 @@
label_selectors:
- "app.kubernetes.io/instance={{ instance_name }}"
register: kiali_deployment
when:
- kiali_configmap.deployment.remote_cluster_resources_only == False

- name: Get Kiali Service
vars:
Expand All @@ -67,6 +71,8 @@
label_selectors:
- "app.kubernetes.io/instance={{ instance_name }}"
register: kiali_service
when:
- kiali_configmap.deployment.remote_cluster_resources_only == False

- name: Get Kiali Route
vars:
Expand All @@ -80,6 +86,7 @@
register: kiali_route
when:
- is_openshift == True
- kiali_configmap.deployment.remote_cluster_resources_only == False

- name: Get Kiali Ingress
ignore_errors: yes
Expand All @@ -93,7 +100,8 @@
- "app.kubernetes.io/instance={{ instance_name }}"
register: kiali_ingress
when:
- is_openshift != True
- is_openshift == False
- kiali_configmap.deployment.remote_cluster_resources_only == False

- name: Determine the Kiali Route URL on OpenShift
vars:
Expand All @@ -102,6 +110,7 @@
kiali_base_url: "https://{{ kiali_route.resources[0].spec.host }}{{ web_root }}"
when:
- is_openshift == True
- kiali_configmap.deployment.remote_cluster_resources_only == False

# To avoid problems with Ingress/Minikube conflicts, if installing multiple kiali instances set web_root to the instance name
- name: Determine the Kiali Ingress URL on minikube
Expand All @@ -112,9 +121,11 @@
kiali_base_url: "https://{{ lookup('env', 'MOLECULE_MINIKUBE_IP') }}{{ web_root }}"
when:
- is_minikube == True
- kiali_configmap.deployment.remote_cluster_resources_only == False

- name: Determine the Kiali Ingress URL on kind
set_fact:
kiali_base_url: "http://{{ kiali_service.resources[0].status.loadBalancer.ingress[0].ip }}:20001/kiali"
when:
- is_kind == True
- kiali_configmap.deployment.remote_cluster_resources_only == False
5 changes: 5 additions & 0 deletions molecule/default/prepare.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@
namespace: "{{ cr_namespace }}"
definition: "{{ kiali_cr_definition }}"

# We normally always want to wait for kiali to be deployed, but for those tests
# where this is not wanted (e.g. when remote_cluster_resources_only==true), then
# import this playbook with the var "wait_for_kiali_pod_after_prepare" set to false.
- name: Asserting that Kiali is Deployed
vars:
instance_name: "{{ kiali.instance_name | default('kiali') }}"
Expand All @@ -127,3 +130,5 @@
- kiali_deployment.resources[0].status.availableReplicas == 1
retries: "{{ wait_retries }}"
delay: 5
when:
- wait_for_kiali_pod_after_prepare | default(true) == True
251 changes: 251 additions & 0 deletions molecule/remote-cluster-resources-test/converge.yml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
- name: Destroy
hosts: localhost
connection: local
collections:
- kubernetes.core

- name: Include the base destroy play to destroy the Kiali CR and operator
import_playbook: ../default/destroy.yml

- name: Delete the test namespaces
import_playbook: ./process-namespaces.yml
vars:
state: absent
12 changes: 12 additions & 0 deletions molecule/remote-cluster-resources-test/kiali-cr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: kiali.io/v1alpha1
kind: Kiali
metadata:
name: kiali
spec:
version: {{ kiali.spec_version }}
auth:
strategy: {{ kiali.auth_strategy }}
deployment:
namespace: {{ kiali.install_namespace }}
cluster_wide_access: {{ kiali.cluster_wide_access|bool }}
remote_cluster_resources_only: true
43 changes: 43 additions & 0 deletions molecule/remote-cluster-resources-test/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---
dependency:
name: galaxy
driver:
name: $DORP
platforms:
- name: default
groups:
- k8s
provisioner:
name: ansible
config_options:
defaults:
callbacks_enabled: junit
playbooks:
destroy: ./destroy-remote-cluster-resources-test.yml
prepare: ./prepare-remote-cluster-resources-test.yml
cleanup: ../default/cleanup.yml
inventory:
group_vars:
all:
cr_file_path: "{{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') }}/molecule/remote-cluster-resources-test/kiali-cr.yaml"
cr_namespace: "{{ 'kiali-operator' if (lookup('env', 'MOLECULE_OPERATOR_INSTALLER') | default('helm', True) == 'helm') else 'istio-system' }}" # if external operator, assume CR must go in control plane namespace
wait_retries: "{{ lookup('env', 'MOLECULE_WAIT_RETRIES') | default('360', True) }}"
istio:
control_plane_namespace: istio-system
kiali:
spec_version: "{{ lookup('env', 'MOLECULE_KIALI_CR_SPEC_VERSION') | default('default', True) }}"
install_namespace: istio-system
cluster_wide_access: true
auth_strategy: anonymous
operator_namespace: "{{ 'kiali-operator' if (lookup('env', 'MOLECULE_OPERATOR_INSTALLER') | default('helm', True) == 'helm') else ('openshift-operators' if (query('kubernetes.core.k8s', kind='Namespace', resource_name='openshift-operators') | length > 0) else 'operators') }}" # if external operator, assume operator is in OLM location
operator_image_name: "{{ 'image-registry.openshift-image-registry.svc:5000/kiali/kiali-operator' if lookup('env', 'MOLECULE_KIALI_OPERATOR_IMAGE_NAME') == 'dev' else (lookup('env', 'MOLECULE_KIALI_OPERATOR_IMAGE_NAME')|default('quay.io/kiali/kiali-operator', True)) }}"
operator_version: "{{ lookup('env', 'MOLECULE_KIALI_OPERATOR_IMAGE_VERSION')|default('latest', True) }}"
operator_watch_namespace: kiali-operator
operator_cluster_role_creator: "true"
operator_image_pull_policy: "{{ lookup('env', 'MOLECULE_KIALI_OPERATOR_IMAGE_PULL_POLICY')|default('Always', True) }}"
scenario:
name: remote-cluster-resources-test
test_sequence:
- prepare
- converge
- destroy
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
- name: Prepare
hosts: localhost
connection: local
collections:
- kubernetes.core

- name: Create the test namespaces
import_playbook: ./process-namespaces.yml
vars:
state: present

- name: Include the base prepare play to create the first kiali CR
import_playbook: ../default/prepare.yml
vars:
wait_for_kiali_pod_after_prepare: false
36 changes: 36 additions & 0 deletions molecule/remote-cluster-resources-test/process-namespaces.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
- name: "Process Test Namespaces [state={{ state }}]"
hosts: localhost
connection: local
collections:
- kubernetes.core

tasks:
- k8s:
state: "{{ state }}"
definition:
apiVersion: v1
kind: Namespace
metadata:
name: remote-cluster-resources-test-1
labels:
discoverySelectorLabel1: test
test: kiali
- k8s:
state: "{{ state }}"
definition:
apiVersion: v1
kind: Namespace
metadata:
name: remote-cluster-resources-test-2
labels:
discoverySelectorLabel2: matchme
test: kiali
- k8s:
state: "{{ state }}"
definition:
apiVersion: v1
kind: Namespace
metadata:
name: remote-cluster-resources-test-x
labels:
test: kiali

0 comments on commit c54806b

Please sign in to comment.