upgrade_control_plane.yml 13 KB

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