upgrade_control_plane.yml 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. ---
  2. ###############################################################################
  3. # Upgrade Masters
  4. ###############################################################################
  5. # If facts cache were for some reason deleted, this fact may not be set, and if not set
  6. # it will always default to true. This causes problems for the etcd data dir fact detection
  7. # so we must first make sure this is set correctly before attempting the backup.
  8. - name: Set master embedded_etcd fact
  9. hosts: oo_masters_to_config
  10. roles:
  11. - openshift_facts
  12. tasks:
  13. - openshift_facts:
  14. role: master
  15. local_facts:
  16. embedded_etcd: "{{ groups.oo_etcd_to_config | default([]) | length == 0 }}"
  17. - name: Upgrade and backup etcd
  18. include: ./etcd/main.yml
  19. # Create service signer cert when missing. Service signer certificate
  20. # is added to master config in the master_config_upgrade hook.
  21. - name: Determine if service signer cert must be created
  22. hosts: oo_first_master
  23. tasks:
  24. - name: Determine if service signer certificate must be created
  25. stat:
  26. path: "{{ openshift.common.config_base }}/master/service-signer.crt"
  27. register: service_signer_cert_stat
  28. changed_when: false
  29. - include: create_service_signer_cert.yml
  30. # oc adm migrate storage should be run prior to etcd v3 upgrade
  31. # See: https://github.com/openshift/origin/pull/14625#issuecomment-308467060
  32. - name: Pre master upgrade - Upgrade all storage
  33. hosts: oo_first_master
  34. tasks:
  35. - name: Upgrade all storage
  36. command: >
  37. {{ openshift.common.client_binary }} adm --config={{ openshift.common.config_base }}/master/admin.kubeconfig
  38. migrate storage --include=* --confirm
  39. register: l_pb_upgrade_control_plane_pre_upgrade_storage
  40. when: openshift_upgrade_pre_storage_migration_enabled | default(true) | bool
  41. failed_when:
  42. - openshift_upgrade_pre_storage_migration_enabled | default(true) | bool
  43. - l_pb_upgrade_control_plane_pre_upgrade_storage.rc != 0
  44. - openshift_upgrade_pre_storage_migration_fatal | default(true) | bool
  45. # Set openshift_master_facts separately. In order to reconcile
  46. # admission_config's, we currently must run openshift_master_facts and
  47. # then run openshift_facts.
  48. - name: Set OpenShift master facts
  49. hosts: oo_masters_to_config
  50. roles:
  51. - openshift_master_facts
  52. # The main master upgrade play. Should handle all changes to the system in one pass, with
  53. # support for optional hooks to be defined.
  54. - name: Upgrade master
  55. hosts: oo_masters_to_config
  56. vars:
  57. openshift_master_ha: "{{ groups.oo_masters_to_config | length > 1 }}"
  58. serial: 1
  59. tasks:
  60. - include_role:
  61. name: openshift_facts
  62. # Run the pre-upgrade hook if defined:
  63. - debug: msg="Running master pre-upgrade hook {{ openshift_master_upgrade_pre_hook }}"
  64. when: openshift_master_upgrade_pre_hook is defined
  65. - include: "{{ openshift_master_upgrade_pre_hook }}"
  66. when: openshift_master_upgrade_pre_hook is defined
  67. - include_role:
  68. name: openshift_master
  69. tasks_from: upgrade.yml
  70. # Run the upgrade hook prior to restarting services/system if defined:
  71. - debug: msg="Running master upgrade hook {{ openshift_master_upgrade_hook }}"
  72. when: openshift_master_upgrade_hook is defined
  73. - include: "{{ openshift_master_upgrade_hook }}"
  74. when: openshift_master_upgrade_hook is defined
  75. - include: ../../../openshift-master/private/tasks/restart_hosts.yml
  76. when: openshift.common.rolling_restart_mode == 'system'
  77. - include: ../../../openshift-master/private/tasks/restart_services.yml
  78. when: openshift.common.rolling_restart_mode == 'services'
  79. # Run the post-upgrade hook if defined:
  80. - debug: msg="Running master post-upgrade hook {{ openshift_master_upgrade_post_hook }}"
  81. when: openshift_master_upgrade_post_hook is defined
  82. - include: "{{ openshift_master_upgrade_post_hook }}"
  83. when: openshift_master_upgrade_post_hook is defined
  84. - name: Post master upgrade - Upgrade clusterpolicies storage
  85. command: >
  86. {{ openshift.common.client_binary }} adm --config={{ openshift.common.config_base }}/master/admin.kubeconfig
  87. migrate storage --include=clusterpolicies --confirm
  88. register: l_pb_upgrade_control_plane_post_upgrade_storage
  89. when:
  90. - openshift_upgrade_post_storage_migration_enabled | default(true) | bool
  91. - openshift_version | version_compare('3.7','<')
  92. failed_when:
  93. - openshift_upgrade_post_storage_migration_enabled | default(true) | bool
  94. - l_pb_upgrade_control_plane_post_upgrade_storage.rc != 0
  95. - openshift_upgrade_post_storage_migration_fatal | default(false) | bool
  96. run_once: true
  97. delegate_to: "{{ groups.oo_first_master.0 }}"
  98. - set_fact:
  99. master_update_complete: True
  100. ##############################################################################
  101. # Gate on master update complete
  102. ##############################################################################
  103. - name: Gate on master update
  104. hosts: localhost
  105. connection: local
  106. become: no
  107. tasks:
  108. - set_fact:
  109. master_update_completed: "{{ hostvars
  110. | oo_select_keys(groups.oo_masters_to_config)
  111. | oo_collect('inventory_hostname', {'master_update_complete': true}) }}"
  112. - set_fact:
  113. master_update_failed: "{{ groups.oo_masters_to_config | difference(master_update_completed) | list }}"
  114. - fail:
  115. msg: "Upgrade cannot continue. The following masters did not finish updating: {{ master_update_failed | join(',') }}"
  116. when: master_update_failed | length > 0
  117. ###############################################################################
  118. # Reconcile Cluster Roles, Cluster Role Bindings and Security Context Constraints
  119. ###############################################################################
  120. - name: Reconcile Cluster Roles and Cluster Role Bindings and Security Context Constraints
  121. hosts: oo_masters_to_config
  122. roles:
  123. - { role: openshift_cli }
  124. vars:
  125. __master_shared_resource_viewer_file: "shared_resource_viewer_role.yaml"
  126. tasks:
  127. - name: Reconcile Cluster Roles
  128. command: >
  129. {{ openshift.common.client_binary }} adm --config={{ openshift.common.config_base }}/master/admin.kubeconfig
  130. policy reconcile-cluster-roles --additive-only=true --confirm -o name
  131. register: reconcile_cluster_role_result
  132. when: openshift_version | version_compare('3.7','<')
  133. changed_when:
  134. - reconcile_cluster_role_result.stdout != ''
  135. - reconcile_cluster_role_result.rc == 0
  136. run_once: true
  137. - name: Reconcile Cluster Role Bindings
  138. command: >
  139. {{ openshift.common.client_binary }} adm --config={{ openshift.common.config_base }}/master/admin.kubeconfig
  140. policy reconcile-cluster-role-bindings
  141. --exclude-groups=system:authenticated
  142. --exclude-groups=system:authenticated:oauth
  143. --exclude-groups=system:unauthenticated
  144. --exclude-users=system:anonymous
  145. --additive-only=true --confirm -o name
  146. when: openshift_version | version_compare('3.7','<')
  147. register: reconcile_bindings_result
  148. changed_when:
  149. - reconcile_bindings_result.stdout != ''
  150. - reconcile_bindings_result.rc == 0
  151. run_once: true
  152. - name: Reconcile Jenkins Pipeline Role Bindings
  153. command: >
  154. {{ openshift.common.client_binary }} adm --config={{ openshift.common.config_base }}/master/admin.kubeconfig policy reconcile-cluster-role-bindings system:build-strategy-jenkinspipeline --confirm -o name
  155. run_once: true
  156. register: reconcile_jenkins_role_binding_result
  157. changed_when:
  158. - reconcile_jenkins_role_binding_result.stdout != ''
  159. - reconcile_jenkins_role_binding_result.rc == 0
  160. when:
  161. - openshift_version | version_compare('3.7','<')
  162. - when: openshift_upgrade_target | version_compare('3.7','<')
  163. block:
  164. - name: Retrieve shared-resource-viewer
  165. oc_obj:
  166. state: list
  167. kind: role
  168. name: "shared-resource-viewer"
  169. namespace: "openshift"
  170. register: objout
  171. - name: Determine if shared-resource-viewer is protected
  172. set_fact:
  173. __shared_resource_viewer_protected: true
  174. when:
  175. - "'results' in objout"
  176. - "'results' in objout['results']"
  177. - "'annotations' in objout['results']['results'][0]['metadata']"
  178. - "'openshift.io/reconcile-protect' in objout['results']['results'][0]['metadata']['annotations']"
  179. - "objout['results']['results'][0]['metadata']['annotations']['openshift.io/reconcile-protect'] == 'true'"
  180. - copy:
  181. src: "{{ item }}"
  182. dest: "/tmp/{{ item }}"
  183. with_items:
  184. - "{{ __master_shared_resource_viewer_file }}"
  185. when: __shared_resource_viewer_protected is not defined
  186. - name: Fixup shared-resource-viewer role
  187. oc_obj:
  188. state: present
  189. kind: role
  190. name: "shared-resource-viewer"
  191. namespace: "openshift"
  192. files:
  193. - "/tmp/{{ __master_shared_resource_viewer_file }}"
  194. delete_after: true
  195. when: __shared_resource_viewer_protected is not defined
  196. register: result
  197. retries: 3
  198. delay: 5
  199. until: result.rc == 0
  200. ignore_errors: true
  201. - name: Reconcile Security Context Constraints
  202. command: >
  203. {{ openshift.common.client_binary }} adm policy --config={{ openshift.common.config_base }}/master/admin.kubeconfig reconcile-sccs --confirm --additive-only=true -o name
  204. register: reconcile_scc_result
  205. changed_when:
  206. - reconcile_scc_result.stdout != ''
  207. - reconcile_scc_result.rc == 0
  208. run_once: true
  209. - name: Migrate storage post policy reconciliation
  210. command: >
  211. {{ openshift.common.client_binary }} adm --config={{ openshift.common.config_base }}/master/admin.kubeconfig
  212. migrate storage --include=* --confirm
  213. run_once: true
  214. register: l_pb_upgrade_control_plane_post_upgrade_storage
  215. when: openshift_upgrade_post_storage_migration_enabled | default(true) | bool
  216. failed_when:
  217. - openshift_upgrade_post_storage_migration_enabled | default(true) | bool
  218. - l_pb_upgrade_control_plane_post_upgrade_storage.rc != 0
  219. - openshift_upgrade_post_storage_migration_fatal | default(false) | bool
  220. - set_fact:
  221. reconcile_complete: True
  222. ##############################################################################
  223. # Gate on reconcile
  224. ##############################################################################
  225. - name: Gate on reconcile
  226. hosts: localhost
  227. connection: local
  228. become: no
  229. tasks:
  230. - set_fact:
  231. reconcile_completed: "{{ hostvars
  232. | oo_select_keys(groups.oo_masters_to_config)
  233. | oo_collect('inventory_hostname', {'reconcile_complete': true}) }}"
  234. - set_fact:
  235. reconcile_failed: "{{ groups.oo_masters_to_config | difference(reconcile_completed) | list }}"
  236. - fail:
  237. msg: "Upgrade cannot continue. The following masters did not finish reconciling: {{ reconcile_failed | join(',') }}"
  238. when: reconcile_failed | length > 0
  239. - name: Upgrade Docker on dedicated containerized etcd hosts
  240. hosts: oo_etcd_to_config:!oo_nodes_to_upgrade
  241. serial: 1
  242. any_errors_fatal: true
  243. roles:
  244. - openshift_facts
  245. tasks:
  246. - include: docker/tasks/upgrade.yml
  247. when: l_docker_upgrade is defined and l_docker_upgrade | bool and not openshift.common.is_atomic | bool
  248. - name: Drain and upgrade master nodes
  249. hosts: 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|succeeded
  270. - name: Drain Node for Kubelet upgrade
  271. command: >
  272. {{ hostvars[groups.oo_first_master.0].openshift.common.admin_binary }} drain {{ openshift.node.nodename | lower }} --config={{ openshift.common.config_base }}/master/admin.kubeconfig --force --delete-local-data --ignore-daemonsets
  273. delegate_to: "{{ groups.oo_first_master.0 }}"
  274. register: l_upgrade_control_plane_drain_result
  275. until: not l_upgrade_control_plane_drain_result | failed
  276. retries: 60
  277. delay: 60
  278. roles:
  279. - openshift_facts
  280. post_tasks:
  281. - include_role:
  282. name: openshift_node
  283. tasks_from: upgrade.yml
  284. vars:
  285. openshift_node_upgrade_in_progress: True
  286. - name: Set node schedulability
  287. oc_adm_manage_node:
  288. node: "{{ openshift.node.nodename | lower }}"
  289. schedulable: True
  290. delegate_to: "{{ groups.oo_first_master.0 }}"
  291. retries: 10
  292. delay: 5
  293. register: node_schedulable
  294. until: node_schedulable|succeeded
  295. when: node_unschedulable|changed