upgrade.yml 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. ---
  2. ###############################################################################
  3. # Upgrade Masters
  4. ###############################################################################
  5. # Some change makes critical outage on current cluster.
  6. - name: Confirm upgrade will not make critical changes
  7. hosts: oo_first_master
  8. tasks:
  9. - name: Confirm Reconcile Security Context Constraints will not change current SCCs
  10. command: >
  11. {{ openshift_client_binary }} adm policy --config={{ openshift.common.config_base }}/master/admin.kubeconfig reconcile-sccs --additive-only=true -o name
  12. register: check_reconcile_scc_result
  13. when: openshift_reconcile_sccs_reject_change | default(true) | bool
  14. until: check_reconcile_scc_result.rc == 0
  15. retries: 3
  16. - fail:
  17. msg: >
  18. Changes to bootstrapped SCCs have been detected. Please review the changes by running
  19. "{{ openshift_client_binary }} adm policy --config={{ openshift.common.config_base }}/master/admin.kubeconfig reconcile-sccs --additive-only=true"
  20. After reviewing the changes please apply those changes by adding the '--confirm' flag.
  21. Do not modify the default SCCs. Customizing the default SCCs will cause this check to fail when upgrading.
  22. If you require non standard SCCs please refer to https://docs.openshift.org/latest/admin_guide/manage_scc.html
  23. when:
  24. - openshift_reconcile_sccs_reject_change | default(true) | bool
  25. - check_reconcile_scc_result.stdout != '' or check_reconcile_scc_result.rc != 0
  26. # Create service signer cert when missing. Service signer certificate
  27. # is added to master config in the master_config_upgrade hook.
  28. - name: Determine if service signer cert must be created
  29. hosts: oo_first_master
  30. tasks:
  31. - name: Determine if service signer certificate must be created
  32. stat:
  33. path: "{{ openshift.common.config_base }}/master/service-signer.crt"
  34. register: service_signer_cert_stat
  35. changed_when: false
  36. - name: verify api server
  37. command: >
  38. curl --silent --tlsv1.2
  39. --cacert {{ openshift.common.config_base }}/master/ca-bundle.crt
  40. {{ openshift.master.api_url }}/healthz/ready
  41. args:
  42. # Disables the following warning:
  43. # Consider using get_url or uri module rather than running curl
  44. warn: no
  45. register: api_available_output
  46. until: api_available_output.stdout == 'ok'
  47. retries: 120
  48. delay: 1
  49. changed_when: false
  50. - import_playbook: create_service_signer_cert.yml
  51. # oc adm migrate storage should be run prior to etcd v3 upgrade
  52. # See: https://github.com/openshift/origin/pull/14625#issuecomment-308467060
  53. - name: Pre master upgrade - Upgrade all storage
  54. hosts: oo_first_master
  55. roles:
  56. - openshift_facts
  57. tasks:
  58. - name: Wait for API health
  59. import_role:
  60. name: openshift_control_plane
  61. tasks_from: check_master_api_is_ready.yml
  62. - name: Upgrade all storage
  63. command: >
  64. {{ openshift_client_binary }} adm --config={{ openshift.common.config_base }}/master/admin.kubeconfig
  65. migrate storage --include=* --confirm
  66. register: l_pb_upgrade_control_plane_pre_upgrade_storage
  67. when: openshift_upgrade_pre_storage_migration_enabled | default(true) | bool
  68. until: l_pb_upgrade_control_plane_pre_upgrade_storage.rc == 0
  69. failed_when:
  70. - l_pb_upgrade_control_plane_pre_upgrade_storage.rc != 0
  71. - openshift_upgrade_pre_storage_migration_fatal | default(true) | bool
  72. retries: 6
  73. delay: 30
  74. - name: Migrate legacy HPA scale target refs
  75. command: >
  76. {{ openshift_client_binary }} adm --config={{ openshift.common.config_base }}/master/admin.kubeconfig
  77. migrate legacy-hpa --confirm
  78. register: migrate_legacy_hpa_result
  79. when: openshift_upgrade_pre_storage_migration_enabled | default(true) | bool
  80. failed_when:
  81. - migrate_legacy_hpa_result.rc != 0
  82. - openshift_upgrade_pre_storage_migration_fatal | default(true) | bool
  83. # Set openshift_master_facts separately. In order to reconcile
  84. # admission_config's, we currently must run openshift_master_facts and
  85. # then run openshift_facts.
  86. - name: Set OpenShift master facts
  87. hosts: oo_masters_to_config
  88. roles:
  89. - openshift_master_facts
  90. - name: configure vsphere svc account
  91. hosts: oo_first_master
  92. tasks:
  93. - import_role:
  94. name: openshift_cloud_provider
  95. tasks_from: vsphere-svc.yml
  96. when:
  97. - openshift_cloudprovider_kind is defined
  98. - openshift_cloudprovider_kind == 'vsphere'
  99. # The main master upgrade play. Should handle all changes to the system in one pass, with
  100. # support for optional hooks to be defined.
  101. - name: Upgrade master
  102. hosts: oo_masters_to_config
  103. serial: 1
  104. roles:
  105. - openshift_facts
  106. tasks:
  107. # Run the pre-upgrade hook if defined:
  108. - debug: msg="Running master pre-upgrade hook {{ openshift_master_upgrade_pre_hook }}"
  109. when: openshift_master_upgrade_pre_hook is defined
  110. - include_tasks: "{{ openshift_master_upgrade_pre_hook }}"
  111. when: openshift_master_upgrade_pre_hook is defined
  112. - import_role:
  113. name: openshift_control_plane
  114. tasks_from: upgrade.yml
  115. - name: update vsphere provider master config
  116. import_role:
  117. name: openshift_cloud_provider
  118. tasks_from: update-vsphere.yml
  119. when:
  120. - openshift_cloudprovider_kind is defined
  121. - openshift_cloudprovider_kind == 'vsphere'
  122. # Run the upgrade hook prior to restarting services/system if defined:
  123. - debug: msg="Running master upgrade hook {{ openshift_master_upgrade_hook }}"
  124. when: openshift_master_upgrade_hook is defined
  125. - include_tasks: "{{ openshift_master_upgrade_hook }}"
  126. when: openshift_master_upgrade_hook is defined
  127. - name: Lay down the static configuration
  128. import_role:
  129. name: openshift_control_plane
  130. tasks_from: static.yml
  131. - import_tasks: tasks/restart_hosts.yml
  132. when: openshift_rolling_restart_mode | default('services') == 'system'
  133. - import_tasks: tasks/restart_services.yml
  134. when: openshift_rolling_restart_mode | default('services') == 'services'
  135. # Run the post-upgrade hook if defined:
  136. - debug: msg="Running master post-upgrade hook {{ openshift_master_upgrade_post_hook }}"
  137. when: openshift_master_upgrade_post_hook is defined
  138. - include_tasks: "{{ openshift_master_upgrade_post_hook }}"
  139. when: openshift_master_upgrade_post_hook is defined
  140. - set_fact:
  141. master_update_complete: True
  142. ##############################################################################
  143. # Gate on master update complete
  144. ##############################################################################
  145. - name: Gate on master update
  146. hosts: localhost
  147. connection: local
  148. tasks:
  149. - set_fact:
  150. master_update_completed: "{{ hostvars
  151. | lib_utils_oo_select_keys(groups.oo_masters_to_config)
  152. | lib_utils_oo_collect('inventory_hostname', {'master_update_complete': true}) }}"
  153. - set_fact:
  154. master_update_failed: "{{ groups.oo_masters_to_config | difference(master_update_completed) | list }}"
  155. - fail:
  156. msg: "Upgrade cannot continue. The following masters did not finish updating: {{ master_update_failed | join(',') }}"
  157. when: master_update_failed | length > 0
  158. ###############################################################################
  159. # Reconcile Cluster Roles, Cluster Role Bindings and Security Context Constraints
  160. ###############################################################################
  161. - name: Reconcile Cluster Roles and Cluster Role Bindings and Security Context Constraints
  162. hosts: oo_masters_to_config
  163. roles:
  164. - { role: openshift_cli }
  165. - { role: openshift_facts }
  166. vars:
  167. __master_shared_resource_viewer_file: "shared_resource_viewer_role.yaml"
  168. tasks:
  169. - name: Wait for API health
  170. import_role:
  171. name: openshift_control_plane
  172. tasks_from: check_master_api_is_ready.yml
  173. - name: Reconcile Security Context Constraints
  174. command: >
  175. {{ openshift_client_binary }} adm policy --config={{ openshift.common.config_base }}/master/admin.kubeconfig reconcile-sccs --confirm --additive-only=true -o name
  176. register: reconcile_scc_result
  177. changed_when:
  178. - reconcile_scc_result.stdout != ''
  179. - reconcile_scc_result.rc == 0
  180. run_once: true
  181. - name: Migrate storage post policy reconciliation
  182. command: >
  183. {{ openshift_client_binary }} adm --config={{ openshift.common.config_base }}/master/admin.kubeconfig
  184. migrate storage --include=* --confirm
  185. run_once: true
  186. register: l_pb_upgrade_control_plane_post_upgrade_storage
  187. when: openshift_upgrade_post_storage_migration_enabled | default(true) | bool
  188. until: l_pb_upgrade_control_plane_post_upgrade_storage.rc == 0
  189. failed_when:
  190. - l_pb_upgrade_control_plane_post_upgrade_storage.rc != 0
  191. - openshift_upgrade_post_storage_migration_fatal | default(false) | bool
  192. retries: 6
  193. delay: 30
  194. - set_fact:
  195. reconcile_complete: True
  196. ##############################################################################
  197. # Gate on reconcile
  198. ##############################################################################
  199. - name: Gate on reconcile
  200. hosts: localhost
  201. connection: local
  202. tasks:
  203. - set_fact:
  204. reconcile_completed: "{{ hostvars
  205. | lib_utils_oo_select_keys(groups.oo_masters_to_config)
  206. | lib_utils_oo_collect('inventory_hostname', {'reconcile_complete': true}) }}"
  207. - set_fact:
  208. reconcile_failed: "{{ groups.oo_masters_to_config | difference(reconcile_completed) | list }}"
  209. - fail:
  210. msg: "Upgrade cannot continue. The following masters did not finish reconciling: {{ reconcile_failed | join(',') }}"
  211. when: reconcile_failed | length > 0
  212. - name: Drain and upgrade master nodes
  213. hosts: oo_masters_to_config:&oo_nodes_to_upgrade
  214. # This var must be set with -e on invocation, as it is not a per-host inventory var
  215. # and is evaluated early. Values such as "20%" can also be used.
  216. serial: "{{ openshift_upgrade_control_plane_nodes_serial | default(1) }}"
  217. max_fail_percentage: "{{ openshift_upgrade_control_plane_nodes_max_fail_percentage | default(0) }}"
  218. pre_tasks:
  219. - name: Load lib_openshift modules
  220. import_role:
  221. name: lib_openshift
  222. roles:
  223. - openshift_facts
  224. post_tasks:
  225. - import_role:
  226. name: openshift_manage_node
  227. tasks_from: config.yml
  228. vars:
  229. openshift_master_host: "{{ groups.oo_first_master.0 }}"
  230. openshift_manage_node_is_master: true