upgrade_control_plane.yml 13 KB

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