Skip to content

Commit

Permalink
get molecule default test to pass
Browse files Browse the repository at this point in the history
  • Loading branch information
jmazzitelli committed Oct 9, 2023
1 parent a71681d commit e08616a
Show file tree
Hide file tree
Showing 14 changed files with 199 additions and 178 deletions.
2 changes: 2 additions & 0 deletions molecule/default/prepare.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@
- "--set"
- "allowAdHocKialiImage=true"
- "--set"
- "allowAdHocOSSMConsoleImage=true"
- "--set"
- "allowSecurityContextOverride=true"
- "--set"
- "cr.create=false"
Expand Down
11 changes: 11 additions & 0 deletions molecule/ossmconsole-common/confirm_openshift.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
- name: Get information about the cluster
set_fact:
api_groups: "{{ lookup('kubernetes.core.k8s', cluster_info='api_groups') }}"

- name: Determine the cluster type
set_fact:
is_openshift: "{{ True if 'route.openshift.io' in api_groups else False }}"

# OSSM Console is only usable on OpenShift, skip the test if not on OpenShift platform
- meta: end_play
when: is_openshift == False
19 changes: 0 additions & 19 deletions molecule/ossmconsole-common/tasks.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,7 @@
- name: Get information about the cluster
set_fact:
api_groups: "{{ lookup('kubernetes.core.k8s', cluster_info='api_groups') }}"
- name: Determine the cluster type
set_fact:
is_openshift: "{{ True if 'route.openshift.io' in api_groups else False }}"
- name: Determine the Istio implementation
set_fact:
is_maistra: "{{ True if 'maistra.io' in api_groups else False }}"

- name: Get OSSMConsole CR if present
set_fact:
ossmconsole_cr: "{{ lookup('kubernetes.core.k8s', api_version='kiali.io/v1alpha1', kind='OSSMConsole', namespace=ossmconsole_cr_namespace, resource_name=custom_resource.metadata.name) }}"

- name: Get OSSMConsole Operator Pod
k8s_info:
api_version: v1
kind: Pod
namespace: "{{ ossmconsole.operator_namespace }}"
label_selectors:
- app.kubernetes.io/name = ossmconsole-operator
register: ossmconsole_operator_pod

- name: Get OSSMConsole Pod
k8s_info:
api_version: v1
Expand Down
7 changes: 4 additions & 3 deletions molecule/ossmconsole-config-values-test/converge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
vars:
custom_resource: "{{ lookup('template', ossmconsole_cr_file_path) | from_yaml }}"
tasks:
- import_tasks: ../ossmconsole-common/confirm_openshift.yml
- import_tasks: ../ossmconsole-common/tasks.yml
- import_tasks: ../ossmconsole-common/wait_for_ossmconsole_cr_changes.yml

Expand Down Expand Up @@ -49,11 +50,11 @@
debug:
msg: "{{ current_ossmconsole_cr }}"

- import_tasks: ../common/set_ossmconsole_cr.yml
- import_tasks: ../ossmconsole-common/set_ossmconsole_cr.yml
vars:
new_ossmconsole_cr: "{{ current_ossmconsole_cr }}"
- import_tasks: ../common/wait_for_ossmconsole_cr_changes.yml
- import_tasks: ../common/tasks.yml
- import_tasks: ../ossmconsole-common/wait_for_ossmconsole_cr_changes.yml
- import_tasks: ../ossmconsole-common/tasks.yml

