upgrade_control_plane.yml 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  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. - import_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. - import_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. tasks:
  95. - set_fact:
  96. master_update_completed: "{{ hostvars
  97. | lib_utils_oo_select_keys(groups.oo_masters_to_config)
  98. | lib_utils_oo_collect('inventory_hostname', {'master_update_complete': true}) }}"
  99. - set_fact:
  100. master_update_failed: "{{ groups.oo_masters_to_config | difference(master_update_completed) | list }}"
  101. - fail:
  102. msg: "Upgrade cannot continue. The following masters did not finish updating: {{ master_update_failed | join(',') }}"
  103. when: master_update_failed | length > 0
  104. ###############################################################################
  105. # Reconcile Cluster Roles, Cluster Role Bindings and Security Context Constraints
  106. ###############################################################################
  107. - name: Reconcile Cluster Roles and Cluster Role Bindings and Security Context Constraints
  108. hosts: oo_masters_to_config
  109. roles:
  110. - { role: openshift_cli }
  111. vars:
  112. __master_shared_resource_viewer_file: "shared_resource_viewer_role.yaml"
  113. tasks:
  114. - name: Reconcile Cluster Roles
  115. command: >
  116. {{ openshift_client_binary }} adm --config={{ openshift.common.config_base }}/master/admin.kubeconfig
  117. policy reconcile-cluster-roles --additive-only=true --confirm -o name
  118. register: reconcile_cluster_role_result
  119. when: openshift_version is version_compare('3.7','<')
  120. changed_when:
  121. - reconcile_cluster_role_result.stdout != ''
  122. - reconcile_cluster_role_result.rc == 0
  123. run_once: true
  124. - name: Reconcile Cluster Role Bindings
  125. command: >
  126. {{ openshift_client_binary }} adm --config={{ openshift.common.config_base }}/master/admin.kubeconfig
  127. policy reconcile-cluster-role-bindings
  128. --exclude-groups=system:authenticated
  129. --exclude-groups=system:authenticated:oauth
  130. --exclude-groups=system:unauthenticated
  131. --exclude-users=system:anonymous
  132. --additive-only=true --confirm -o name
  133. when: openshift_version is version_compare('3.7','<')
  134. register: reconcile_bindings_result
  135. changed_when:
  136. - reconcile_bindings_result.stdout != ''
  137. - reconcile_bindings_result.rc == 0
  138. run_once: true
  139. - name: Reconcile Jenkins Pipeline Role Bindings
  140. command: >
  141. {{ openshift_client_binary }} adm --config={{ openshift.common.config_base }}/master/admin.kubeconfig policy reconcile-cluster-role-bindings system:build-strategy-jenkinspipeline --confirm -o name
  142. run_once: true
  143. register: reconcile_jenkins_role_binding_result
  144. changed_when:
  145. - reconcile_jenkins_role_binding_result.stdout != ''
  146. - reconcile_jenkins_role_binding_result.rc == 0
  147. when:
  148. - openshift_version is version_compare('3.7','<')
  149. - when: openshift_upgrade_target is version_compare('3.7','<')
  150. block:
  151. - name: Retrieve shared-resource-viewer
  152. oc_obj:
  153. state: list
  154. kind: role
  155. name: "shared-resource-viewer"
  156. namespace: "openshift"
  157. register: objout
  158. - name: Determine if shared-resource-viewer is protected
  159. set_fact:
  160. __shared_resource_viewer_protected: true
  161. when:
  162. - "'results' in objout"
  163. - "'results' in objout['results']"
  164. - "'annotations' in objout['results']['results'][0]['metadata']"
  165. - "'openshift.io/reconcile-protect' in objout['results']['results'][0]['metadata']['annotations']"
  166. - "objout['results']['results'][0]['metadata']['annotations']['openshift.io/reconcile-protect'] == 'true'"
  167. - copy:
  168. src: "{{ item }}"
  169. dest: "/tmp/{{ item }}"
  170. with_items:
  171. - "{{ __master_shared_resource_viewer_file }}"
  172. when: __shared_resource_viewer_protected is not defined
  173. - name: Fixup shared-resource-viewer role
  174. oc_obj:
  175. state: present
  176. kind: role
  177. name: "shared-resource-viewer"
  178. namespace: "openshift"
  179. files:
  180. - "/tmp/{{ __master_shared_resource_viewer_file }}"
  181. delete_after: true
  182. when: __shared_resource_viewer_protected is not defined
  183. register: result
  184. retries: 3
  185. delay: 5
  186. until: result.rc == 0
  187. ignore_errors: true
  188. - name: Reconcile Security Context Constraints
  189. command: >
  190. {{ openshift_client_binary }} adm policy --config={{ openshift.common.config_base }}/master/admin.kubeconfig reconcile-sccs --confirm --additive-only=true -o name
  191. register: reconcile_scc_result
  192. changed_when:
  193. - reconcile_scc_result.stdout != ''
  194. - reconcile_scc_result.rc == 0
  195. run_once: true
  196. - name: Migrate storage post policy reconciliation
  197. command: >
  198. {{ openshift_client_binary }} adm --config={{ openshift.common.config_base }}/master/admin.kubeconfig
  199. migrate storage --include=* --confirm
  200. run_once: true
  201. register: l_pb_upgrade_control_plane_post_upgrade_storage
  202. when: openshift_upgrade_post_storage_migration_enabled | default(true) | bool
  203. failed_when:
  204. - openshift_upgrade_post_storage_migration_enabled | default(true) | bool
  205. - l_pb_upgrade_control_plane_post_upgrade_storage.rc != 0
  206. - openshift_upgrade_post_storage_migration_fatal | default(false) | bool
  207. - set_fact:
  208. reconcile_complete: True
  209. ##############################################################################
  210. # Gate on reconcile
  211. ##############################################################################
  212. - name: Gate on reconcile
  213. hosts: localhost
  214. connection: local
  215. tasks:
  216. - set_fact:
  217. reconcile_completed: "{{ hostvars
  218. | lib_utils_oo_select_keys(groups.oo_masters_to_config)
  219. | lib_utils_oo_collect('inventory_hostname', {'reconcile_complete': true}) }}"
  220. - set_fact:
  221. reconcile_failed: "{{ groups.oo_masters_to_config | difference(reconcile_completed) | list }}"
  222. - fail:
  223. msg: "Upgrade cannot continue. The following masters did not finish reconciling: {{ reconcile_failed | join(',') }}"
  224. when: reconcile_failed | length > 0
  225. - name: Upgrade Docker on dedicated containerized etcd hosts
  226. hosts: oo_etcd_to_config:!oo_nodes_to_upgrade
  227. serial: 1
  228. any_errors_fatal: true
  229. roles:
  230. - openshift_facts
  231. tasks:
  232. - include_tasks: docker/tasks/upgrade.yml
  233. when: l_docker_upgrade is defined and l_docker_upgrade | bool and not openshift_is_atomic | bool
  234. - name: Drain and upgrade master nodes
  235. hosts: oo_masters_to_config:&oo_nodes_to_upgrade
  236. # This var must be set with -e on invocation, as it is not a per-host inventory var
  237. # and is evaluated early. Values such as "20%" can also be used.
  238. serial: "{{ openshift_upgrade_control_plane_nodes_serial | default(1) }}"
  239. max_fail_percentage: "{{ openshift_upgrade_control_plane_nodes_max_fail_percentage | default(0) }}"
  240. pre_tasks:
  241. - name: Load lib_openshift modules
  242. import_role:
  243. name: lib_openshift
  244. # TODO: To better handle re-trying failed upgrades, it would be nice to check if the node
  245. # or docker actually needs an upgrade before proceeding. Perhaps best to save this until
  246. # we merge upgrade functionality into the base roles and a normal config.yml playbook run.
  247. - name: Mark node unschedulable
  248. oc_adm_manage_node:
  249. node: "{{ openshift.node.nodename | lower }}"
  250. schedulable: False
  251. delegate_to: "{{ groups.oo_first_master.0 }}"
  252. retries: 10
  253. delay: 5
  254. register: node_unschedulable
  255. until: node_unschedulable is succeeded
  256. - name: Drain Node for Kubelet upgrade
  257. command: >
  258. {{ 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
  259. delegate_to: "{{ groups.oo_first_master.0 }}"
  260. register: l_upgrade_control_plane_drain_result
  261. until: not (l_upgrade_control_plane_drain_result is failed)
  262. retries: 60
  263. delay: 60
  264. roles:
  265. - openshift_facts
  266. post_tasks:
  267. - import_role:
  268. name: openshift_node
  269. tasks_from: upgrade.yml
  270. - name: Set node schedulability
  271. oc_adm_manage_node:
  272. node: "{{ openshift.node.nodename | lower }}"
  273. schedulable: True
  274. delegate_to: "{{ groups.oo_first_master.0 }}"
  275. retries: 10
  276. delay: 5
  277. register: node_schedulable
  278. until: node_schedulable is succeeded
  279. when: node_unschedulable is changed