diff --git a/.gitignore b/.gitignore index e19c4dd0..a50ed99b 100644 --- a/.gitignore +++ b/.gitignore @@ -11,6 +11,7 @@ tmp/ bin/ dist/ ocp-cluster/ +*.pyc # IDE folders .vscode/ diff --git a/ansible_pip_requirements.txt b/ansible_pip_requirements.txt index c9163633..f78914b4 100644 --- a/ansible_pip_requirements.txt +++ b/ansible_pip_requirements.txt @@ -11,3 +11,4 @@ rsa==4.9.1 --hash=sha256:68635866661c6836b8d39430f97a996acbd61bfa49406748ea24353 oauthlib==3.2.2 --hash=sha256:8139f29aac13e25d502680e9e19963e83f16838d48a0d71c287fe40e7067fbca jsonschema==4.26.0 --hash=sha256:d489f15263b8d200f8387e64b4c3a75f06629559fb73deb8fdfb525f2dab50ce rpds-py==0.30.0 --hash=sha256:47f236970bccb2233267d89173d3ad2703cd36a0e2a6e92d0560d333871a3d23 +click==8.3.3 --hash=sha256:398329ad4837b2ff7cbe1dd166a4c0f8900c3ca3a218de04466f38f6497f18a2 diff --git a/operators/openshift-pipelines-operator-rh/operator_update_pipeline.yaml b/operators/openshift-pipelines-operator-rh/operator_update_pipeline.yaml index b5eacc32..a7320cc8 100644 --- a/operators/openshift-pipelines-operator-rh/operator_update_pipeline.yaml +++ b/operators/openshift-pipelines-operator-rh/operator_update_pipeline.yaml @@ -91,8 +91,8 @@ script: | #!/bin/bash - cat < approve_installplans.py - {{ lookup('ansible.builtin.file', '../helpers/operator-update/approve_installplans.py') }} + cat < reconcile_operator_versions.py + {{ lookup('ansible.builtin.file', '../reconcile/operator_versions.py') }} EOF - name: operator-update image: "{{ oc_cli_image }}" @@ -100,7 +100,7 @@ script: | #!/bin/bash - python ./approve_installplans.py "{{ (_core_plugin_operators | default([])) + operators }}" "$(params.dry-run)" > "$(results.status-report.path)" + python ./reconcile_operator_versions.py "{{ (_core_plugin_operators | default([])) + operators }}" "$(params.dry-run)" > "$(results.status-report.path)" rc=$? echo -n "${rc}" > "$(results.exit-code.path)" exit "${rc}" diff --git a/playbooks/tasks/configure_operator.yaml b/playbooks/tasks/configure_operator.yaml index a715bdcb..629b3477 100644 --- a/playbooks/tasks/configure_operator.yaml +++ b/playbooks/tasks/configure_operator.yaml @@ -143,7 +143,7 @@ - r_sub_check.resources | length == 0 - operator.namespace != "openshift-operators" ansible.builtin.shell: | - python ../helpers/operator-update/approve_installplans.py "{{ [operator] }}" "False" + python ../reconcile/cli.py operator-versions --operators "{{ [operator] }}" --no-dry-run register: operator_update_result - name: Print the output diff --git a/reconcile/cli.py b/reconcile/cli.py new file mode 100644 index 00000000..3ca7a8f5 --- /dev/null +++ b/reconcile/cli.py @@ -0,0 +1,28 @@ +import click +import sys + +from operator_versions import reconcile as operator_versions_reconcile + + +@click.group() +def cli(): + pass + + +@cli.command() +@click.option("--operators", default="[]") +@click.option("--dry-run/--no-dry-run", default=False) +def operator_versions(operators, dry_run): + # rebuild sys.argv for the standalone script + sys.argv = ["operator_versions.py", operators, str(dry_run)] + + operator_versions_reconcile() + + +@cli.command() +def mgmt_cluster_version(): + raise click.ClickException("mgmt-cluster-version is not implemented yet") + + +if __name__ == "__main__": + cli() diff --git a/helpers/operator-update/approve_installplans.py b/reconcile/operator_versions.py similarity index 99% rename from helpers/operator-update/approve_installplans.py rename to reconcile/operator_versions.py index 0702dae3..51ca40c8 100755 --- a/helpers/operator-update/approve_installplans.py +++ b/reconcile/operator_versions.py @@ -149,7 +149,7 @@ def init_ns_op_version_map( return ns_op_version_map -def main(): +def reconcile(): try: operators = ast.literal_eval(sys.argv[1]) except (IndexError, ValueError, SyntaxError) as e: @@ -180,4 +180,4 @@ def main(): if __name__ == "__main__": - main() + reconcile()