Skip to content

Commit

Permalink
[test-operator] Move away from Jobs to Pods
Browse files Browse the repository at this point in the history
With this PR [1] the test operator dropped the usage of OCP Jobs for
spawning of the test pods.

This change updates the test-operator role so that it works with the
new version of the test-operator that spawns test pods directly through
the OCP Pods object.

[1] openstack-k8s-operators/test-operator#266
  • Loading branch information
lpiwowar committed Dec 13, 2024
1 parent 93de89d commit 1b557d1
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 27 deletions.
4 changes: 2 additions & 2 deletions roles/test_operator/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ cifmw_test_operator_tempest_config:
apiVersion: test.openstack.org/v1beta1
kind: Tempest
metadata:
name: "{{ test_operator_job_name }}"
name: "{{ test_operator_instance_name }}"
namespace: "{{ cifmw_test_operator_namespace }}"
spec:
containerImage: "{{ cifmw_test_operator_tempest_image }}:{{ cifmw_test_operator_tempest_image_tag }}"
Expand Down Expand Up @@ -200,7 +200,7 @@ cifmw_test_operator_ansibletest_config:
apiVersion: test.openstack.org/v1beta1
kind: AnsibleTest
metadata:
name: "{{ test_operator_job_name }}"
name: "{{ test_operator_instance_name }}"
namespace: "{{ cifmw_test_operator_namespace }}"
spec:
containerImage: "{{ cifmw_test_operator_ansibletest_image }}:{{ cifmw_test_operator_ansibletest_image_tag }}"
Expand Down
8 changes: 4 additions & 4 deletions roles/test_operator/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@
vars:
run_test_fw: tempest
test_operator_config: "{{ cifmw_test_operator_tempest_config }}"
test_operator_job_name: "{{ cifmw_test_operator_tempest_name }}"
test_operator_instance_name: "{{ cifmw_test_operator_tempest_name }}"
test_operator_kind_name: "{{ cifmw_test_operator_tempest_kind_name }}"
test_operator_crd_name: "{{ cifmw_test_operator_tempest_crd_name }}"
test_operator_workflow: "{{ cifmw_test_operator_tempest_workflow }}"
Expand All @@ -148,7 +148,7 @@
vars:
run_test_fw: ansibletest
test_operator_config: "{{ cifmw_test_operator_ansibletest_config }}"
test_operator_job_name: "{{ cifmw_test_operator_ansibletest_name }}"
test_operator_instance_name: "{{ cifmw_test_operator_ansibletest_name }}"
test_operator_kind_name: "{{ cifmw_test_operator_ansibletest_kind_name }}"
test_operator_crd_name: "{{ cifmw_test_operator_ansibletest_crd_name }}"
test_operator_workflow: "{{ cifmw_test_operator_ansibletest_workflow }}"
Expand All @@ -159,7 +159,7 @@
vars:
run_test_fw: horizontest
test_operator_config: "{{ cifmw_test_operator_horizontest_config }}"
test_operator_job_name: "{{ cifmw_test_operator_horizontest_name }}"
test_operator_instance_name: "{{ cifmw_test_operator_horizontest_name }}"
test_operator_kind_name: "{{ cifmw_test_operator_horizontest_kind_name }}"
test_operator_crd_name: "{{ cifmw_test_operator_horizontest_crd_name }}"
test_operator_workflow: []
Expand All @@ -171,7 +171,7 @@
vars:
run_test_fw: tobiko
test_operator_config: "{{ cifmw_test_operator_tobiko_config }}"
test_operator_job_name: "{{ cifmw_test_operator_tobiko_name }}"
test_operator_instance_name: "{{ cifmw_test_operator_tobiko_name }}"
test_operator_kind_name: "{{ cifmw_test_operator_tobiko_kind_name }}"
test_operator_crd_name: "{{ cifmw_test_operator_tobiko_crd_name }}"
test_operator_workflow: "{{ cifmw_test_operator_tobiko_workflow }}"
Expand Down
52 changes: 32 additions & 20 deletions roles/test_operator/tasks/run-test-operator-job.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,35 +37,47 @@
definition: "{{ test_operator_cr }}"
when: not cifmw_test_operator_dry_run | bool

- name: Wait for the last job to be Completed - {{ run_test_fw }}
- name: Wait for the last Pod to be Completed - {{ run_test_fw }}
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 }}"
kind: Job
kind: Pod
label_selectors:
- "workflowStep={{ [(test_operator_workflow | length) - 1, 0] | max }}"
- "instanceName={{ test_operator_job_name }}"
retries: "{{ (cifmw_test_operator_timeout / 10) | round | int }}"
delay: 10
- "instanceName={{ test_operator_instance_name }}"
# retries: "{{ (cifmw_test_operator_timeout / 10) | round | int }}"
# delay: 10
until: >
testjob.resources[0].status.succeeded | default(0) | int >= 1 or
testjob.resources[0].status.failed | default(0) | int >= 1
testpod.resources[0].status.phase == "Succeeded" or
testpod.resources[0].phase == "Failed"
ignore_errors: true
register: testjob
register: testpod
when: not cifmw_test_operator_dry_run | bool

