Skip to content

Commit

Permalink
Merge pull request #456 from yashvardhannanavati/olm_variables
Browse files Browse the repository at this point in the history
[CVP-3949] Add olm.skipRange and olm.replaces to parsed_operator_data
  • Loading branch information
nmars authored Dec 5, 2023
2 parents d3837bc + 3994892 commit c3d6a83
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
56 changes: 56 additions & 0 deletions Dockerfiles/ci/run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

6 changes: 6 additions & 0 deletions roles/parse_operator_bundle/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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) }}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
Expand Down

0 comments on commit c3d6a83

Please sign in to comment.