registry.yml 6.6 KB

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