- name: Confirm the Kiali Graph Impl is now changed to use the "cy" impl
assert:
Expand Down
29 changes: 24 additions & 5 deletions molecule/ossmconsole-config-values-test/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,39 @@ provisioner:
playbooks:
destroy: ../ossmconsole-default/destroy.yml
prepare: ../ossmconsole-default/prepare.yml
cleanup: ../ossmconsole-default/cleanup.yml
cleanup: ../default/cleanup.yml
inventory:
group_vars:
all:
ossmconsole_cr_file_path: "{{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') }}/molecule/ossmconsole-cr.yaml"
ossmconsole_cr_namespace: "{{ 'ossmconsole' }}"
cr_file_path: "{{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') }}/molecule/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 will 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
accessible_namespaces: ["**"]
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"
image_name: "{{ 'image-registry.openshift-image-registry.svc:5000/kiali/kiali' if lookup('env', 'MOLECULE_KIALI_IMAGE_NAME') == 'dev' else ('quay.io/kiali/kiali' if ansible_env.MOLECULE_KIALI_IMAGE_NAME is not defined else lookup('env', 'MOLECULE_KIALI_IMAGE_NAME')) }}"
image_version: "{{ 'latest' if ansible_env.MOLECULE_KIALI_IMAGE_VERSION is not defined else lookup('env', 'MOLECULE_KIALI_IMAGE_VERSION') }}"
image_pull_policy: "{{ lookup('env', 'MOLECULE_KIALI_IMAGE_PULL_POLICY')|default('Always', True) }}"
operator_image_pull_policy: "{{ lookup('env', 'MOLECULE_KIALI_OPERATOR_IMAGE_PULL_POLICY')|default('Always', True) }}"
ossmconsole_cr_file_path: "{{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') }}/molecule/ossmconsole-cr.yaml"
ossmconsole_cr_namespace: "{{ 'kiali-operator' if (lookup('env', 'MOLECULE_OPERATOR_INSTALLER') | default('helm', True) == 'helm') else 'istio-system' }}" # if external operator, assume CR will go in control plane namespace
plugin_image_pull_secret_json: "{{ lookup('env', 'PLUGIN_IMAGE_PULL_SECRET_JSON') | default('') }}"
ossmconsole:
install_namespace: "{{ 'kiali-operator' if (lookup('env', 'MOLECULE_OPERATOR_INSTALLER') | default('helm', True) == 'helm') else 'istio-system' }}" # install namespace must be the same as the CR namespace today
spec_version: "{{ lookup('env', 'MOLECULE_OSSMCONSOLE_CR_SPEC_VERSION') | default('default', True) }}"
install_namespace: "ossmconsole"
operator_namespace: "{{ 'openshift-operators' }}"
image_name: "{{ 'image-registry.openshift-image-registry.svc:5000/kiali/ossmconsole' if lookup('env', 'MOLECULE_PLUGIN_IMAGE_NAME') == 'dev' else ('quay.io/kiali/ossmconsole' if ansible_env.MOLECULE_PLUGIN_IMAGE_NAME is not defined else lookup('env', 'MOLECULE_PLUGIN_IMAGE_NAME')) }}"
image_version: "{{ 'latest' if ansible_env.MOLECULE_PLUGIN_IMAGE_VERSION is not defined else lookup('env', 'MOLECULE_PLUGIN_IMAGE_VERSION') }}"
image_pull_policy: "{{ lookup('env', 'MOLECULE_PLUGIN_IMAGE_PULL_POLICY')|default('Always', True) }}"
scenario:
name: ossmconsole-config-values-test
test_sequence:
Expand Down
2 changes: 1 addition & 1 deletion molecule/ossmconsole-cr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ spec:
deployment:
imageName: "{{ ossmconsole.image_name }}"
imageVersion: "{{ ossmconsole.image_version }}"
imagePullPolicy: Always
imagePullPolicy: "{{ ossmconsole.image_pull_policy }}"
imagePullSecrets: [ {{ plugin_image_pull_secret_name | default('') }} ]
10 changes: 0 additions & 10 deletions molecule/ossmconsole-default/cleanup.yml

This file was deleted.

1 change: 1 addition & 0 deletions molecule/ossmconsole-default/converge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
vars:
custom_resource: "{{ lookup('template', ossmconsole_cr_file_path) | from_yaml }}"
tasks:
- import_tasks: ../ossmconsole-common/confirm_openshift.yml
- import_tasks: ../ossmconsole-common/tasks.yml
33 changes: 6 additions & 27 deletions molecule/ossmconsole-default/destroy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,11 @@
collections:
- kubernetes.core
tasks:
- name: Skip test if not on OpenShift
import_tasks: ../ossmconsole-common/confirm_openshift.yml

- name: Remove OSSMConsole CR
vars:
custom_resource: "{{ lookup('template', ossmconsole_cr_file_path) | from_yaml }}"
k8s:
state: absent
api_version: kiali.io/v1alpha1
kind: OSSMConsole
namespace: "{{ ossmconsole_cr_namespace }}"
name: "{{ custom_resource.metadata.name }}"
wait: yes
wait_timeout: 600
ignore_errors: yes
- name: Uninstall the OSSM Console
import_playbook: remove_ossmconsole.yml

- name: Remove the cr namespace
k8s:
state: absent
api_version: v1
kind: Namespace
name: "{{ ossmconsole_cr_namespace }}"

- name: Remove the install namespace
k8s:
state: absent
api_version: v1
kind: Namespace
name: "{{ ossmconsole.install_namespace }}"
when:
- ossmconsole.install_namespace != ossmconsole_cr_namespace
- name: Include the base destroy play to destroy the kiali install
import_playbook: ../default/destroy.yml
39 changes: 0 additions & 39 deletions molecule/ossmconsole-default/dump-logs.yml

This file was deleted.

79 changes: 79 additions & 0 deletions molecule/ossmconsole-default/install_ossmconsole.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
- name: Install OSSMConsole
hosts: localhost
connection: local
collections:
- kubernetes.core
tasks:
- import_tasks: ../ossmconsole-common/confirm_openshift.yml

- name: Make sure the OSSMConsole CR namespace exists
k8s:
state: present
api_version: v1
kind: Namespace
name: "{{ ossmconsole_cr_namespace }}"

# This is really a no-op because today we know the CR namespace will always be the same as the install namespace
- name: Make sure the OSSMConsole install namespace exists
k8s:
state: present
api_version: v1
kind: Namespace
name: "{{ ossmconsole.install_namespace }}"
when:
- ossmconsole.install_namespace != ossmconsole_cr_namespace

- name: Define the name of the pull secret if a secret is needed to pull the plugin image from the internal image registry
set_fact:
plugin_image_pull_secret_name: "ossmconsole-pull-secret"
when:
- plugin_image_pull_secret_json != ""