# - name: message
# debug:
# msg: "{{ testpod.status }}"

# - name: fail
# fail:
# msg: "tortuga"

# - name: debug
# debug:
# var: testpod

- name: Check whether timed out - {{ run_test_fw }}
ansible.builtin.set_fact:
testjob_timed_out: >-
{{ testjob.attempts == (cifmw_test_operator_timeout / 10) | round | int }}
testpod_timed_out: >-
{{ testpod.attempts == (cifmw_test_operator_timeout / 10) | round | int }}
when: not cifmw_test_operator_dry_run | bool

- name: Collect logs
when:
- not cifmw_test_operator_dry_run | bool
- not testjob_timed_out
- not testpod_timed_out
block:
- name: Reset volumes and volume_mounts to an empty list
ansible.builtin.set_fact:
Expand All @@ -79,7 +91,7 @@
context: "{{ cifmw_openshift_context | default(omit)}}"
kind: PersistentVolumeClaim
label_selectors:
- "instanceName={{ test_operator_job_name }}"
- "instanceName={{ test_operator_instance_name }}"
register: logsPVCs

- name: Set up volume mounts and volumes for all PVCs
Expand All @@ -88,7 +100,7 @@
{{
(volume_mounts | default([])) + [{
'name': "logs-volume-" ~ index,
'mountPath': "/mnt/logs-{{ test_operator_job_name }}-step-" ~ index
'mountPath': "/mnt/logs-{{ test_operator_instance_name }}-step-" ~ index
}]
}}
volumes: >
Expand All @@ -115,7 +127,7 @@
apiVersion: v1
kind: Pod
metadata:
name: "test-operator-logs-pod-{{ run_test_fw }}-{{ test_operator_job_name }}"
name: "test-operator-logs-pod-{{ run_test_fw }}-{{ test_operator_instance_name }}"
namespace: "{{ cifmw_test_operator_namespace }}"
spec:
containers:
Expand All @@ -134,7 +146,7 @@
context: "{{ cifmw_openshift_context | default(omit) }}"
namespace: "{{ cifmw_test_operator_namespace }}"
kind: Pod
name: "test-operator-logs-pod-{{ run_test_fw }}-{{ test_operator_job_name }}"
name: "test-operator-logs-pod-{{ run_test_fw }}-{{ test_operator_instance_name }}"
wait: true
register: logs_pod
until: logs_pod.resources[0].status.phase == "Running"
Expand All @@ -146,10 +158,10 @@
KUBECONFIG: "{{ cifmw_openshift_kubeconfig }}"
PATH: "{{ cifmw_path }}"
vars:
pod_path: mnt/logs-{{ test_operator_job_name }}-step-{{ index }}
pod_path: mnt/logs-{{ test_operator_instance_name }}-step-{{ index }}
ansible.builtin.shell: >
oc cp -n {{ cifmw_test_operator_namespace }}
openstack/test-operator-logs-pod-{{ run_test_fw }}-{{ test_operator_job_name }}:{{ pod_path }}
openstack/test-operator-logs-pod-{{ run_test_fw }}-{{ test_operator_instance_name }}:{{ pod_path }}
{{ cifmw_test_operator_artifacts_basedir }}
loop: "{{ logsPVCs.resources }}"
loop_control:
Expand All @@ -174,7 +186,7 @@
namespace: "{{ cifmw_test_operator_namespace }}"
kind: Pod
label_selectors:
- "instanceName={{ test_operator_job_name }}"
- "instanceName={{ test_operator_instance_name }}"
when: not cifmw_test_operator_dry_run | bool

- name: Get status from test pods
Expand Down Expand Up @@ -225,7 +237,7 @@
kind: "{{ test_operator_kind_name }}"
state: absent
api_version: test.openstack.org/v1beta1
name: "{{ test_operator_job_name }}"
name: "{{ test_operator_instance_name }}"
namespace: "{{ cifmw_test_operator_namespace }}"
wait: true
wait_timeout: 600
Expand All @@ -251,7 +263,7 @@
kind: Pod
state: absent
api_version: v1
name: "test-operator-logs-pod-{{ run_test_fw }}-{{ test_operator_job_name }}"
name: "test-operator-logs-pod-{{ run_test_fw }}-{{ test_operator_instance_name }}"
namespace: "{{ cifmw_test_operator_namespace }}"
wait: true
wait_timeout: 600
Expand Down
2 changes: 1 addition & 1 deletion roles/test_operator/tasks/tempest-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
tempest_list_allowed:
yaml_file: "{{ cifmw_test_operator_artifacts_basedir }}/list_allowed.yml"
groups: "{{ cifmw_test_operator_default_groups }}"
job: "{{ cifmw_test_operator_job_name | default(omit) }}"
job: "{{ cifmw_test_operator_instance_name | default(omit) }}"
register:
list_allowed

Expand Down

0 comments on commit 1b557d1

Please sign in to comment.