registry.yml 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. ---
  2. - name: setup firewall
  3. include: firewall.yml
  4. static: yes
  5. - when: openshift.hosted.registry.replicas | default(none) is none
  6. block:
  7. - name: Retrieve list of openshift nodes matching registry selector
  8. oc_obj:
  9. state: list
  10. kind: node
  11. selector: "{{ openshift.hosted.registry.selector | default(omit) }}"
  12. register: registry_nodes
  13. - name: set_fact l_node_count to number of nodes matching registry selector
  14. set_fact:
  15. l_node_count: "{{ registry_nodes.results.results[0]['items'] | length }}"
  16. # Determine the default number of registry/router replicas to use if no count
  17. # has been specified.
  18. # If no registry nodes defined, the default should be 0.
  19. - name: set_fact l_default_replicas when l_node_count == 0
  20. set_fact:
  21. l_default_replicas: 0
  22. when: l_node_count | int == 0
  23. # If registry nodes are defined and the registry storage kind is
  24. # defined, default should be the number of registry nodes, otherwise
  25. # just 1:
  26. - name: set_fact l_default_replicas when l_node_count > 0
  27. set_fact:
  28. l_default_replicas: "{{ l_node_count if openshift.hosted.registry.storage.kind | default(none) is not none else 1 }}"
  29. when: l_node_count | int > 0
  30. - name: set openshift_hosted facts
  31. set_fact:
  32. openshift_hosted_registry_replicas: "{{ openshift.hosted.registry.replicas | default(l_default_replicas) }}"
  33. openshift_hosted_registry_name: docker-registry
  34. openshift_hosted_registry_serviceaccount: registry
  35. openshift_hosted_registry_namespace: "{{ openshift.hosted.registry.namespace | default('default') }}"
  36. openshift_hosted_registry_selector: "{{ openshift.hosted.registry.selector }}"
  37. openshift_hosted_registry_images: "{{ openshift.hosted.registry.registryurl | default('openshift3/ose-${component}:${version}')}}"
  38. openshift_hosted_registry_volumes: []
  39. openshift_hosted_registry_env_vars: {}
  40. openshift_hosted_registry_routecertificates: "{{ ('routecertificates' in openshift.hosted.registry.keys()) | ternary(openshift.hosted.registry.routecertificates, {}) }}"
  41. openshift_hosted_registry_routehost: "{{ ('routehost' in openshift.hosted.registry.keys()) | ternary(openshift.hosted.registry.routehost, False) }}"
  42. openshift_hosted_registry_routetermination: "{{ ('routetermination' in openshift.hosted.registry.keys()) | ternary(openshift.hosted.registry.routetermination, 'passthrough') }}"
  43. openshift_hosted_registry_edits:
  44. # These edits are being specified only to prevent 'changed' on rerun
  45. - key: spec.strategy.rollingParams
  46. value:
  47. intervalSeconds: 1
  48. maxSurge: "25%"
  49. maxUnavailable: "25%"
  50. timeoutSeconds: 600
  51. updatePeriodSeconds: 1
  52. action: put
  53. openshift_hosted_registry_force:
  54. - False
  55. - name: Update registry environment variables when pushing via dns
  56. set_fact:
  57. openshift_hosted_registry_env_vars: "{{ openshift_hosted_registry_env_vars | combine({'OPENSHIFT_DEFAULT_REGISTRY':'docker-registry.default.svc:5000'}) }}"
  58. when: openshift_push_via_dns | default(false) | bool
  59. - name: Create the registry service account
  60. oc_serviceaccount:
  61. name: "{{ openshift_hosted_registry_serviceaccount }}"
  62. namespace: "{{ openshift_hosted_registry_namespace }}"
  63. - name: Grant the registry service account access to the appropriate scc
  64. oc_adm_policy_user:
  65. user: "system:serviceaccount:{{ openshift_hosted_registry_namespace }}:{{ openshift_hosted_registry_serviceaccount }}"
  66. namespace: "{{ openshift_hosted_registry_namespace }}"
  67. resource_kind: scc
  68. resource_name: hostnetwork
  69. - name: oc adm policy add-cluster-role-to-user system:registry system:serviceaccount:default:registry
  70. oc_adm_policy_user:
  71. user: "system:serviceaccount:{{ openshift_hosted_registry_namespace }}:{{ openshift_hosted_registry_serviceaccount }}"
  72. namespace: "{{ openshift_hosted_registry_namespace }}"
  73. resource_kind: cluster-role
  74. resource_name: system:registry
  75. - name: create the default registry service
  76. oc_service:
  77. namespace: "{{ openshift_hosted_registry_namespace }}"
  78. name: "{{ openshift_hosted_registry_name }}"
  79. ports:
  80. - name: 5000-tcp
  81. port: 5000
  82. protocol: TCP
  83. targetPort: 5000
  84. selector:
  85. docker-registry: default
  86. session_affinity: ClientIP
  87. service_type: ClusterIP
  88. - include: secure.yml
  89. static: no
  90. run_once: true
  91. when:
  92. - not (openshift.docker.hosted_registry_insecure | default(false) | bool)
  93. - include: storage/object_storage.yml
  94. static: no
  95. when:
  96. - openshift.hosted.registry.storage.kind | default(none) == 'object'
  97. - name: Update openshift_hosted facts for persistent volumes
  98. set_fact:
  99. openshift_hosted_registry_volumes: "{{ openshift_hosted_registry_volumes | union(pvc_volume_mounts) }}"
  100. vars:
  101. pvc_volume_mounts:
  102. - name: registry-storage
  103. type: persistentVolumeClaim
  104. claim_name: "{{ openshift.hosted.registry.storage.volume.name }}-claim"
  105. when:
  106. - openshift.hosted.registry.storage.kind | default(none) in ['nfs', 'openstack', 'glusterfs']
  107. - name: Create OpenShift registry
  108. oc_adm_registry:
  109. name: "{{ openshift_hosted_registry_name }}"
  110. namespace: "{{ openshift_hosted_registry_namespace }}"
  111. selector: "{{ openshift_hosted_registry_selector }}"
  112. replicas: "{{ openshift_hosted_registry_replicas }}"
  113. service_account: "{{ openshift_hosted_registry_serviceaccount }}"
  114. images: "{{ openshift_hosted_registry_images }}"
  115. env_vars: "{{ openshift_hosted_registry_env_vars }}"
  116. volume_mounts: "{{ openshift_hosted_registry_volumes }}"
  117. edits: "{{ openshift_hosted_registry_edits }}"
  118. force: "{{ True|bool in openshift_hosted_registry_force }}"
  119. - name: Ensure OpenShift registry correctly rolls out (best-effort today)
  120. command: |
  121. oc rollout status deploymentconfig {{ openshift_hosted_registry_name }} \
  122. --namespace {{ openshift_hosted_registry_namespace }} \
  123. --config {{ openshift.common.config_base }}/master/admin.kubeconfig
  124. async: 600
  125. poll: 15
  126. failed_when: false
  127. - name: Determine the latest version of the OpenShift registry deployment
  128. command: |
  129. {{ openshift.common.client_binary }} get deploymentconfig {{ openshift_hosted_registry_name }} \
  130. --namespace {{ openshift_hosted_registry_namespace }} \
  131. --config {{ openshift.common.config_base }}/master/admin.kubeconfig \
  132. -o jsonpath='{ .status.latestVersion }'
  133. register: openshift_hosted_registry_latest_version
  134. - name: Sanity-check that the OpenShift registry rolled out correctly
  135. command: |
  136. {{ openshift.common.client_binary }} get replicationcontroller {{ openshift_hosted_registry_name }}-{{ openshift_hosted_registry_latest_version.stdout }} \
  137. --namespace {{ openshift_hosted_registry_namespace }} \
  138. --config {{ openshift.common.config_base }}/master/admin.kubeconfig \
  139. -o jsonpath='{ .metadata.annotations.openshift\.io/deployment\.phase }'
  140. register: openshift_hosted_registry_rc_phase
  141. until: "'Running' not in openshift_hosted_registry_rc_phase.stdout"
  142. delay: 15
  143. retries: 40
  144. failed_when: "'Failed' in openshift_hosted_registry_rc_phase.stdout"
  145. - include: storage/glusterfs.yml
  146. when:
  147. - openshift.hosted.registry.storage.kind | default(none) == 'glusterfs' or openshift.hosted.registry.storage.glusterfs.swap