- name: Create the secret that will be used by the plugin pod to pull the image from the internal registry when needed
k8s:
state: present
definition:
apiVersion: v1
kind: Secret
metadata:
name: "{{ plugin_image_pull_secret_name }}"
namespace: "{{ ossmconsole.install_namespace }}"
type: kubernetes.io/dockerconfigjson
data:
.dockerconfigjson: "{{ plugin_image_pull_secret_json }}"
when:
- plugin_image_pull_secret_name is defined

- name: Wait for the OSSMConsole CRD to be established
k8s_info:
api_version: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
name: ossmconsoles.kiali.io
wait: yes
wait_condition:
type: Established

- name: Prepare initial OSSMConsole CR definition based solely on the template
set_fact:
ossmconsole_cr_definition: "{{ lookup('template', ossmconsole_cr_file_path) }}"

- name: Create OSSMConsole CR
k8s:
namespace: "{{ ossmconsole_cr_namespace }}"
definition: "{{ ossmconsole_cr_definition }}"

- name: Asserting that OSSMConsole plugin is Deployed
k8s_info:
api_version: v1
kind: Deployment
namespace: "{{ ossmconsole.install_namespace }}"
label_selectors:
- "app.kubernetes.io/name=ossmconsole"
register: ossmconsole_deployment
until:
- ossmconsole_deployment is success
- ossmconsole_deployment.resources | length == 1
- ossmconsole_deployment.resources[0].status.availableReplicas is defined
- ossmconsole_deployment.resources[0].status.availableReplicas == 1
retries: "{{ wait_retries }}"
delay: 5
29 changes: 24 additions & 5 deletions molecule/ossmconsole-default/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,39 @@ provisioner:
playbooks:
destroy: ../ossmconsole-default/destroy.yml
prepare: ../ossmconsole-default/prepare.yml
cleanup: ../ossmconsole-default/cleanup.yml
cleanup: ../default/cleanup.yml
inventory:
group_vars:
all:
ossmconsole_cr_file_path: "{{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') }}/molecule/ossmconsole-cr.yaml"
ossmconsole_cr_namespace: "{{ 'ossmconsole' }}"
cr_file_path: "{{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') }}/molecule/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 will 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
accessible_namespaces: ["**"]
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"
image_name: "{{ 'image-registry.openshift-image-registry.svc:5000/kiali/kiali' if lookup('env', 'MOLECULE_KIALI_IMAGE_NAME') == 'dev' else ('quay.io/kiali/kiali' if ansible_env.MOLECULE_KIALI_IMAGE_NAME is not defined else lookup('env', 'MOLECULE_KIALI_IMAGE_NAME')) }}"
image_version: "{{ 'latest' if ansible_env.MOLECULE_KIALI_IMAGE_VERSION is not defined else lookup('env', 'MOLECULE_KIALI_IMAGE_VERSION') }}"
image_pull_policy: "{{ lookup('env', 'MOLECULE_KIALI_IMAGE_PULL_POLICY')|default('Always', True) }}"
operator_image_pull_policy: "{{ lookup('env', 'MOLECULE_KIALI_OPERATOR_IMAGE_PULL_POLICY')|default('Always', True) }}"
ossmconsole_cr_file_path: "{{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') }}/molecule/ossmconsole-cr.yaml"
ossmconsole_cr_namespace: "{{ 'kiali-operator' if (lookup('env', 'MOLECULE_OPERATOR_INSTALLER') | default('helm', True) == 'helm') else 'istio-system' }}" # if external operator, assume CR will go in control plane namespace
plugin_image_pull_secret_json: "{{ lookup('env', 'PLUGIN_IMAGE_PULL_SECRET_JSON') | default('') }}"
ossmconsole:
install_namespace: "{{ 'kiali-operator' if (lookup('env', 'MOLECULE_OPERATOR_INSTALLER') | default('helm', True) == 'helm') else 'istio-system' }}" # install namespace must be the same as the CR namespace today
spec_version: "{{ lookup('env', 'MOLECULE_OSSMCONSOLE_CR_SPEC_VERSION') | default('default', True) }}"
install_namespace: "ossmconsole"
operator_namespace: "{{ 'openshift-operators' }}"
image_name: "{{ 'image-registry.openshift-image-registry.svc:5000/kiali/ossmconsole' if lookup('env', 'MOLECULE_PLUGIN_IMAGE_NAME') == 'dev' else ('quay.io/kiali/ossmconsole' if ansible_env.MOLECULE_PLUGIN_IMAGE_NAME is not defined else lookup('env', 'MOLECULE_PLUGIN_IMAGE_NAME')) }}"
image_version: "{{ 'latest' if ansible_env.MOLECULE_PLUGIN_IMAGE_VERSION is not defined else lookup('env', 'MOLECULE_PLUGIN_IMAGE_VERSION') }}"
image_pull_policy: "{{ lookup('env', 'MOLECULE_PLUGIN_IMAGE_PULL_POLICY')|default('Always', True) }}"
scenario:
name: ossmconsole-default
test_sequence:
Expand Down
Loading

0 comments on commit e08616a

Please sign in to comment.