Skip to content

Commit caa39db

Browse files
committed
Use the Pod FQDN to generate the right SRV record
This simplifies the Kube configuration by relying on the information that already exists inside the Pod. The FQDN format is stable and well-documented.
1 parent 25e459a commit caa39db

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

mem3_helper.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22
# called "couchdb" and feeds those as `couchdb@HOSTNAME` nodes to mem3.
33

44
import json
5-
import os
65
import requests
76
import time
87
import dns.resolver
8+
import socket
99

1010
def discover_peers_dns(retries=5):
11-
# Assumes <namespace>.svc.cluster.local is in the DNS search space ...
12-
resource = '_couchdb._tcp.{0}'.format(
13-
os.environ.get("COUCHDB_SERVICE", "couchdb")
14-
)
11+
# Drop our Pod's unique identity and replace with '_couchdb._tcp'
12+
# to form the name of the SRV record
13+
resource = '.'.join(['_couchdb', '_tcp'] + socket.getfqdn().split('.')[1:])
14+
print ('SRV record', resource)
1515
if retries > 0:
1616
try:
1717
answers = dns.resolver.query(resource, 'SRV')
@@ -53,5 +53,4 @@ def sleep_forever():
5353
time.sleep(5)
5454

5555
if __name__ == '__main__':
56-
print(os.environ)
5756
discover_peers_dns()

0 commit comments

Comments
 (0)