Skip to content

Commit

Permalink
[test-operator] Move to openstack-test-operator namespace
Browse files Browse the repository at this point in the history
The test-operator got changed from cluster scoped operator to namespace
scoped operator in this PR [1]. It is now recommended that the
test-operator gets installed in a separate namespace other than the one
where the test pods are spawned.

This patch ensures that:

 - the test-operator gets installed in the openstack-test-operator
   namespace

 - the test-operator spawns test pods in the openstack namespace

[1] openstack-k8s-operators/test-operator#264
  • Loading branch information
lpiwowar committed Dec 17, 2024
1 parent ff9f827 commit 042133f
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 22 deletions.
3 changes: 2 additions & 1 deletion roles/test_operator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ Execute tests via the [test-operator](https://openstack-k8s-operators.github.io/

## Parameters
* `cifmw_test_operator_artifacts_basedir`: (String) Directory where we will have all test-operator related files. Default value: `{{ cifmw_basedir }}/tests/test_operator` which defaults to `~/ci-framework-data/tests/test_operator`
* `cifmw_test_operator_namespace`: (String) Namespace inside which all the resources are created. Default value: `openstack`
* `cifmw_test_operator_namespace`: (String) Namespace where test pods are spawned and where OCP resources related to test-operator are created by the role. Default value: `openstack`
* `cifmw_test_operator_target_namespace`: (String) Namespace where test-operator is installed. Default value: `openstack-test-operator`
* `cifmw_test_operator_index`: (String) Full name of container image with index that contains the test-operator. Default value: `quay.io/openstack-k8s-operators/test-operator-index:latest`
* `cifmw_test_operator_timeout`: (Integer) Timeout in seconds for the execution of the tests. Default value: `3600`
* `cifmw_test_operator_logs_image`: (String) Image that should be used to collect logs from the pods spawned by the test-operator. Default value: `quay.io/quay/busybox`
Expand Down
11 changes: 6 additions & 5 deletions roles/test_operator/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ cifmw_test_operator_stages:
type: tempest
cifmw_test_operator_fail_on_test_failure: true
cifmw_test_operator_artifacts_basedir: "{{ cifmw_basedir | default(ansible_user_dir ~ '/ci-framework-data') }}/tests/test_operator"
cifmw_test_operator_namespace: openstack
cifmw_test_operator_namespace: openstack-test-operator
cifmw_test_operator_target_namespace: openstack
cifmw_test_operator_index: quay.io/openstack-k8s-operators/test-operator-index:latest
cifmw_test_operator_timeout: 3600
cifmw_test_operator_logs_image: quay.io/quay/busybox
Expand Down Expand Up @@ -106,7 +107,7 @@ cifmw_test_operator_tempest_config:
kind: Tempest
metadata:
name: "{{ stage_vars_dict.cifmw_test_operator_tempest_name }}-{{ _stage_vars.name }}"
namespace: "{{ cifmw_test_operator_namespace }}"
namespace: "{{ cifmw_test_operator_target_namespace }}"
spec:
SELinuxLevel: "{{ cifmw_test_operator_selinux_level }}"
containerImage: "{{ stage_vars_dict.cifmw_test_operator_tempest_image }}:{{ stage_vars_dict.cifmw_test_operator_tempest_image_tag }}"
Expand Down Expand Up @@ -159,7 +160,7 @@ cifmw_test_operator_tobiko_config:
kind: Tobiko
metadata:
name: "{{ stage_vars_dict.cifmw_test_operator_tobiko_name }}-{{ _stage_vars.name }}"
namespace: "{{ cifmw_test_operator_namespace }}"
namespace: "{{ cifmw_test_operator_target_namespace }}"
spec:
SELinuxLevel: "{{ cifmw_test_operator_selinux_level }}"
kubeconfigSecretName: "{{ stage_vars_dict.cifmw_test_operator_tobiko_kubeconfig_secret }}"
Expand Down Expand Up @@ -205,7 +206,7 @@ cifmw_test_operator_ansibletest_config:
kind: AnsibleTest
metadata:
name: "{{ stage_vars_dict.cifmw_test_operator_ansibletest_name }}-{{ _stage_vars.name }}"
namespace: "{{ cifmw_test_operator_namespace }}"
namespace: "{{ cifmw_test_operator_target_namespace }}"
spec:
SELinuxLevel: "{{ cifmw_test_operator_selinux_level }}"
containerImage: "{{ stage_vars_dict.cifmw_test_operator_ansibletest_image }}:{{ stage_vars_dict.cifmw_test_operator_ansibletest_image_tag }}"
Expand Down Expand Up @@ -250,7 +251,7 @@ cifmw_test_operator_horizontest_config:
kind: HorizonTest
metadata:
name: "{{ stage_vars_dict.cifmw_test_operator_horizontest_name }}-{{ _stage_vars.name }}"
namespace: "{{ cifmw_test_operator_namespace }}"
namespace: "{{ cifmw_test_operator_target_namespace }}"
spec:
SELinuxLevel: "{{ cifmw_test_operator_selinux_level }}"
storageClass: "{{ cifmw_test_operator_storage_class }}"
Expand Down
27 changes: 20 additions & 7 deletions roles/test_operator/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,19 @@
owner: "{{ ansible_user | default(lookup('env', 'USER')) }}"
group: "{{ ansible_user | default(lookup('env', 'USER')) }}"

- name: Create namespace where the test-operator is going to be installed
kubernetes.core.k8s:
kubeconfig: "{{ cifmw_openshift_kubeconfig }}"
api_key: "{{ cifmw_openshift_token | default(omit) }}"
context: "{{ cifmw_openshift_context | default(omit) }}"
state: present
wait: true
definition:
apiVersion: v1
kind: Namespace
metadata:
name: "{{ cifmw_test_operator_namespace }}"

- name: Ensure OperatorGroup for the test-operator is present
kubernetes.core.k8s:
kubeconfig: "{{ cifmw_openshift_kubeconfig }}"
Expand All @@ -38,7 +51,7 @@
namespace: "{{ cifmw_test_operator_namespace }}"
spec:
targetNamespaces:
- "{{ cifmw_test_operator_namespace }}"
- "{{ cifmw_test_operator_target_namespace }}"
when: not cifmw_test_operator_dry_run | bool

- name: Ensure CatalogSource for the test-operator is present
Expand Down Expand Up @@ -81,17 +94,17 @@
nodeSelector: "{{ cifmw_test_operator_node_selector | default(omit) }}"
when: not cifmw_test_operator_dry_run | bool

- name: Wait until the test-operator csv is present
- name: Wait until the test-operator CSV is present in the target namespace
kubernetes.core.k8s_info:
kubeconfig: "{{ cifmw_openshift_kubeconfig }}"
api_key: "{{ cifmw_openshift_token | default(omit)}}"
context: "{{ cifmw_openshift_context | default(omit) }}"
namespace: "{{ cifmw_test_operator_namespace }}"
namespace: "{{ cifmw_test_operator_target_namespace }}"
kind: ClusterServiceVersion
api_version: operators.coreos.com/v1alpha1
register: csv_list
delay: 10
retries: 20
retries: 100
until: >-
{{
csv_list.resources |
Expand All @@ -100,7 +113,7 @@
}}
when: not cifmw_test_operator_dry_run | bool

- name: Get full name of the test-operator csv
- name: Get full name of the test-operator CSV in the target namespace
ansible.builtin.set_fact:
test_operator_csv_name: >-
{{
Expand All @@ -110,12 +123,12 @@
}}
when: not cifmw_test_operator_dry_run | bool

- name: Wait for the test-operator csv to Succeed
- name: Wait for the test-operator CSV to Succeed in the target namespace
kubernetes.core.k8s_info:
kubeconfig: "{{ cifmw_openshift_kubeconfig }}"
api_key: "{{ cifmw_openshift_token | default(omit)}}"
context: "{{ cifmw_openshift_context | default(omit) }}"
namespace: "{{ cifmw_test_operator_namespace }}"
namespace: "{{ cifmw_test_operator_target_namespace }}"
kind: ClusterServiceVersion
api_version: operators.coreos.com/v1alpha1
name: "{{ test_operator_csv_name }}"
Expand Down
18 changes: 9 additions & 9 deletions roles/test_operator/tasks/run-test-operator-job.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
kubeconfig: "{{ cifmw_openshift_kubeconfig }}"
api_key: "{{ cifmw_openshift_token | default(omit) }}"
context: "{{ cifmw_openshift_context | default(omit) }}"
namespace: "{{ cifmw_test_operator_namespace }}"
namespace: "{{ cifmw_test_operator_target_namespace }}"
kind: Job
label_selectors:
- "workflowStep={{ [(test_operator_workflow | length) - 1, 0] | max }}"
Expand Down Expand Up @@ -116,7 +116,7 @@
kind: Pod
metadata:
name: "test-operator-logs-pod-{{ run_test_fw }}-{{ test_operator_job_name }}"
namespace: "{{ cifmw_test_operator_namespace }}"
namespace: "{{ cifmw_test_operator_target_namespace }}"
spec:
containers:
- name: test-operator-logs-container
Expand All @@ -132,7 +132,7 @@
kubeconfig: "{{ cifmw_openshift_kubeconfig }}"
api_key: "{{ cifmw_openshift_token | default(omit) }}"
context: "{{ cifmw_openshift_context | default(omit) }}"
namespace: "{{ cifmw_test_operator_namespace }}"
namespace: "{{ cifmw_test_operator_target_namespace }}"
kind: Pod
name: "test-operator-logs-pod-{{ run_test_fw }}-{{ test_operator_job_name }}"
wait: true
Expand All @@ -148,7 +148,7 @@
vars:
pod_path: mnt/logs-{{ test_operator_job_name }}-step-{{ index }}
ansible.builtin.shell: >
oc cp -n {{ cifmw_test_operator_namespace }}
oc cp -n {{ cifmw_test_operator_target_namespace }}
openstack/test-operator-logs-pod-{{ run_test_fw }}-{{ test_operator_job_name }}:{{ pod_path }}
{{ cifmw_test_operator_artifacts_basedir }}
loop: "{{ logsPVCs.resources }}"
Expand All @@ -160,7 +160,7 @@
kubeconfig: "{{ cifmw_openshift_kubeconfig }}"
api_key: "{{ cifmw_openshift_token | default(omit)}}"
context: "{{ cifmw_openshift_context | default(omit) }}"
namespace: "{{ cifmw_test_operator_namespace }}"
namespace: "{{ cifmw_test_operator_target_namespace }}"
kind: Pod
register: pod_list
when: not cifmw_test_operator_dry_run | bool
Expand All @@ -171,7 +171,7 @@
kubeconfig: "{{ cifmw_openshift_kubeconfig }}"
api_key: "{{ cifmw_openshift_token | default(omit) }}"
context: "{{ cifmw_openshift_context | default(omit) }}"
namespace: "{{ cifmw_test_operator_namespace }}"
namespace: "{{ cifmw_test_operator_target_namespace }}"
kind: Pod
label_selectors:
- "instanceName={{ test_operator_job_name }}"
Expand Down Expand Up @@ -226,7 +226,7 @@
state: absent
api_version: test.openstack.org/v1beta1
name: "{{ test_operator_job_name }}"
namespace: "{{ cifmw_test_operator_namespace }}"
namespace: "{{ cifmw_test_operator_target_namespace }}"
wait: true
wait_timeout: 600

Expand All @@ -239,7 +239,7 @@
state: absent
api_version: v1
name: "{{ test_operator_crd_name }}"
namespace: "{{ cifmw_test_operator_namespace }}"
namespace: "{{ cifmw_test_operator_target_namespace }}"
wait: true
wait_timeout: 600

Expand All @@ -252,7 +252,7 @@
state: absent
api_version: v1
name: "test-operator-logs-pod-{{ run_test_fw }}-{{ test_operator_job_name }}"
namespace: "{{ cifmw_test_operator_namespace }}"
namespace: "{{ cifmw_test_operator_target_namespace }}"
wait: true
wait_timeout: 600
when:
Expand Down

0 comments on commit 042133f

Please sign in to comment.