object_storage.yml 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. ---
  2. - fail:
  3. msg: >
  4. Object Storage Provider: {{ openshift.hosted.registry.storage.provider }}
  5. is not currently supported
  6. when: openshift.hosted.registry.storage.provider not in ['azure_blob', 's3', 'swift']
  7. - fail:
  8. msg: >
  9. Support for provider: "{{ openshift.hosted.registry.storage.provider }}"
  10. not implemented yet
  11. when: openshift.hosted.registry.storage.provider in ['azure_blob', 'swift']
  12. - include: s3.yml
  13. when: openshift.hosted.registry.storage.provider == 's3'
  14. - name: Test if docker registry config secret exists
  15. command: >
  16. {{ openshift.common.client_binary }}
  17. --config={{ openshift_hosted_kubeconfig }}
  18. --namespace={{ openshift.hosted.registry.namespace | default('default') }}
  19. get secrets {{ registry_config_secret_name }} -o json
  20. register: secrets
  21. changed_when: false
  22. failed_when: false
  23. - set_fact:
  24. registry_config: "{{ lookup('template', 'registry_config.j2') | b64encode }}"
  25. - set_fact:
  26. registry_config_secret: "{{ lookup('template', 'registry_config_secret.j2') | from_yaml }}"
  27. - set_fact:
  28. same_storage_provider: "{{ (secrets.stdout|from_json)['metadata']['annotations']['provider'] | default(none) == openshift.hosted.registry.storage.provider }}"
  29. when: secrets.rc == 0
  30. - name: Update registry config secret
  31. command: >
  32. {{ openshift.common.client_binary }}
  33. --config={{ openshift_hosted_kubeconfig }}
  34. --namespace={{ openshift.hosted.registry.namespace | default('default') }}
  35. patch secret/{{ registry_config_secret_name }}
  36. -p '{"data": {"config.yml": "{{ registry_config }}"}}'
  37. register: update_config_secret
  38. when: secrets.rc == 0 and (secrets.stdout|from_json)['data']['config.yml'] != registry_config and same_storage_provider | bool
  39. - name: Create registry config secret
  40. shell: >
  41. echo '{{ registry_config_secret |to_json }}' |
  42. {{ openshift.common.client_binary }}
  43. --config={{ openshift_hosted_kubeconfig }}
  44. --namespace={{ openshift.hosted.registry.namespace | default('default') }}
  45. create -f -
  46. when: secrets.rc == 1
  47. - name: Determine if service account contains secrets
  48. command: >
  49. {{ openshift.common.client_binary }}
  50. --config={{ openshift_hosted_kubeconfig }}
  51. --namespace={{ openshift.hosted.registry.namespace | default('default') }}
  52. get serviceaccounts registry
  53. -o jsonpath='{.secrets[?(@.name=="{{ registry_config_secret_name }}")].name}'
  54. register: serviceaccount
  55. changed_when: false
  56. - name: Add secrets to registry service account
  57. command: >
  58. {{ openshift.common.client_binary }}
  59. --config={{ openshift_hosted_kubeconfig }}
  60. --namespace={{ openshift.hosted.registry.namespace | default('default') }}
  61. secrets add serviceaccount/registry secrets/{{ registry_config_secret_name }}
  62. when: serviceaccount.stdout == ''
  63. - name: Determine if deployment config contains secrets
  64. command: >
  65. {{ openshift.common.client_binary }}
  66. --config={{ openshift_hosted_kubeconfig }}
  67. --namespace={{ openshift.hosted.registry.namespace | default('default') }}
  68. set volumes dc/docker-registry --list
  69. register: volume
  70. changed_when: false
  71. - name: Add secrets to registry deployment config
  72. command: >
  73. {{ openshift.common.client_binary }}
  74. --config={{ openshift_hosted_kubeconfig }}
  75. --namespace={{ openshift.hosted.registry.namespace | default('default') }}
  76. set volumes dc/docker-registry --add --name=docker-config -m /etc/registry
  77. --type=secret --secret-name={{ registry_config_secret_name }}
  78. when: registry_config_secret_name not in volume.stdout
  79. - name: Determine if registry environment variable needs to be created
  80. command: >
  81. {{ openshift.common.client_binary }}
  82. --config={{ openshift_hosted_kubeconfig }}
  83. --namespace={{ openshift.hosted.registry.namespace | default('default') }}
  84. set env --list dc/docker-registry
  85. register: oc_env
  86. changed_when: false
  87. - name: Add registry environment variable
  88. command: >
  89. {{ openshift.common.client_binary }}
  90. --config={{ openshift_hosted_kubeconfig }}
  91. --namespace={{ openshift.hosted.registry.namespace | default('default') }}
  92. set env dc/docker-registry REGISTRY_CONFIGURATION_PATH=/etc/registry/config.yml
  93. when: "'REGISTRY_CONFIGURATION_PATH' not in oc_env.stdout"
  94. - name: Redeploy registry
  95. command: >
  96. {{ openshift.common.client_binary }}
  97. --config={{ openshift_hosted_kubeconfig }}
  98. --namespace={{ openshift.hosted.registry.namespace | default('default') }}
  99. deploy dc/docker-registry --latest
  100. when: secrets.rc == 0 and not update_config_secret | skipped and update_config_secret.rc == 0 and same_storage_provider | bool