upgrade.yml 9.9 KB

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