From 0fb4b140caaccf3e981dbd92e97a4e897fa70dfa Mon Sep 17 00:00:00 2001 From: Beto Rodriguez Date: Mon, 9 Dec 2024 14:47:01 -0600 Subject: [PATCH 1/5] Handle startingCSV cases --- roles/olm_operator/tasks/main.yml | 34 ++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/roles/olm_operator/tasks/main.yml b/roles/olm_operator/tasks/main.yml index 9d2343913..4ce77a58b 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,38 @@ sourceNamespace: "{{ source_ns }}" startingCSV: "{{ operator_csv }}" + - name: Approve the install plan for the desired StartingCSV + when: + - starting_csv | default('') | length + block: + - name: Get created install plans + community.kubernetes.k8s_info: + api: operators.coreos.com/v1alpha1 + kind: InstallPlan + namespace: "{{ namespace }}" + register: _oo_install_plans + retries: 5 + delay: 5 + until: + - _oo_install_plans.resources is defined + - _oo_install_plans.resources | length + + - name: Approve 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) }}" + loop_control: + loop_var: install_plan + - name: Wait for CSV to be ready community.kubernetes.k8s_info: api: operators.coreos.com/v1alpha1 From 8c0662c62aefa20d6a0be166da2848a8773d4200 Mon Sep 17 00:00:00 2001 From: Jose Alberto Rodriguez Date: Mon, 9 Dec 2024 15:07:52 -0600 Subject: [PATCH 2/5] Update roles/olm_operator/tasks/main.yml Co-authored-by: Tony Garcia --- roles/olm_operator/tasks/main.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/roles/olm_operator/tasks/main.yml b/roles/olm_operator/tasks/main.yml index 4ce77a58b..dac5e4ebc 100644 --- a/roles/olm_operator/tasks/main.yml +++ b/roles/olm_operator/tasks/main.yml @@ -156,7 +156,8 @@ - name: Approve the install plan for the specific CSV vars: - query: "resources[? spec.approved == `false` && contains(spec.clusterServiceVersionNames, '{{ starting_csv }}')]" + query: "resources[? !spec.approved && contains(spec.clusterServiceVersionNames, '{{ starting_csv }}')]" +`` community.kubernetes.k8s: definition: apiVersion: operators.coreos.com/v1alpha1 From 5343990d22b300a5649697761d062b21b6341973 Mon Sep 17 00:00:00 2001 From: Beto Rodriguez Date: Mon, 9 Dec 2024 15:09:18 -0600 Subject: [PATCH 3/5] Remove extra chars --- roles/olm_operator/tasks/main.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/roles/olm_operator/tasks/main.yml b/roles/olm_operator/tasks/main.yml index dac5e4ebc..1a8b56a5e 100644 --- a/roles/olm_operator/tasks/main.yml +++ b/roles/olm_operator/tasks/main.yml @@ -157,7 +157,6 @@ - name: Approve the install plan for the specific CSV vars: query: "resources[? !spec.approved && contains(spec.clusterServiceVersionNames, '{{ starting_csv }}')]" -`` community.kubernetes.k8s: definition: apiVersion: operators.coreos.com/v1alpha1 From fa2a1cd3a698e66e4f5c7ae8d6c5fa2143bf33f6 Mon Sep 17 00:00:00 2001 From: Beto Rodriguez Date: Mon, 9 Dec 2024 17:02:23 -0600 Subject: [PATCH 4/5] Fix condition --- roles/olm_operator/tasks/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/olm_operator/tasks/main.yml b/roles/olm_operator/tasks/main.yml index 1a8b56a5e..ffe1ce0b4 100644 --- a/roles/olm_operator/tasks/main.yml +++ b/roles/olm_operator/tasks/main.yml @@ -140,7 +140,7 @@ - name: Approve the install plan for the desired StartingCSV when: - - starting_csv | default('') | length + - starting_csv | default('') | length > 0 block: - name: Get created install plans community.kubernetes.k8s_info: From 917a8ca00b9cac4d3ec6c9e74efa0ec43eb59647 Mon Sep 17 00:00:00 2001 From: Beto Rodriguez Date: Mon, 9 Dec 2024 18:58:29 -0600 Subject: [PATCH 5/5] Fix conditions and block --- roles/olm_operator/tasks/main.yml | 57 +++++++++++++++---------------- 1 file changed, 28 insertions(+), 29 deletions(-) diff --git a/roles/olm_operator/tasks/main.yml b/roles/olm_operator/tasks/main.yml index ffe1ce0b4..111bcefd8 100644 --- a/roles/olm_operator/tasks/main.yml +++ b/roles/olm_operator/tasks/main.yml @@ -138,37 +138,36 @@ sourceNamespace: "{{ source_ns }}" startingCSV: "{{ operator_csv }}" - - name: Approve the install plan for the desired StartingCSV + - 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 - block: - - name: Get created install plans - community.kubernetes.k8s_info: - api: operators.coreos.com/v1alpha1 - kind: InstallPlan - namespace: "{{ namespace }}" - register: _oo_install_plans - retries: 5 - delay: 5 - until: - - _oo_install_plans.resources is defined - - _oo_install_plans.resources | length - - - name: Approve the install plan for the specific CSV - vars: - query: "resources[? !spec.approved && 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) }}" - loop_control: - loop_var: install_plan - name: Wait for CSV to be ready community.kubernetes.k8s_info: