upgrade_control_plane.yml 13 KB

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