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 12, 2024
1 parent 93de89d commit ad1eca3
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 21 deletions.
11 changes: 6 additions & 5 deletions roles/test_operator/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
# Section 1: generic parameters (applied to all supported test frameworks)
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 @@ -102,7 +103,7 @@ cifmw_test_operator_tempest_config:
kind: Tempest
metadata:
name: "{{ test_operator_job_name }}"
namespace: "{{ cifmw_test_operator_namespace }}"
namespace: "{{ cifmw_test_operator_target_namespace }}"
spec:
containerImage: "{{ cifmw_test_operator_tempest_image }}:{{ cifmw_test_operator_tempest_image_tag }}"
storageClass: "{{ cifmw_test_operator_storage_class }}"
Expand Down Expand Up @@ -155,7 +156,7 @@ cifmw_test_operator_tobiko_config:
kind: Tobiko
metadata:
name: tobiko-tests
namespace: "{{ cifmw_test_operator_namespace }}"
namespace: "{{ cifmw_test_operator_target_namespace }}"
spec:
kubeconfigSecretName: "{{ cifmw_test_operator_tobiko_kubeconfig_secret }}"
storageClass: "{{ cifmw_test_operator_storage_class }}"
Expand Down Expand Up @@ -201,7 +202,7 @@ cifmw_test_operator_ansibletest_config:
kind: AnsibleTest
metadata:
name: "{{ test_operator_job_name }}"
namespace: "{{ cifmw_test_operator_namespace }}"
namespace: "{{ cifmw_test_operator_target_namespace }}"
spec:
containerImage: "{{ cifmw_test_operator_ansibletest_image }}:{{ cifmw_test_operator_ansibletest_image_tag }}"
extraConfigmapsMounts: "{{ cifmw_test_operator_ansibletest_extra_configmaps_mounts }}"
Expand Down Expand Up @@ -246,7 +247,7 @@ cifmw_test_operator_horizontest_config:
kind: HorizonTest
metadata:
name: "{{ cifmw_test_operator_horizontest_name }}"
namespace: "{{ cifmw_test_operator_namespace }}"
namespace: "{{ cifmw_test_operator_target_namespace }}"
spec:
storageClass: "{{ cifmw_test_operator_storage_class }}"
privileged: "{{ cifmw_test_operator_privileged }}"
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 @@ -30,6 +30,19 @@
run_ansibletest: "{{ cifmw_run_ansibletest | default('false') | bool }}"
run_horizontest: "{{ cifmw_run_horizontest | default('false') | bool }}"

- 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 @@ -45,7 +58,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 @@ -88,17 +101,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 @@ -107,7 +120,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 @@ -117,12 +130,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 ad1eca3

Please sign in to comment.