upgrade.yml 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. ---
  2. ###############################################################################
  3. # Upgrade Masters
  4. ###############################################################################
  5. # Create service signer cert when missing. Service signer certificate
  6. # is added to master config in the master_config_upgrade hook.
  7. - name: Determine if service signer cert must be created
  8. hosts: oo_first_master
  9. tasks:
  10. - name: Determine if service signer certificate must be created
  11. stat:
  12. path: "{{ openshift.common.config_base }}/master/service-signer.crt"
  13. register: service_signer_cert_stat
  14. changed_when: false
  15. - import_playbook: create_service_signer_cert.yml
  16. # oc adm migrate storage should be run prior to etcd v3 upgrade
  17. # See: https://github.com/openshift/origin/pull/14625#issuecomment-308467060
  18. - name: Pre master upgrade - Upgrade all storage
  19. hosts: oo_first_master
  20. roles:
  21. - openshift_facts
  22. tasks:
  23. - name: Upgrade all storage
  24. command: >
  25. {{ openshift_client_binary }} adm --config={{ openshift.common.config_base }}/master/admin.kubeconfig
  26. migrate storage --include=* --confirm
  27. register: l_pb_upgrade_control_plane_pre_upgrade_storage
  28. when: openshift_upgrade_pre_storage_migration_enabled | default(true) | bool
  29. failed_when:
  30. - l_pb_upgrade_control_plane_pre_upgrade_storage.rc != 0
  31. - openshift_upgrade_pre_storage_migration_fatal | default(true) | bool
  32. # Set openshift_master_facts separately. In order to reconcile
  33. # admission_config's, we currently must run openshift_master_facts and
  34. # then run openshift_facts.
  35. - name: Set OpenShift master facts
  36. hosts: oo_masters_to_config
  37. roles:
  38. - openshift_master_facts
  39. - name: configure vsphere svc account
  40. hosts: oo_first_master
  41. tasks:
  42. - include_role:
  43. name: openshift_cloud_provider
  44. tasks_from: vsphere-svc
  45. when:
  46. - openshift_cloudprovider_kind is defined
  47. - openshift_cloudprovider_kind == 'vsphere'
  48. - openshift_version | version_compare('3.9', '>=')
  49. # The main master upgrade play. Should handle all changes to the system in one pass, with
  50. # support for optional hooks to be defined.
  51. - name: Upgrade master
  52. hosts: oo_masters_to_config
  53. serial: 1
  54. roles:
  55. - openshift_facts
  56. tasks:
  57. # Run the pre-upgrade hook if defined:
  58. - debug: msg="Running master pre-upgrade hook {{ openshift_master_upgrade_pre_hook }}"
  59. when: openshift_master_upgrade_pre_hook is defined
  60. - include_tasks: "{{ openshift_master_upgrade_pre_hook }}"
  61. when: openshift_master_upgrade_pre_hook is defined
  62. - import_role:
  63. name: openshift_control_plane
  64. tasks_from: upgrade.yml
  65. - name: update vsphere provider master config
  66. include_role:
  67. name: openshift_control_plane
  68. tasks_from: update-vsphere
  69. when:
  70. - openshift_cloudprovider_kind is defined
  71. - openshift_cloudprovider_kind == 'vsphere'
  72. - openshift_version | version_compare('3.9', '>=')
  73. - name: Setup and enable bootstrapping options
  74. include_tasks: tasks/enable_bootstrap.yml
  75. # Run the upgrade hook prior to restarting services/system if defined:
  76. - debug: msg="Running master upgrade hook {{ openshift_master_upgrade_hook }}"
  77. when: openshift_master_upgrade_hook is defined
  78. - include_tasks: "{{ openshift_master_upgrade_hook }}"
  79. when: openshift_master_upgrade_hook is defined
  80. - name: Disable master controller
  81. service:
  82. name: "{{ openshift_service_type }}-master-controllers"
  83. enabled: false
  84. when: openshift.common.rolling_restart_mode == 'system'
  85. - include_tasks: tasks/restart_hosts.yml
  86. when: openshift.common.rolling_restart_mode == 'system'
  87. - include_tasks: tasks/restart_services.yml
  88. when: openshift.common.rolling_restart_mode == 'services'
  89. # Run the post-upgrade hook if defined:
  90. - debug: msg="Running master post-upgrade hook {{ openshift_master_upgrade_post_hook }}"
  91. when: openshift_master_upgrade_post_hook is defined
  92. - include_tasks: "{{ openshift_master_upgrade_post_hook }}"
  93. when: openshift_master_upgrade_post_hook is defined
  94. - name: Post master upgrade - Upgrade clusterpolicies storage
  95. command: >
  96. {{ openshift_client_binary }} adm --config={{ openshift.common.config_base }}/master/admin.kubeconfig
  97. migrate storage --include=clusterpolicies --confirm
  98. register: l_pb_upgrade_control_plane_post_upgrade_storage
  99. when:
  100. - openshift_upgrade_post_storage_migration_enabled | default(true) | bool
  101. - openshift_version is version_compare('3.7','<')
  102. failed_when:
  103. - l_pb_upgrade_control_plane_post_upgrade_storage.rc != 0
  104. - openshift_upgrade_post_storage_migration_fatal | default(false) | bool
  105. run_once: true
  106. delegate_to: "{{ groups.oo_first_master.0 }}"
  107. - set_fact:
  108. master_update_complete: True
  109. ##############################################################################
  110. # Gate on master update complete
  111. ##############################################################################
  112. - name: Gate on master update
  113. hosts: localhost
  114. connection: local
  115. tasks:
  116. - set_fact:
  117. master_update_completed: "{{ hostvars
  118. | lib_utils_oo_select_keys(groups.oo_masters_to_config)
  119. | lib_utils_oo_collect('inventory_hostname', {'master_update_complete': true}) }}"
  120. - set_fact:
  121. master_update_failed: "{{ groups.oo_masters_to_config | difference(master_update_completed) | list }}"
  122. - fail:
  123. msg: "Upgrade cannot continue. The following masters did not finish updating: {{ master_update_failed | join(',') }}"
  124. when: master_update_failed | length > 0
  125. ###############################################################################
  126. # Reconcile Cluster Roles, Cluster Role Bindings and Security Context Constraints
  127. ###############################################################################
  128. - name: Reconcile Cluster Roles and Cluster Role Bindings and Security Context Constraints
  129. hosts: oo_masters_to_config
  130. roles:
  131. - { role: openshift_cli }
  132. - { role: openshift_facts }
  133. vars:
  134. __master_shared_resource_viewer_file: "shared_resource_viewer_role.yaml"
  135. tasks:
  136. - name: Reconcile Cluster Roles
  137. command: >
  138. {{ openshift_client_binary }} adm --config={{ openshift.common.config_base }}/master/admin.kubeconfig
  139. policy reconcile-cluster-roles --additive-only=true --confirm -o name
  140. register: reconcile_cluster_role_result
  141. when: openshift_version is version_compare('3.7','<')
  142. changed_when:
  143. - reconcile_cluster_role_result.stdout != ''
  144. - reconcile_cluster_role_result.rc == 0
  145. run_once: true
  146. - name: Reconcile Cluster Role Bindings
  147. command: >
  148. {{ openshift_client_binary }} adm --config={{ openshift.common.config_base }}/master/admin.kubeconfig
  149. policy reconcile-cluster-role-bindings
  150. --exclude-groups=system:authenticated
  151. --exclude-groups=system:authenticated:oauth
  152. --exclude-groups=system:unauthenticated
  153. --exclude-users=system:anonymous
  154. --additive-only=true --confirm -o name
  155. when: openshift_version is version_compare('3.7','<')
  156. register: reconcile_bindings_result
  157. changed_when:
  158. - reconcile_bindings_result.stdout != ''
  159. - reconcile_bindings_result.rc == 0
  160. run_once: true
  161. - name: Reconcile Jenkins Pipeline Role Bindings
  162. command: >
  163. {{ openshift_client_binary }} adm --config={{ openshift.common.config_base }}/master/admin.kubeconfig policy reconcile-cluster-role-bindings system:build-strategy-jenkinspipeline --confirm -o name
  164. run_once: true
  165. register: reconcile_jenkins_role_binding_result
  166. changed_when:
  167. - reconcile_jenkins_role_binding_result.stdout != ''
  168. - reconcile_jenkins_role_binding_result.rc == 0
  169. when:
  170. - openshift_version is version_compare('3.7','<')
  171. - when: openshift_upgrade_target is version_compare('3.7','<')
  172. block:
  173. - name: Retrieve shared-resource-viewer
  174. oc_obj:
  175. state: list
  176. kind: role
  177. name: "shared-resource-viewer"
  178. namespace: "openshift"
  179. register: objout
  180. - name: Determine if shared-resource-viewer is protected
  181. set_fact:
  182. __shared_resource_viewer_protected: true
  183. when:
  184. - "'results' in objout"
  185. - "'results' in objout['results']"
  186. - "'annotations' in objout['results']['results'][0]['metadata']"
  187. - "'openshift.io/reconcile-protect' in objout['results']['results'][0]['metadata']['annotations']"
  188. - "objout['results']['results'][0]['metadata']['annotations']['openshift.io/reconcile-protect'] == 'true'"
  189. - copy:
  190. src: "{{ item }}"
  191. dest: "/tmp/{{ item }}"
  192. with_items:
  193. - "{{ __master_shared_resource_viewer_file }}"
  194. when: __shared_resource_viewer_protected is not defined
  195. - name: Fixup shared-resource-viewer role
  196. oc_obj:
  197. state: present
  198. kind: role
  199. name: "shared-resource-viewer"
  200. namespace: "openshift"
  201. files:
  202. - "/tmp/{{ __master_shared_resource_viewer_file }}"
  203. delete_after: true
  204. when: __shared_resource_viewer_protected is not defined
  205. register: result
  206. retries: 3
  207. delay: 5
  208. until: result.rc == 0
  209. ignore_errors: true
  210. - name: Reconcile Security Context Constraints
  211. command: >
  212. {{ openshift_client_binary }} adm policy --config={{ openshift.common.config_base }}/master/admin.kubeconfig reconcile-sccs --confirm --additive-only=true -o name
  213. register: reconcile_scc_result
  214. changed_when:
  215. - reconcile_scc_result.stdout != ''
  216. - reconcile_scc_result.rc == 0
  217. run_once: true
  218. - name: Migrate storage post policy reconciliation
  219. command: >
  220. {{ openshift_client_binary }} adm --config={{ openshift.common.config_base }}/master/admin.kubeconfig
  221. migrate storage --include=* --confirm
  222. run_once: true
  223. register: l_pb_upgrade_control_plane_post_upgrade_storage
  224. when: openshift_upgrade_post_storage_migration_enabled | default(true) | bool
  225. failed_when:
  226. - l_pb_upgrade_control_plane_post_upgrade_storage.rc != 0
  227. - openshift_upgrade_post_storage_migration_fatal | default(false) | bool
  228. - set_fact:
  229. reconcile_complete: True
  230. ##############################################################################
  231. # Gate on reconcile
  232. ##############################################################################
  233. - name: Gate on reconcile
  234. hosts: localhost
  235. connection: local
  236. tasks:
  237. - set_fact:
  238. reconcile_completed: "{{ hostvars
  239. | lib_utils_oo_select_keys(groups.oo_masters_to_config)
  240. | lib_utils_oo_collect('inventory_hostname', {'reconcile_complete': true}) }}"
  241. - set_fact:
  242. reconcile_failed: "{{ groups.oo_masters_to_config | difference(reconcile_completed) | list }}"
  243. - fail:
  244. msg: "Upgrade cannot continue. The following masters did not finish reconciling: {{ reconcile_failed | join(',') }}"
  245. when: reconcile_failed | length > 0
  246. - name: Drain and upgrade master nodes
  247. # There is no need to update nodes in the middle of double upgrade
  248. # This would skip node update to 3.8 during 3.7->3.9 upgrade
  249. hosts: "{{ l_double_upgrade_cp | default(False) | ternary('all:!all', 'oo_masters_to_config:&oo_nodes_to_upgrade') }}"
  250. # This var must be set with -e on invocation, as it is not a per-host inventory var
  251. # and is evaluated early. Values such as "20%" can also be used.
  252. serial: "{{ openshift_upgrade_control_plane_nodes_serial | default(1) }}"
  253. max_fail_percentage: "{{ openshift_upgrade_control_plane_nodes_max_fail_percentage | default(0) }}"
  254. pre_tasks:
  255. - name: Load lib_openshift modules
  256. import_role:
  257. name: lib_openshift
  258. # TODO: To better handle re-trying failed upgrades, it would be nice to check if the node
  259. # or docker actually needs an upgrade before proceeding. Perhaps best to save this until
  260. # we merge upgrade functionality into the base roles and a normal config.yml playbook run.
  261. - name: Mark node unschedulable
  262. oc_adm_manage_node:
  263. node: "{{ openshift.node.nodename | lower }}"
  264. schedulable: False
  265. delegate_to: "{{ groups.oo_first_master.0 }}"
  266. retries: 10
  267. delay: 5
  268. register: node_unschedulable
  269. until: node_unschedulable is succeeded
  270. - name: Drain Node for Kubelet upgrade
  271. command: >
  272. {{ hostvars[groups.oo_first_master.0]['first_master_client_binary'] }} adm drain {{ openshift.node.nodename | lower }}
  273. --config={{ openshift.common.config_base }}/master/admin.kubeconfig
  274. --force --delete-local-data --ignore-daemonsets
  275. --timeout={{ openshift_upgrade_nodes_drain_timeout | default(0) }}s
  276. delegate_to: "{{ groups.oo_first_master.0 }}"
  277. register: l_upgrade_control_plane_drain_result
  278. until: not (l_upgrade_control_plane_drain_result is failed)
  279. retries: "{{ 1 if ( openshift_upgrade_nodes_drain_timeout | default(0) | int ) == 0 else 0 }}"
  280. delay: 5
  281. failed_when:
  282. - l_upgrade_control_plane_drain_result is failed
  283. - openshift_upgrade_nodes_drain_timeout | default(0) | int == 0
  284. roles:
  285. - openshift_facts
  286. post_tasks:
  287. - import_role:
  288. name: openshift_node
  289. tasks_from: upgrade_pre.yml
  290. - import_role:
  291. name: openshift_node
  292. tasks_from: upgrade.yml
  293. - import_role:
  294. name: openshift_manage_node
  295. tasks_from: config.yml
  296. vars:
  297. openshift_master_host: "{{ groups.oo_first_master.0 }}"
  298. openshift_manage_node_is_master: true