upgrade_control_plane.yml 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  1. ---
  2. ###############################################################################
  3. # Upgrade Masters
  4. ###############################################################################
  5. # oc adm migrate storage should be run prior to etcd v3 upgrade
  6. # See: https://github.com/openshift/origin/pull/14625#issuecomment-308467060
  7. - name: Pre master upgrade - Upgrade all storage
  8. hosts: oo_first_master
  9. tasks:
  10. - name: Upgrade all storage
  11. command: >
  12. {{ openshift.common.client_binary }} adm --config={{ openshift.common.config_base }}/master/admin.kubeconfig
  13. migrate storage --include=* --confirm
  14. register: l_pb_upgrade_control_plane_pre_upgrade_storage
  15. when: openshift_upgrade_pre_storage_migration_enabled | default(true) | bool
  16. failed_when:
  17. - openshift_upgrade_pre_storage_migration_enabled | default(true) | bool
  18. - l_pb_upgrade_control_plane_pre_upgrade_storage.rc != 0
  19. - openshift_upgrade_pre_storage_migration_fatal | default(true) | bool
  20. # If facts cache were for some reason deleted, this fact may not be set, and if not set
  21. # it will always default to true. This causes problems for the etcd data dir fact detection
  22. # so we must first make sure this is set correctly before attempting the backup.
  23. - name: Set master embedded_etcd fact
  24. hosts: oo_masters_to_config
  25. roles:
  26. - openshift_facts
  27. tasks:
  28. - openshift_facts:
  29. role: master
  30. local_facts:
  31. embedded_etcd: "{{ groups.oo_etcd_to_config | default([]) | length == 0 }}"
  32. - name: Upgrade and backup etcd
  33. include: ./etcd/main.yml
  34. # Create service signer cert when missing. Service signer certificate
  35. # is added to master config in the master_config_upgrade hook.
  36. - name: Determine if service signer cert must be created
  37. hosts: oo_first_master
  38. tasks:
  39. - name: Determine if service signer certificate must be created
  40. stat:
  41. path: "{{ openshift.common.config_base }}/master/service-signer.crt"
  42. register: service_signer_cert_stat
  43. changed_when: false
  44. - include: create_service_signer_cert.yml
  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. handlers:
  60. - include: ../../../../roles/openshift_master/handlers/main.yml
  61. static: yes
  62. roles:
  63. - openshift_facts
  64. - lib_utils
  65. post_tasks:
  66. # Run the pre-upgrade hook if defined:
  67. - debug: msg="Running master pre-upgrade hook {{ openshift_master_upgrade_pre_hook }}"
  68. when: openshift_master_upgrade_pre_hook is defined
  69. - include: "{{ openshift_master_upgrade_pre_hook }}"
  70. when: openshift_master_upgrade_pre_hook is defined
  71. - include: rpm_upgrade.yml component=master
  72. when: not openshift.common.is_containerized | bool
  73. - include_vars: ../../../../roles/openshift_master_facts/vars/main.yml
  74. - include: upgrade_scheduler.yml
  75. - include: "{{ master_config_hook }}"
  76. when: master_config_hook is defined
  77. - include_vars: ../../../../roles/openshift_master/vars/main.yml
  78. - name: Update journald config
  79. include: ../../../../roles/openshift_master/tasks/journald.yml
  80. - name: Remove any legacy systemd units and update systemd units
  81. include: ../../../../roles/openshift_master/tasks/systemd_units.yml
  82. - name: Check for ca-bundle.crt
  83. stat:
  84. path: "{{ openshift.common.config_base }}/master/ca-bundle.crt"
  85. register: ca_bundle_stat
  86. failed_when: false
  87. - name: Check for ca.crt
  88. stat:
  89. path: "{{ openshift.common.config_base }}/master/ca.crt"
  90. register: ca_crt_stat
  91. failed_when: false
  92. - name: Migrate ca.crt to ca-bundle.crt
  93. command: mv ca.crt ca-bundle.crt
  94. args:
  95. chdir: "{{ openshift.common.config_base }}/master"
  96. when: ca_crt_stat.stat.isreg and not ca_bundle_stat.stat.exists
  97. - name: Link ca.crt to ca-bundle.crt
  98. file:
  99. src: "{{ openshift.common.config_base }}/master/ca-bundle.crt"
  100. path: "{{ openshift.common.config_base }}/master/ca.crt"
  101. state: link
  102. when: ca_crt_stat.stat.isreg and not ca_bundle_stat.stat.exists
  103. - name: Update oreg value
  104. yedit:
  105. src: "{{ openshift.common.config_base }}/master/master-config.yaml"
  106. key: 'imageConfig.format'
  107. value: "{{ oreg_url | default(oreg_url_master) }}"
  108. when: oreg_url is defined or oreg_url_master is defined
  109. # Run the upgrade hook prior to restarting services/system if defined:
  110. - debug: msg="Running master upgrade hook {{ openshift_master_upgrade_hook }}"
  111. when: openshift_master_upgrade_hook is defined
  112. - include: "{{ openshift_master_upgrade_hook }}"
  113. when: openshift_master_upgrade_hook is defined
  114. - include: ../../openshift-master/restart_hosts.yml
  115. when: openshift.common.rolling_restart_mode == 'system'
  116. - include: ../../openshift-master/restart_services.yml
  117. when: openshift.common.rolling_restart_mode == 'services'
  118. # Run the post-upgrade hook if defined:
  119. - debug: msg="Running master post-upgrade hook {{ openshift_master_upgrade_post_hook }}"
  120. when: openshift_master_upgrade_post_hook is defined
  121. - include: "{{ openshift_master_upgrade_post_hook }}"
  122. when: openshift_master_upgrade_post_hook is defined
  123. - name: Post master upgrade - Upgrade clusterpolicies storage
  124. command: >
  125. {{ openshift.common.client_binary }} adm --config={{ openshift.common.config_base }}/master/admin.kubeconfig
  126. migrate storage --include=clusterpolicies --confirm
  127. register: l_pb_upgrade_control_plane_post_upgrade_storage
  128. when: openshift_upgrade_post_storage_migration_enabled | default(true) | bool
  129. failed_when:
  130. - openshift_upgrade_post_storage_migration_enabled | default(true) | bool
  131. - l_pb_upgrade_control_plane_post_upgrade_storage.rc != 0
  132. - openshift_upgrade_post_storage_migration_fatal | default(false) | bool
  133. run_once: true
  134. delegate_to: "{{ groups.oo_first_master.0 }}"
  135. - set_fact:
  136. master_update_complete: True
  137. ##############################################################################
  138. # Gate on master update complete
  139. ##############################################################################
  140. - name: Gate on master update
  141. hosts: localhost
  142. connection: local
  143. become: no
  144. tasks:
  145. - set_fact:
  146. master_update_completed: "{{ hostvars
  147. | oo_select_keys(groups.oo_masters_to_config)
  148. | oo_collect('inventory_hostname', {'master_update_complete': true}) }}"
  149. - set_fact:
  150. master_update_failed: "{{ groups.oo_masters_to_config | difference(master_update_completed) | list }}"
  151. - fail:
  152. msg: "Upgrade cannot continue. The following masters did not finish updating: {{ master_update_failed | join(',') }}"
  153. when: master_update_failed | length > 0
  154. ###############################################################################
  155. # Reconcile Cluster Roles, Cluster Role Bindings and Security Context Constraints
  156. ###############################################################################
  157. - name: Reconcile Cluster Roles and Cluster Role Bindings and Security Context Constraints
  158. hosts: oo_masters_to_config
  159. roles:
  160. - { role: openshift_cli }
  161. vars:
  162. openshift_docker_hosted_registry_network: "{{ hostvars[groups.oo_first_master.0].openshift.common.portal_net }}"
  163. # Another spot where we assume docker is running and do not want to accidentally trigger an unsafe
  164. # restart.
  165. skip_docker_role: True
  166. __master_shared_resource_viewer_file: "shared_resource_viewer_role.yaml"
  167. tasks:
  168. - name: Reconcile Cluster Roles
  169. command: >
  170. {{ openshift.common.client_binary }} adm --config={{ openshift.common.config_base }}/master/admin.kubeconfig
  171. policy reconcile-cluster-roles --additive-only=true --confirm -o name
  172. register: reconcile_cluster_role_result
  173. when: openshift_version | version_compare('3.7','<')
  174. changed_when:
  175. - reconcile_cluster_role_result.stdout != ''
  176. - reconcile_cluster_role_result.rc == 0
  177. run_once: true
  178. - name: Reconcile Cluster Role Bindings
  179. command: >
  180. {{ openshift.common.client_binary }} adm --config={{ openshift.common.config_base }}/master/admin.kubeconfig
  181. policy reconcile-cluster-role-bindings
  182. --exclude-groups=system:authenticated
  183. --exclude-groups=system:authenticated:oauth
  184. --exclude-groups=system:unauthenticated
  185. --exclude-users=system:anonymous
  186. --additive-only=true --confirm -o name
  187. when: openshift_version | version_compare('3.7','<')
  188. register: reconcile_bindings_result
  189. changed_when:
  190. - reconcile_bindings_result.stdout != ''
  191. - reconcile_bindings_result.rc == 0
  192. run_once: true
  193. - name: Reconcile Jenkins Pipeline Role Bindings
  194. command: >
  195. {{ 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
  196. run_once: true
  197. register: reconcile_jenkins_role_binding_result
  198. changed_when:
  199. - reconcile_jenkins_role_binding_result.stdout != ''
  200. - reconcile_jenkins_role_binding_result.rc == 0
  201. when:
  202. - openshift_version | version_compare('3.7','<')
  203. - when: openshift_upgrade_target | version_compare('3.7','<')
  204. block:
  205. - name: Retrieve shared-resource-viewer
  206. oc_obj:
  207. state: list
  208. kind: role
  209. name: "shared-resource-viewer"
  210. namespace: "openshift"
  211. register: objout
  212. - name: Determine if shared-resource-viewer is protected
  213. set_fact:
  214. __shared_resource_viewer_protected: true
  215. when:
  216. - "'results' in objout"
  217. - "'results' in objout['results']"
  218. - "'annotations' in objout['results']['results'][0]['metadata']"
  219. - "'openshift.io/reconcile-protect' in objout['results']['results'][0]['metadata']['annotations']"
  220. - "objout['results']['results'][0]['metadata']['annotations']['openshift.io/reconcile-protect'] == 'true'"
  221. - copy:
  222. src: "{{ item }}"
  223. dest: "/tmp/{{ item }}"
  224. with_items:
  225. - "{{ __master_shared_resource_viewer_file }}"
  226. when: __shared_resource_viewer_protected is not defined
  227. - name: Fixup shared-resource-viewer role
  228. oc_obj:
  229. state: present
  230. kind: role
  231. name: "shared-resource-viewer"
  232. namespace: "openshift"
  233. files:
  234. - "/tmp/{{ __master_shared_resource_viewer_file }}"
  235. delete_after: true
  236. when: __shared_resource_viewer_protected is not defined
  237. register: result
  238. retries: 3
  239. delay: 5
  240. until: result.rc == 0
  241. ignore_errors: true
  242. - name: Reconcile Security Context Constraints
  243. command: >
  244. {{ openshift.common.client_binary }} adm policy --config={{ openshift.common.config_base }}/master/admin.kubeconfig reconcile-sccs --confirm --additive-only=true -o name
  245. register: reconcile_scc_result
  246. changed_when:
  247. - reconcile_scc_result.stdout != ''
  248. - reconcile_scc_result.rc == 0
  249. run_once: true
  250. - name: Migrate storage post policy reconciliation
  251. command: >
  252. {{ openshift.common.client_binary }} adm --config={{ openshift.common.config_base }}/master/admin.kubeconfig
  253. migrate storage --include=* --confirm
  254. run_once: true
  255. register: l_pb_upgrade_control_plane_post_upgrade_storage
  256. when: openshift_upgrade_post_storage_migration_enabled | default(true) | bool
  257. failed_when:
  258. - openshift_upgrade_post_storage_migration_enabled | default(true) | bool
  259. - l_pb_upgrade_control_plane_post_upgrade_storage.rc != 0
  260. - openshift_upgrade_post_storage_migration_fatal | default(false) | bool
  261. - set_fact:
  262. reconcile_complete: True
  263. ##############################################################################
  264. # Gate on reconcile
  265. ##############################################################################
  266. - name: Gate on reconcile
  267. hosts: localhost
  268. connection: local
  269. become: no
  270. tasks:
  271. - set_fact:
  272. reconcile_completed: "{{ hostvars
  273. | oo_select_keys(groups.oo_masters_to_config)
  274. | oo_collect('inventory_hostname', {'reconcile_complete': true}) }}"
  275. - set_fact:
  276. reconcile_failed: "{{ groups.oo_masters_to_config | difference(reconcile_completed) | list }}"
  277. - fail:
  278. msg: "Upgrade cannot continue. The following masters did not finish reconciling: {{ reconcile_failed | join(',') }}"
  279. when: reconcile_failed | length > 0
  280. - name: Upgrade Docker on dedicated containerized etcd hosts
  281. hosts: oo_etcd_to_config:!oo_nodes_to_upgrade
  282. serial: 1
  283. any_errors_fatal: true
  284. roles:
  285. - openshift_facts
  286. tasks:
  287. - include: docker/tasks/upgrade.yml
  288. when: l_docker_upgrade is defined and l_docker_upgrade | bool and not openshift.common.is_atomic | bool
  289. - name: Drain and upgrade master nodes
  290. hosts: oo_masters_to_config:&oo_nodes_to_upgrade
  291. # This var must be set with -e on invocation, as it is not a per-host inventory var
  292. # and is evaluated early. Values such as "20%" can also be used.
  293. serial: "{{ openshift_upgrade_control_plane_nodes_serial | default(1) }}"
  294. max_fail_percentage: "{{ openshift_upgrade_control_plane_nodes_max_fail_percentage | default(0) }}"
  295. pre_tasks:
  296. - name: Load lib_openshift modules
  297. include_role:
  298. name: lib_openshift
  299. # TODO: To better handle re-trying failed upgrades, it would be nice to check if the node
  300. # or docker actually needs an upgrade before proceeding. Perhaps best to save this until
  301. # we merge upgrade functionality into the base roles and a normal config.yml playbook run.
  302. - name: Mark node unschedulable
  303. oc_adm_manage_node:
  304. node: "{{ openshift.node.nodename | lower }}"
  305. schedulable: False
  306. delegate_to: "{{ groups.oo_first_master.0 }}"
  307. retries: 10
  308. delay: 5
  309. register: node_unschedulable
  310. until: node_unschedulable|succeeded
  311. - name: Drain Node for Kubelet upgrade
  312. command: >
  313. {{ 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
  314. delegate_to: "{{ groups.oo_first_master.0 }}"
  315. register: l_upgrade_control_plane_drain_result
  316. until: not l_upgrade_control_plane_drain_result | failed
  317. retries: 60
  318. delay: 60
  319. roles:
  320. - lib_openshift
  321. - openshift_facts
  322. - docker
  323. - openshift_node_dnsmasq
  324. - openshift_node_upgrade
  325. post_tasks:
  326. - name: Set node schedulability
  327. oc_adm_manage_node:
  328. node: "{{ openshift.node.nodename | lower }}"
  329. schedulable: True
  330. delegate_to: "{{ groups.oo_first_master.0 }}"
  331. retries: 10
  332. delay: 5
  333. register: node_schedulable
  334. until: node_schedulable|succeeded
  335. when: node_unschedulable|changed