upgrade_control_plane.yml 14 KB

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