upgrade.yml 10 KB

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