upgrade_control_plane.yml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  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 job storage
  8. hosts: oo_first_master
  9. tasks:
  10. - name: Upgrade job storage
  11. command: >
  12. {{ openshift.common.client_binary }} adm --config={{ openshift.common.config_base }}/master/admin.kubeconfig
  13. migrate storage --include=jobs --confirm
  14. # If facts cache were for some reason deleted, this fact may not be set, and if not set
  15. # it will always default to true. This causes problems for the etcd data dir fact detection
  16. # so we must first make sure this is set correctly before attempting the backup.
  17. - name: Set master embedded_etcd fact
  18. hosts: oo_masters_to_config
  19. roles:
  20. - openshift_facts
  21. tasks:
  22. - openshift_facts:
  23. role: master
  24. local_facts:
  25. embedded_etcd: "{{ groups.oo_etcd_to_config | default([]) | length == 0 }}"
  26. debug_level: "{{ openshift_master_debug_level | default(openshift.common.debug_level | default(2)) }}"
  27. - name: Upgrade and backup etcd
  28. include: ./etcd/main.yml
  29. # Create service signer cert when missing. Service signer certificate
  30. # is added to master config in the master_config_upgrade hook.
  31. - name: Determine if service signer cert must be created
  32. hosts: oo_first_master
  33. tasks:
  34. - name: Determine if service signer certificate must be created
  35. stat:
  36. path: "{{ openshift.common.config_base }}/master/service-signer.crt"
  37. register: service_signer_cert_stat
  38. changed_when: false
  39. - include: create_service_signer_cert.yml
  40. # Set openshift_master_facts separately. In order to reconcile
  41. # admission_config's, we currently must run openshift_master_facts and
  42. # then run openshift_facts.
  43. - name: Set OpenShift master facts
  44. hosts: oo_masters_to_config
  45. roles:
  46. - openshift_master_facts
  47. # The main master upgrade play. Should handle all changes to the system in one pass, with
  48. # support for optional hooks to be defined.
  49. - name: Upgrade master
  50. hosts: oo_masters_to_config
  51. vars:
  52. openshift_master_ha: "{{ groups.oo_masters_to_config | length > 1 }}"
  53. serial: 1
  54. handlers:
  55. - include: ../../../../roles/openshift_master/handlers/main.yml
  56. static: yes
  57. roles:
  58. - openshift_facts
  59. - lib_utils
  60. post_tasks:
  61. # Run the pre-upgrade hook if defined:
  62. - debug: msg="Running master pre-upgrade hook {{ openshift_master_upgrade_pre_hook }}"
  63. when: openshift_master_upgrade_pre_hook is defined
  64. - include: "{{ openshift_master_upgrade_pre_hook }}"
  65. when: openshift_master_upgrade_pre_hook is defined
  66. - include: rpm_upgrade.yml component=master
  67. when: not openshift.common.is_containerized | bool
  68. - include_vars: ../../../../roles/openshift_master_facts/vars/main.yml
  69. - include: upgrade_scheduler.yml
  70. - include: "{{ master_config_hook }}"
  71. when: master_config_hook is defined
  72. - include_vars: ../../../../roles/openshift_master/vars/main.yml
  73. - name: Update systemd units
  74. include: ../../../../roles/openshift_master/tasks/systemd_units.yml
  75. - name: Check for ca-bundle.crt
  76. stat:
  77. path: "{{ openshift.common.config_base }}/master/ca-bundle.crt"
  78. register: ca_bundle_stat
  79. failed_when: false
  80. - name: Check for ca.crt
  81. stat:
  82. path: "{{ openshift.common.config_base }}/master/ca.crt"
  83. register: ca_crt_stat
  84. failed_when: false
  85. - name: Migrate ca.crt to ca-bundle.crt
  86. command: mv ca.crt ca-bundle.crt
  87. args:
  88. chdir: "{{ openshift.common.config_base }}/master"
  89. when: ca_crt_stat.stat.isreg and not ca_bundle_stat.stat.exists
  90. - name: Link ca.crt to ca-bundle.crt
  91. file:
  92. src: "{{ openshift.common.config_base }}/master/ca-bundle.crt"
  93. path: "{{ openshift.common.config_base }}/master/ca.crt"
  94. state: link
  95. when: ca_crt_stat.stat.isreg and not ca_bundle_stat.stat.exists
  96. - name: Update oreg value
  97. yedit:
  98. src: "{{ openshift.common.config_base }}/master/master-config.yaml"
  99. key: 'imageConfig.format'
  100. value: "{{ oreg_url | default(oreg_url_master) }}"
  101. when: oreg_url is defined or oreg_url_master is defined
  102. # Run the upgrade hook prior to restarting services/system if defined:
  103. - debug: msg="Running master upgrade hook {{ openshift_master_upgrade_hook }}"
  104. when: openshift_master_upgrade_hook is defined
  105. - include: "{{ openshift_master_upgrade_hook }}"
  106. when: openshift_master_upgrade_hook is defined
  107. - include: ../../openshift-master/restart_hosts.yml
  108. when: openshift.common.rolling_restart_mode == 'system'
  109. - include: ../../openshift-master/restart_services.yml
  110. when: openshift.common.rolling_restart_mode == 'services'
  111. # Run the post-upgrade hook if defined:
  112. - debug: msg="Running master post-upgrade hook {{ openshift_master_upgrade_post_hook }}"
  113. when: openshift_master_upgrade_post_hook is defined
  114. - include: "{{ openshift_master_upgrade_post_hook }}"
  115. when: openshift_master_upgrade_post_hook is defined
  116. - set_fact:
  117. master_update_complete: True
  118. - name: Post master upgrade - Upgrade job storage
  119. hosts: oo_first_master
  120. tasks:
  121. - name: Upgrade job storage
  122. command: >
  123. {{ openshift.common.client_binary }} adm --config={{ openshift.common.config_base }}/master/admin.kubeconfig
  124. migrate storage --include=jobs --confirm
  125. ##############################################################################
  126. # Gate on master update complete
  127. ##############################################################################
  128. - name: Gate on master update
  129. hosts: localhost
  130. connection: local
  131. become: no
  132. tasks:
  133. - set_fact:
  134. master_update_completed: "{{ hostvars
  135. | oo_select_keys(groups.oo_masters_to_config)
  136. | oo_collect('inventory_hostname', {'master_update_complete': true}) }}"
  137. - set_fact:
  138. master_update_failed: "{{ groups.oo_masters_to_config | difference(master_update_completed) }}"
  139. - fail:
  140. msg: "Upgrade cannot continue. The following masters did not finish updating: {{ master_update_failed | join(',') }}"
  141. when: master_update_failed | length > 0
  142. ###############################################################################
  143. # Reconcile Cluster Roles, Cluster Role Bindings and Security Context Constraints
  144. ###############################################################################
  145. - name: Reconcile Cluster Roles and Cluster Role Bindings and Security Context Constraints
  146. hosts: oo_masters_to_config
  147. roles:
  148. - { role: openshift_cli }
  149. vars:
  150. origin_reconcile_bindings: "{{ deployment_type == 'origin' and openshift_version | version_compare('1.0.6', '>') }}"
  151. ent_reconcile_bindings: true
  152. openshift_docker_hosted_registry_network: "{{ hostvars[groups.oo_first_master.0].openshift.common.portal_net }}"
  153. # Another spot where we assume docker is running and do not want to accidentally trigger an unsafe
  154. # restart.
  155. skip_docker_role: True
  156. tasks:
  157. - name: Reconcile Cluster Roles
  158. command: >
  159. {{ openshift.common.client_binary }} adm --config={{ openshift.common.config_base }}/master/admin.kubeconfig
  160. policy reconcile-cluster-roles --additive-only=true --confirm -o name
  161. register: reconcile_cluster_role_result
  162. changed_when:
  163. - reconcile_cluster_role_result.stdout != ''
  164. - reconcile_cluster_role_result.rc == 0
  165. run_once: true
  166. - name: Reconcile Cluster Role Bindings
  167. command: >
  168. {{ openshift.common.client_binary }} adm --config={{ openshift.common.config_base }}/master/admin.kubeconfig
  169. policy reconcile-cluster-role-bindings
  170. --exclude-groups=system:authenticated
  171. --exclude-groups=system:authenticated:oauth
  172. --exclude-groups=system:unauthenticated
  173. --exclude-users=system:anonymous
  174. --additive-only=true --confirm -o name
  175. when: origin_reconcile_bindings | bool or ent_reconcile_bindings | bool
  176. register: reconcile_bindings_result
  177. changed_when:
  178. - reconcile_bindings_result.stdout != ''
  179. - reconcile_bindings_result.rc == 0
  180. run_once: true
  181. - name: Reconcile Jenkins Pipeline Role Bindings
  182. command: >
  183. {{ 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
  184. run_once: true
  185. register: reconcile_jenkins_role_binding_result
  186. changed_when:
  187. - reconcile_jenkins_role_binding_result.stdout != ''
  188. - reconcile_jenkins_role_binding_result.rc == 0
  189. when: openshift.common.version_gte_3_4_or_1_4 | bool
  190. - name: Reconcile Security Context Constraints
  191. command: >
  192. {{ openshift.common.client_binary }} adm policy reconcile-sccs --confirm --additive-only=true -o name
  193. register: reconcile_scc_result
  194. changed_when:
  195. - reconcile_scc_result.stdout != ''
  196. - reconcile_scc_result.rc == 0
  197. run_once: true
  198. - set_fact:
  199. reconcile_complete: True
  200. ##############################################################################
  201. # Gate on reconcile
  202. ##############################################################################
  203. - name: Gate on reconcile
  204. hosts: localhost
  205. connection: local
  206. become: no
  207. tasks:
  208. - set_fact:
  209. reconcile_completed: "{{ hostvars
  210. | oo_select_keys(groups.oo_masters_to_config)
  211. | oo_collect('inventory_hostname', {'reconcile_complete': true}) }}"
  212. - set_fact:
  213. reconcile_failed: "{{ groups.oo_masters_to_config | difference(reconcile_completed) }}"
  214. - fail:
  215. msg: "Upgrade cannot continue. The following masters did not finish reconciling: {{ reconcile_failed | join(',') }}"
  216. when: reconcile_failed | length > 0
  217. - name: Upgrade Docker on dedicated containerized etcd hosts
  218. hosts: oo_etcd_to_config:!oo_nodes_to_upgrade
  219. serial: 1
  220. any_errors_fatal: true
  221. roles:
  222. - openshift_facts
  223. tasks:
  224. - include: docker/upgrade.yml
  225. when: l_docker_upgrade is defined and l_docker_upgrade | bool and not openshift.common.is_atomic | bool
  226. - name: Drain and upgrade master nodes
  227. hosts: oo_masters_to_config:&oo_nodes_to_upgrade
  228. # This var must be set with -e on invocation, as it is not a per-host inventory var
  229. # and is evaluated early. Values such as "20%" can also be used.
  230. serial: "{{ openshift_upgrade_control_plane_nodes_serial | default(1) }}"
  231. max_fail_percentage: "{{ openshift_upgrade_control_plane_nodes_max_fail_percentage | default(0) }}"
  232. pre_tasks:
  233. - name: Load lib_openshift modules
  234. include_role:
  235. name: lib_openshift
  236. # TODO: To better handle re-trying failed upgrades, it would be nice to check if the node
  237. # or docker actually needs an upgrade before proceeding. Perhaps best to save this until
  238. # we merge upgrade functionality into the base roles and a normal config.yml playbook run.
  239. - name: Mark node unschedulable
  240. oc_adm_manage_node:
  241. node: "{{ openshift.node.nodename | lower }}"
  242. schedulable: False
  243. delegate_to: "{{ groups.oo_first_master.0 }}"
  244. retries: 10
  245. delay: 5
  246. register: node_unschedulable
  247. until: node_unschedulable|succeeded
  248. - name: Drain Node for Kubelet upgrade
  249. command: >
  250. {{ hostvars[groups.oo_first_master.0].openshift.common.admin_binary }} drain {{ openshift.node.nodename | lower }} --force --delete-local-data --ignore-daemonsets
  251. delegate_to: "{{ groups.oo_first_master.0 }}"
  252. roles:
  253. - lib_openshift
  254. - openshift_facts
  255. - docker
  256. - openshift_node_dnsmasq
  257. - openshift_node_upgrade
  258. post_tasks:
  259. - name: Set node schedulability
  260. oc_adm_manage_node:
  261. node: "{{ openshift.node.nodename | lower }}"
  262. schedulable: True
  263. delegate_to: "{{ groups.oo_first_master.0 }}"
  264. retries: 10
  265. delay: 5
  266. register: node_schedulable
  267. until: node_schedulable|succeeded
  268. when: node_unschedulable|changed