diff --git a/roles/olm_operator/tasks/main.yml b/roles/olm_operator/tasks/main.yml index 9d2343913..111bcefd8 100644 --- a/roles/olm_operator/tasks/main.yml +++ b/roles/olm_operator/tasks/main.yml @@ -130,7 +130,7 @@ namespace: "{{ namespace }}" spec: channel: "{{ desired_channel }}" - installPlanApproval: "Automatic" + installPlanApproval: "{{ (starting_csv | default('') | length) | ternary('Manual', 'Automatic') }}" config: resources: {} name: "{{ operator }}" @@ -138,6 +138,37 @@ sourceNamespace: "{{ source_ns }}" startingCSV: "{{ operator_csv }}" + - name: Check for install plans + community.kubernetes.k8s_info: + api: operators.coreos.com/v1alpha1 + kind: InstallPlan + namespace: "{{ namespace }}" + register: _oo_install_plans + no_log: true + retries: 5 + delay: 5 + until: + - _oo_install_plans.resources is defined + - _oo_install_plans.resources | length + + - name: Approve only the install plan for the specific CSV + vars: + query: "resources[? spec.approved == `false` && contains(spec.clusterServiceVersionNames, '{{ starting_csv }}')]" + community.kubernetes.k8s: + definition: + apiVersion: operators.coreos.com/v1alpha1 + kind: InstallPlan + metadata: + name: "{{ install_plan.metadata.name }}" + namespace: "{{ namespace }}" + spec: + approved: true + loop: "{{ _oo_install_plans | json_query(query) | default([]) }}" + loop_control: + loop_var: install_plan + when: + - starting_csv | default('') | length > 0 + - name: Wait for CSV to be ready community.kubernetes.k8s_info: api: operators.coreos.com/v1alpha1