object_storage.yml 4.5 KB

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