migrate.yml 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. ---
  2. - block:
  3. - name: scale down asb deploymentconfig
  4. oc_scale:
  5. name: asb
  6. namespace: openshift-ansible-service-broker
  7. kind: dc
  8. replicas: 0
  9. - name: Add required permissions to asb-auth clusterrole
  10. oc_clusterrole:
  11. state: present
  12. name: asb-auth
  13. rules:
  14. - apiGroups: [""]
  15. resources: ["namespaces"]
  16. verbs: ["create", "delete"]
  17. - apiGroups: ["authorization.openshift.io"]
  18. resources: ["subjectrulesreview"]
  19. verbs: ["create"]
  20. - apiGroups: ["authorization.k8s.io"]
  21. resources: ["subjectaccessreviews"]
  22. verbs: ["create"]
  23. - apiGroups: ["authentication.k8s.io"]
  24. resources: ["tokenreviews"]
  25. verbs: ["create"]
  26. - apiGroups: ["image.openshift.io", ""]
  27. resources: ["images"]
  28. verbs: ["get", "list"]
  29. - apiGroups: ["network.openshift.io"]
  30. resources: ["clusternetworks", "netnamespaces"]
  31. verbs: ["get"]
  32. - apiGroups: ["network.openshift.io"]
  33. resources: ["netnamespaces"]
  34. verbs: ["update"]
  35. - apiGroups: ["networking.k8s.io"]
  36. resources: ["networkpolicies"]
  37. verbs: ["create", "delete"]
  38. - apiGroups: ["automationbroker.io"]
  39. resources: ["bundles", "bundlebindings", "bundleinstances"]
  40. verbs: ["*"]
  41. - name: Create custom resource definitions for asb
  42. oc_obj:
  43. name: '{{ asb_crd.metadata.name }}'
  44. kind: CustomResourceDefinition
  45. state: present
  46. content:
  47. path: /tmp/{{ asb_crd.metadata.name }}
  48. data: '{{ asb_crd }}'
  49. vars:
  50. asb_crd: "{{ lookup('file', item) | from_yaml }}"
  51. with_fileglob:
  52. - 'files/*.automationbroker.io.yaml'
  53. - name: Migrate from etcd to CustomResources
  54. oc_obj:
  55. force: yes
  56. name: asb-etcd-migration
  57. namespace: openshift-ansible-service-broker
  58. kind: Job
  59. state: present
  60. content:
  61. path: /tmp/asb_migrate_out
  62. data:
  63. apiVersion: batch/v1
  64. kind: Job
  65. metadata:
  66. name: asb-etcd-migration
  67. spec:
  68. parallelism: 1
  69. completions: 1
  70. backoffLimit: 3
  71. activeDeadlineSeconds: "{{ asb_migration_timeout | default(600) | int }}"
  72. template:
  73. metadata:
  74. name: asb-etcd-migration
  75. spec:
  76. containers:
  77. - name: asb
  78. image: '{{ ansible_service_broker_image }}'
  79. imagePullPolicy: IfNotPresent
  80. command:
  81. - '/usr/bin/migration'
  82. args:
  83. - '-host=asb-etcd.openshift-ansible-service-broker.svc'
  84. - '-ca-file=/var/run/secrets/kubernetes.io/serviceaccount/service-ca.crt'
  85. - '-client-cert=/var/run/asb-etcd-auth/client.crt'
  86. - '-client-key=/var/run/asb-etcd-auth/client.key'
  87. - '-namespace=openshift-ansible-service-broker'
  88. volumeMounts:
  89. - name: config-volume
  90. mountPath: /etc/ansible-service-broker
  91. - name: asb-tls
  92. mountPath: /etc/tls/private
  93. - name: asb-etcd-auth
  94. mountPath: /var/run/asb-etcd-auth
  95. env:
  96. - name: BROKER_CONFIG
  97. value: /etc/ansible-service-broker/config.yaml
  98. - name: HTTP_PROXY
  99. value: "{{ openshift.common.http_proxy | default('') }}"
  100. - name: HTTPS_PROXY
  101. value: "{{ openshift.common.https_proxy | default('') }}"
  102. - name: NO_PROXY
  103. value: "{{ ([openshift.common.no_proxy, '.default'] | join(',')) if openshift.get('common', {}).get('no_proxy') else '' }}"
  104. volumes:
  105. - name: config-volume
  106. configMap:
  107. name: broker-config
  108. items:
  109. - key: broker-config
  110. path: config.yaml
  111. - name: asb-tls
  112. secret:
  113. secretName: asb-tls
  114. - name: asb-etcd-auth
  115. secret:
  116. secretName: broker-etcd-auth-secret
  117. restartPolicy: Never
  118. serviceAccount: asb
  119. serviceAccountName: asb
  120. - name: wait for migration to complete
  121. oc_obj:
  122. namespace: openshift-ansible-service-broker
  123. kind: Job
  124. state: list
  125. name: asb-etcd-migration
  126. register: migration_status
  127. ignore_errors: true
  128. until:
  129. - "'results' in migration_status.results and migration_status.results.results | count > 0"
  130. # Pod's 'Complete' status must be True
  131. - "migration_status.results.results | lib_utils_oo_collect(attribute='status.conditions') | lib_utils_oo_collect(attribute='status', filters={'type': 'Complete'}) | map('bool') | select | list | count == 1"
  132. delay: 10
  133. retries: "{{ (asb_migration_timeout|default(600) | int / 10) | int }}"
  134. failed_when:
  135. - "'results' in migration_status.results"
  136. - "migration_status.results.results | count > 0"
  137. # Fail when pod's 'Failed' status is True
  138. - "migration_status.results.results | lib_utils_oo_collect(attribute='status.conditions') | lib_utils_oo_collect(attribute='status', filters={'type': 'Failed'}) | map('bool') | select | list | count == 1"
  139. - when: not (migration_status is failed)
  140. block:
  141. - name: Update broker configmap to use CRD backend
  142. oc_obj:
  143. name: broker-config
  144. namespace: openshift-ansible-service-broker
  145. state: present
  146. kind: ConfigMap
  147. content:
  148. path: /tmp/cmout
  149. data: "{{ lookup('template', 'configmap.yaml.j2') | from_yaml }}"
  150. register: updated_configmap
  151. - name: Update broker deploymentconfig
  152. oc_obj:
  153. force: yes
  154. name: asb
  155. namespace: openshift-ansible-service-broker
  156. state: present
  157. kind: DeploymentConfig
  158. content:
  159. path: /tmp/dcout
  160. data: "{{ lookup('template', 'asb_dc.yaml.j2') | from_yaml }}"
  161. - name: delete etcd service
  162. oc_service:
  163. name: asb-etcd
  164. namespace: openshift-ansible-service-broker
  165. state: absent
  166. - name: delete etcd deploymentconfig
  167. oc_obj:
  168. name: asb-etcd
  169. namespace: openshift-ansible-service-broker
  170. kind: DeploymentConfig
  171. state: absent
  172. - name: delete broker etcd secret
  173. oc_secret:
  174. name: broker-etcd-auth-secret
  175. namespace: openshift_ansible_service_broker
  176. state: absent
  177. always:
  178. - name: scale up asb deploymentconfig
  179. oc_scale:
  180. name: asb
  181. namespace: openshift-ansible-service-broker
  182. kind: dc
  183. replicas: 1
  184. - name: Fail out because the ASB etcd to CRD migration was unsuccessful
  185. fail:
  186. msg: >
  187. The migration from etcd to CustomResourceDefinitions was not
  188. successful, aborting upgrade of the ansible service broker.
  189. when: migration_status is not defined or migration_status is failed or updated_configmap is not defined or updated_configmap is failed