upgrade_nodes.yml 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. ---
  2. - name: Drain and upgrade nodes
  3. hosts: oo_nodes_to_upgrade
  4. # This var must be set with -e on invocation, as it is not a per-host inventory var
  5. # and is evaluated early. Values such as "20%" can also be used.
  6. serial: "{{ openshift_upgrade_nodes_serial | default(1) }}"
  7. any_errors_fatal: true
  8. roles:
  9. - openshift_facts
  10. - docker
  11. handlers:
  12. - include: ../../../../roles/openshift_node/handlers/main.yml
  13. static: yes
  14. pre_tasks:
  15. # TODO: To better handle re-trying failed upgrades, it would be nice to check if the node
  16. # or docker actually needs an upgrade before proceeding. Perhaps best to save this until
  17. # we merge upgrade functionality into the base roles and a normal config.yml playbook run.
  18. - name: Determine if node is currently scheduleable
  19. command: >
  20. {{ hostvars[groups.oo_first_master.0].openshift.common.client_binary }} get node {{ openshift.node.nodename | lower }} -o json
  21. register: node_output
  22. delegate_to: "{{ groups.oo_first_master.0 }}"
  23. changed_when: false
  24. when: inventory_hostname in groups.oo_nodes_to_upgrade
  25. - set_fact:
  26. was_schedulable: "{{ 'unschedulable' not in (node_output.stdout | from_json).spec }}"
  27. when: inventory_hostname in groups.oo_nodes_to_upgrade
  28. - name: Mark unschedulable if host is a node
  29. command: >
  30. {{ hostvars[groups.oo_first_master.0].openshift.common.client_binary }} adm manage-node {{ openshift.node.nodename | lower }} --schedulable=false
  31. delegate_to: "{{ groups.oo_first_master.0 }}"
  32. when: inventory_hostname in groups.oo_nodes_to_upgrade
  33. # NOTE: There is a transient "object has been modified" error here, allow a couple
  34. # retries for a more reliable upgrade.
  35. register: node_unsched
  36. until: node_unsched.rc == 0
  37. retries: 3
  38. delay: 1
  39. - name: Drain Node for Kubelet upgrade
  40. command: >
  41. {{ hostvars[groups.oo_first_master.0].openshift.common.admin_binary }} drain {{ openshift.node.nodename | lower }} --force --delete-local-data
  42. delegate_to: "{{ groups.oo_first_master.0 }}"
  43. when: inventory_hostname in groups.oo_nodes_to_upgrade
  44. tasks:
  45. - include: docker/upgrade.yml
  46. vars:
  47. # We will restart Docker ourselves after everything is ready:
  48. skip_docker_restart: True
  49. when: l_docker_upgrade is defined and l_docker_upgrade | bool and not openshift.common.is_atomic | bool
  50. - include: "{{ node_config_hook }}"
  51. when: node_config_hook is defined and inventory_hostname in groups.oo_nodes_to_upgrade
  52. - include: rpm_upgrade.yml
  53. vars:
  54. component: "node"
  55. openshift_version: "{{ openshift_pkg_version | default('') }}"
  56. when: inventory_hostname in groups.oo_nodes_to_upgrade and not openshift.common.is_containerized | bool
  57. - name: Remove obsolete docker-sdn-ovs.conf
  58. file: path=/etc/systemd/system/docker.service.d/docker-sdn-ovs.conf state=absent
  59. when: (deployment_type == 'openshift-enterprise' and openshift_release | version_compare('3.4', '>=')) or (deployment_type == 'origin' and openshift_release | version_compare('1.4', '>='))
  60. - include: containerized_node_upgrade.yml
  61. when: inventory_hostname in groups.oo_nodes_to_upgrade and openshift.common.is_containerized | bool
  62. - name: Ensure containerized services stopped before Docker restart
  63. service: name={{ item }} state=stopped
  64. with_items:
  65. - etcd_container
  66. - openvswitch
  67. - "{{ openshift.common.service_type }}-master"
  68. - "{{ openshift.common.service_type }}-master-api"
  69. - "{{ openshift.common.service_type }}-master-controllers"
  70. - "{{ openshift.common.service_type }}-node"
  71. failed_when: false
  72. when: openshift.common.is_containerized | bool
  73. - name: Upgrade openvswitch
  74. package:
  75. name: openvswitch
  76. state: latest
  77. register: ovs_pkg
  78. when: inventory_hostname in groups.oo_nodes_to_upgrade and not openshift.common.is_containerized | bool
  79. - name: Restart openvswitch
  80. systemd:
  81. name: openvswitch
  82. state: restarted
  83. when:
  84. - inventory_hostname in groups.oo_nodes_to_upgrade and not openshift.common.is_containerized | bool
  85. - ovs_pkg | changed
  86. # Mandatory Docker restart, ensure all containerized services are running:
  87. - include: docker/restart.yml
  88. - name: Restart rpm node service
  89. service: name="{{ openshift.common.service_type }}-node" state=restarted
  90. when: inventory_hostname in groups.oo_nodes_to_upgrade and not openshift.common.is_containerized | bool
  91. - name: Wait for node to be ready
  92. command: >
  93. {{ hostvars[groups.oo_first_master.0].openshift.common.client_binary }} get node {{ openshift.common.hostname | lower }} --no-headers
  94. register: node_output
  95. delegate_to: "{{ groups.oo_first_master.0 }}"
  96. when: inventory_hostname in groups.oo_nodes_to_upgrade
  97. until: "{{ node_output.stdout.split()[1].startswith('Ready')}}"
  98. # Give the node two minutes to come back online. Note that we pre-pull images now
  99. # so containerized services should restart quickly as well.
  100. retries: 24
  101. delay: 5
  102. - name: Set node schedulability
  103. command: >
  104. {{ hostvars[groups.oo_first_master.0].openshift.common.client_binary }} adm manage-node {{ openshift.node.nodename | lower }} --schedulable=true
  105. delegate_to: "{{ groups.oo_first_master.0 }}"
  106. when: inventory_hostname in groups.oo_nodes_to_upgrade and was_schedulable | bool
  107. register: node_sched
  108. until: node_sched.rc == 0
  109. retries: 3
  110. delay: 1