From 4e7b8a419c4edee808cff7a36d0781395705df93 Mon Sep 17 00:00:00 2001 From: Daniel Pawlik Date: Wed, 14 Aug 2024 13:35:45 +0200 Subject: [PATCH] Add feature to install olm via rpm This commit provides a feature to setup the OLM via MicroShift RPM package. --- defaults/main.yaml | 2 ++ tasks/olm.yaml | 73 ++++++++++++++++++++++++++++------------------ 2 files changed, 47 insertions(+), 28 deletions(-) diff --git a/defaults/main.yaml b/defaults/main.yaml index 019b67e..c2f844a 100644 --- a/defaults/main.yaml +++ b/defaults/main.yaml @@ -97,6 +97,8 @@ microshift_ovn: {} # Install the OLM - https://olm.operatorframework.io/ setup_olm: false # https://github.com/operator-framework/operator-lifecycle-manager/releases +# NOTE: the olm_version is not working when microshift_olm_package is set to true. +microshift_olm_package: false olm_version: "v0.28.0" # Version of the Operator SDK diff --git a/tasks/olm.yaml b/tasks/olm.yaml index 3abcfc7..5f26a3a 100644 --- a/tasks/olm.yaml +++ b/tasks/olm.yaml @@ -1,32 +1,49 @@ --- -- name: Fetch operator-sdk - become: true - ansible.builtin.uri: - url: https://github.com/operator-framework/operator-sdk/releases/download/{{ operator_sdk_version }}/operator-sdk_linux_amd64 - dest: /usr/local/bin/operator-sdk - mode: "755" - status_code: - - 200 - - 304 +- name: Install OLM via rpm package + when: microshift_olm_package + block: + - name: Install OLM rpm + become: true + ansible.builtin.yum: + name: microshift-olm + state: present + enablerepo: microshift-rpms,microshift-deps-rpms + notify: Restart Microshift -- name: Check if OLM is installed - ansible.builtin.command: /usr/local/bin/operator-sdk olm status - register: olm_status - failed_when: olm_status.rc not in [0, 1] - changed_when: true + - name: Flush handlers + ansible.builtin.meta: flush_handlers -# Set ns/user to SCC before we run the OLM installation -- name: Ensure privileged SCC for OLM - ansible.builtin.command: - oc adm policy add-scc-to-user privileged system:serviceaccount:olm:{{ item }} - changed_when: true - loop: - - "default" - - "operatorhubio-catalog" - - "olm-operator-serviceaccount" +- name: Install OLM via OperatorSDK + when: not microshift_olm_package + block: + - name: Fetch operator-sdk + become: true + ansible.builtin.uri: + url: https://github.com/operator-framework/operator-sdk/releases/download/{{ operator_sdk_version }}/operator-sdk_linux_amd64 + dest: /usr/local/bin/operator-sdk + mode: "755" + status_code: + - 200 + - 304 -- name: Install OLM with SDK - ansible.builtin.command: | - /usr/local/bin/operator-sdk olm install --version {{ olm_version }} - when: olm_status.rc != 0 - changed_when: true + - name: Check if OLM is installed + ansible.builtin.command: /usr/local/bin/operator-sdk olm status + register: olm_status + failed_when: olm_status.rc not in [0, 1] + changed_when: true + + # Set ns/user to SCC before we run the OLM installation + - name: Ensure privileged SCC for OLM + ansible.builtin.command: + oc adm policy add-scc-to-user privileged system:serviceaccount:olm:{{ item }} + changed_when: true + loop: + - "default" + - "operatorhubio-catalog" + - "olm-operator-serviceaccount" + + - name: Install OLM with SDK + ansible.builtin.command: | + /usr/local/bin/operator-sdk olm install --version {{ olm_version }} + when: olm_status.rc != 0 + changed_when: true