From 042133f1c58895076e36ed42d823898233b1e9ef Mon Sep 17 00:00:00 2001 From: Lukas Piwowarski Date: Thu, 12 Dec 2024 08:57:49 -0500 Subject: [PATCH] [test-operator] Move to openstack-test-operator namespace 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] https://github.com/openstack-k8s-operators/test-operator/pull/264 --- roles/test_operator/README.md | 3 ++- roles/test_operator/defaults/main.yml | 11 ++++---- roles/test_operator/tasks/main.yml | 27 ++++++++++++++----- .../tasks/run-test-operator-job.yml | 18 ++++++------- 4 files changed, 37 insertions(+), 22 deletions(-) diff --git a/roles/test_operator/README.md b/roles/test_operator/README.md index 0ca3b0898f..12beadf59d 100644 --- a/roles/test_operator/README.md +++ b/roles/test_operator/README.md @@ -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` diff --git a/roles/test_operator/defaults/main.yml b/roles/test_operator/defaults/main.yml index cac69a585b..cdb517b8a9 100644 --- a/roles/test_operator/defaults/main.yml +++ b/roles/test_operator/defaults/main.yml @@ -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 @@ -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 }}" @@ -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 }}" @@ -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 }}" @@ -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 }}" diff --git a/roles/test_operator/tasks/main.yml b/roles/test_operator/tasks/main.yml index ca266d84bb..32cdaefef3 100644 --- a/roles/test_operator/tasks/main.yml +++ b/roles/test_operator/tasks/main.yml @@ -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 }}" @@ -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 @@ -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 | @@ -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: >- {{ @@ -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 }}" diff --git a/roles/test_operator/tasks/run-test-operator-job.yml b/roles/test_operator/tasks/run-test-operator-job.yml index 2299b250b3..93f2e0cf78 100644 --- a/roles/test_operator/tasks/run-test-operator-job.yml +++ b/roles/test_operator/tasks/run-test-operator-job.yml @@ -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 }}" @@ -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 @@ -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 @@ -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 }}" @@ -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 @@ -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 }}" @@ -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 @@ -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 @@ -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: