upgrade_control_plane.yml 13 KB

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