additional_settings.j2.sh 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/bin/bash
  2. set -euxo pipefail
  3. dns_zone="{{ dns_managed_zone | default(openshift_gcp_prefix + 'managed-zone') }}"
  4. # configure DNS
  5. (
  6. # Retry DNS changes until they succeed since this may be a shared resource
  7. while true; do
  8. dns="${TMPDIR:-/tmp}/dns.yaml"
  9. rm -f $dns
  10. # DNS records for etcd discovery
  11. ETCD_DNS_NAME="_etcd-server-ssl._tcp.{{ lookup('env', 'INSTANCE_PREFIX') | mandatory }}.{{ public_hosted_zone }}."
  12. if ! gcloud --project "{{ openshift_gcp_project }}" dns record-sets list -z "${dns_zone}" --name "${ETCD_DNS_NAME}" 2>/dev/null | grep -q "${ETCD_DNS_NAME}"; then
  13. if [[ ! -f $dns ]]; then
  14. gcloud --project "{{ openshift_gcp_project }}" dns record-sets transaction --transaction-file=$dns start -z "${dns_zone}"
  15. fi
  16. gcloud --project "{{ openshift_gcp_project }}" dns record-sets transaction --transaction-file=$dns add -z "${dns_zone}" --ttl {{ openshift_gcp_master_dns_ttl }} --name "${ETCD_DNS_NAME}" --type SRV {% for etcd in etcd_discovery_targets %}'{{ etcd }}' {% endfor %}
  17. else
  18. echo "DNS record for '${ETCD_DNS_NAME}' already exists"
  19. fi
  20. # Commit all DNS changes, retrying if preconditions are not met
  21. if [[ -f $dns ]]; then
  22. if ! out="$( gcloud --project "{{ openshift_gcp_project }}" dns record-sets transaction --transaction-file=$dns execute -z "${dns_zone}" 2>&1 )"; then
  23. rc=$?
  24. if [[ "${out}" == *"HTTPError 412: Precondition not met"* ]]; then
  25. continue
  26. fi
  27. exit $rc
  28. fi
  29. fi
  30. break
  31. done
  32. ) &
  33. for i in `jobs -p`; do wait $i; done