Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sap_hypervisor_node_preconfigure: replace use of oc with kubernetes.core.k8s #7

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ jobs:
pip3 install ansible-compat==3.0.2
pip3 install ansible-core==2.14.5
pip3 install ansible-lint==6.8.6
pip3 install jmespath==1.0.1

- name: Run ansible-lint
working-directory: /home/runner/work/community.sap_infrastructure/community.sap_infrastructure/roles/sap_hypervisor_node_preconfigure
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
---
- name: Label nodes
ansible.builtin.command: "oc label node {{ __sap_hypervisor_node_preconfigure_register_worker.name }} cpumanager=true --overwrite=true"
register: __sap_hypervisor_node_preconfigure_label_node_result
changed_when: __sap_hypervisor_node_preconfigure_label_node_result.rc != 0

- name: Include node network
ansible.builtin.include_tasks: node-network.yml
with_items: "{{ __sap_hypervisor_node_preconfigure_register_worker.networks }}"
Expand All @@ -14,6 +9,17 @@

# How to wait for node to be scheduleable? (NodeSchedulable)
- name: Wait for all k8s nodes to be ready
ansible.builtin.command: oc wait --for=condition=Ready nodes --all --timeout=3600s
register: __sap_hypervisor_node_preconfigure_register_nodes_ready
changed_when: __sap_hypervisor_node_preconfigure_register_nodes_ready.rc != 0
kubernetes.core.k8s_info:
kind: Node
register: __sap_hypervisor_node_preconfigure_register_nodes
until: __sap_hypervisor_node_preconfigure_register_nodes.resources | json_query('[?status.conditions[?type==`Ready` && status==`True`]].metadata.name') | length == __sap_hypervisor_node_preconfigure_register_nodes.resources | length
retries: 180
delay: 20
ignore_errors: True
changed_when: false

- name: Check and fail if any node is not ready
fail:
msg: "Node '{{ item.metadata.name }}' is not ready."
loop: "{{ __sap_hypervisor_node_preconfigure_register_nodes.resources }}"
when: not item.status.conditions | selectattr('type', 'equalto', 'Ready') | map(attribute='status') | list | first == 'True'
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,44 @@
ansible.builtin.pause:
seconds: 300

- name: Get Install Plan Name
- name: Get Install Plan Name from Subscription
retries: 10
delay: 10
ansible.builtin.command: oc get subscriptions/hco-operatorhub --namespace openshift-cnv --output=jsonpath='{$.status.installplan.name}'
kubernetes.core.k8s_info:
api_version: operators.coreos.com/v1alpha1
kind: Subscription
name: hco-operatorhub
namespace: openshift-cnv
register: __sap_hypervisor_node_preconfigure_register_cnv_subscription_install_plan_name
until: __sap_hypervisor_node_preconfigure_register_cnv_subscription_install_plan_name.stdout != ""
changed_when: __sap_hypervisor_node_preconfigure_register_cnv_subscription_install_plan_name.stdout != ""
until: __sap_hypervisor_node_preconfigure_register_cnv_subscription_install_plan_name.resources[0].status.installPlanRef.name is defined
changed_when: true

- name: Set Install Plan Name
set_fact:
install_plan_name: "{{ __sap_hypervisor_node_preconfigure_register_cnv_subscription_install_plan_name.resources[0].status.installPlanRef.name }}"


- name: Wait for Install Plan to finish
ansible.builtin.command: "oc wait installplan \
{{ __sap_hypervisor_node_preconfigure_register_cnv_subscription_install_plan_name.stdout }} --namespace openshift-cnv --for=condition='Installed' --timeout='5m'"
register: __sap_hypervisor_node_preconfigure_register_wait_for_installplan
changed_when: __sap_hypervisor_node_preconfigure_register_wait_for_installplan.rc != 0
vars:
install_plan_name: "{{ __sap_hypervisor_node_preconfigure_register_cnv_subscription_install_plan_name.stdout }}"
namespace: "openshift-cnv"
block:
- name: Get Install Plan details
kubernetes.core.k8s_info:
api_version: operators.coreos.com/v1alpha1
kind: InstallPlan
name: "{{ install_plan_name }}"
namespace: "{{ namespace }}"
register: __sap_hypervisor_node_preconfigure_register_wait_for_installplan
until: __sap_hypervisor_node_preconfigure_register_wait_for_installplan.resources[0].status.phase == "Complete"
retries: 60
delay: 5
ignore_errors: yes

- name: Fail if Install Plan is not Complete after waiting
ansible.builtin.fail:
msg: "Install Plan is not Complete after the specified wait period."
when: __sap_hypervisor_node_preconfigure_register_wait_for_installplan.resources[0].status.phase != "Complete"

- name: Wait
ansible.builtin.pause:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,20 @@

# How to wait for node to be scheduleable? (NodeSchedulable)
- name: Wait for all k8s nodes to be ready
ansible.builtin.command: oc wait --for=condition=Ready nodes --all --timeout=3600s
register: __sap_hypervisor_node_preconfigure_register_nodes_ready
changed_when: __sap_hypervisor_node_preconfigure_register_nodes_ready.rc != 0

- name: Print nodes
ansible.builtin.debug:
var: __sap_hypervisor_node_preconfigure_register_nodes_ready.stdout_lines
kubernetes.core.k8s_info:
kind: Node
register: __sap_hypervisor_node_preconfigure_register_nodes
until: __sap_hypervisor_node_preconfigure_register_nodes.resources | json_query('[?status.conditions[?type==`Ready` && status==`True`]].metadata.name') | length == __sap_hypervisor_node_preconfigure_register_nodes.resources | length
retries: 180
delay: 20
ignore_errors: True
changed_when: false

- name: Check and fail if any node is not ready
fail:
msg: "Node '{{ item.metadata.name }}' is not ready."
loop: "{{ __sap_hypervisor_node_preconfigure_register_nodes.resources }}"
when: not item.status.conditions | selectattr('type', 'equalto', 'Ready') | map(attribute='status') | list | first == 'True'

- name: Include Trident installation
ansible.builtin.include_tasks: "platform/{{ sap_hypervisor_node_platform }}/install-trident.yml"
Expand Down