From 399489286213f954711906adb08bac7ba40b13d5 Mon Sep 17 00:00:00 2001 From: Yashvardhan Nanavati Date: Wed, 29 Nov 2023 00:20:21 -0500 Subject: [PATCH] [CVP-3949] Add olm.skipRange and olm.replaces to parsed_operator_data --- Dockerfiles/ci/run_tests.py | 56 +++++++++++++++++++ roles/parse_operator_bundle/tasks/main.yml | 6 ++ .../templates/parsed_operator_data.yml.j2 | 6 ++ 3 files changed, 68 insertions(+) diff --git a/Dockerfiles/ci/run_tests.py b/Dockerfiles/ci/run_tests.py index f3af13b5..cbd0068d 100755 --- a/Dockerfiles/ci/run_tests.py +++ b/Dockerfiles/ci/run_tests.py @@ -320,6 +320,62 @@ def test_extract_operator_bundle_with_infrastructure_features(self): self.assertIn('operator_feature_token_auth_azure: "False"', parsed_output) self.assertIn('operator_feature_token_auth_gcp: "False"', parsed_output) + def test_extract_operator_bundle_with_skiprange_and_replaces(self): + operator_work_dir = "{}/test_extract_operator_bundle_with_skiprange_and_replaces".format(self.test_dir) + work_dir = operator_work_dir + operator_dir = "{}/test-operator".format(operator_work_dir) + operator_bundle_dir = "{}/operator-bundle".format(operator_work_dir) + bundle_image = "quay.io/cvpops/test-operator:with-skiprange-and-replaces" + exec_cmd = "ansible-playbook -vvv -i localhost, --connection local \ + operator-test-playbooks/extract-operator-bundle.yml \ + -e 'operator_dir={operator_dir}' \ + -e 'bundle_image={bundle_image}' \ + -e 'operator_work_dir={operator_work_dir}' \ + -e 'operator_bundle_dir={operator_bundle_dir}' \ + -e 'work_dir={work_dir}'".format(operator_dir=operator_dir, + operator_work_dir=operator_work_dir, + operator_bundle_dir=operator_bundle_dir, + bundle_image=bundle_image, + work_dir=work_dir) + playbook_command = subprocess.run(exec_cmd, shell=True) + + print(playbook_command.returncode) + self.assertTrue(playbook_command.returncode == 0) + self.assertTrue(path.exists("{}/parsed_operator_data.yml".format(work_dir))) + with open("{}/parsed_operator_data.yml".format(work_dir), "r") as fd: + parsed_output = fd.read() + print(parsed_output) + self.assertIn('olm_replaces: "gatekeeper-operator-product.v0.2.6"', parsed_output) + self.assertIn('olm_skipRange: "<3.11.0"', parsed_output) + + + def test_extract_operator_bundle_with_skiprange_and_without_replaces(self): + operator_work_dir = "{}/test_extract_operator_bundle_with_skiprange_and_without_replaces".format(self.test_dir) + work_dir = operator_work_dir + operator_dir = "{}/test-operator".format(operator_work_dir) + operator_bundle_dir = "{}/operator-bundle".format(operator_work_dir) + bundle_image = "quay.io/cvpops/test-operator:with-skiprange-and-without-replaces" + exec_cmd = "ansible-playbook -vvv -i localhost, --connection local \ + operator-test-playbooks/extract-operator-bundle.yml \ + -e 'operator_dir={operator_dir}' \ + -e 'bundle_image={bundle_image}' \ + -e 'operator_work_dir={operator_work_dir}' \ + -e 'operator_bundle_dir={operator_bundle_dir}' \ + -e 'work_dir={work_dir}'".format(operator_dir=operator_dir, + operator_work_dir=operator_work_dir, + operator_bundle_dir=operator_bundle_dir, + bundle_image=bundle_image, + work_dir=work_dir) + playbook_command = subprocess.run(exec_cmd, shell=True) + + print(playbook_command.returncode) + self.assertTrue(playbook_command.returncode == 0) + self.assertTrue(path.exists("{}/parsed_operator_data.yml".format(work_dir))) + with open("{}/parsed_operator_data.yml".format(work_dir), "r") as fd: + parsed_output = fd.read() + print(parsed_output) + self.assertNotIn('olm_replaces', parsed_output) + if __name__ == '__main__': unittest.main() diff --git a/roles/parse_operator_bundle/tasks/main.yml b/roles/parse_operator_bundle/tasks/main.yml index 48164f21..5dfe5376 100644 --- a/roles/parse_operator_bundle/tasks/main.yml +++ b/roles/parse_operator_bundle/tasks/main.yml @@ -126,6 +126,12 @@ operator_feature_token_auth_gcp: "{{ (csv_vars | from_yaml).metadata.annotations['features.operators.openshift.io/token-auth-gcp'] | default(omit) }}" ignore_errors: true + - name: "Determine olm.skipRange and olm.replaces values" + set_fact: + olm_skipRange: "{{ (csv_vars | from_yaml).metadata.annotations['olm.skipRange'] | default(omit) }}" + olm_replaces: "{{ (csv_vars | from_yaml).spec['replaces'] | default(omit) }}" + ignore_errors: true + - name: "Determine operator_allnamespaces_support" set_fact: operator_allnamespaces_support: "{{ (csv_vars | from_yaml).spec.installModes | json_query(query) }}" diff --git a/roles/parse_operator_bundle/templates/parsed_operator_data.yml.j2 b/roles/parse_operator_bundle/templates/parsed_operator_data.yml.j2 index 39de38ee..d7228cfe 100644 --- a/roles/parse_operator_bundle/templates/parsed_operator_data.yml.j2 +++ b/roles/parse_operator_bundle/templates/parsed_operator_data.yml.j2 @@ -30,6 +30,12 @@ crd_paths: {% endfor %} {% endif %} ocp_versions: "{{ ocp_versions }}" +{% if olm_skipRange is defined %} +olm_skipRange: "{{ olm_skipRange }}" +{% endif %} +{% if olm_replaces is defined %} +olm_replaces: "{{ olm_replaces }}" +{% endif %} {% if operator_feature_disconnected is defined %} operator_feature_disconnected: "{{ operator_feature_disconnected }}" {% endif %}