Yuvipanda has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/278705

Change subject: labs: Add support for custom cnames in labs recursor
......................................................................

labs: Add support for custom cnames in labs recursor

Bug: T118758
Change-Id: I28b0dfaecd255490e5d60cdec9ff0fd67334b92f
---
A hieradata/common/dnsrecursor/labsaliaser.yaml
M modules/dnsrecursor/files/labs-ip-alias-dump.py
M modules/dnsrecursor/manifests/labsaliaser.pp
3 files changed, 37 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/operations/puppet 
refs/changes/05/278705/1

diff --git a/hieradata/common/dnsrecursor/labsaliaser.yaml 
b/hieradata/common/dnsrecursor/labsaliaser.yaml
new file mode 100644
index 0000000..9a9aa28
--- /dev/null
+++ b/hieradata/common/dnsrecursor/labsaliaser.yaml
@@ -0,0 +1,2 @@
+cnames:
+  tools-docker-registry.tools.eqiad.wmflabs: 
tools-docker-registry-01.tools.eqiad.wmflabs
diff --git a/modules/dnsrecursor/files/labs-ip-alias-dump.py 
b/modules/dnsrecursor/files/labs-ip-alias-dump.py
index 6de379e..11a54ea 100644
--- a/modules/dnsrecursor/files/labs-ip-alias-dump.py
+++ b/modules/dnsrecursor/files/labs-ip-alias-dump.py
@@ -20,7 +20,7 @@
     action='store_true'
 )
 
-LUA_LINE_TEMPLATE = 'aliasmapping["{public}"] = "{private}" -- {name}\n'
+LUA_LINE_TEMPLATE = '{table}["{key}"] = "{value}" -- {comment}\n'
 
 args = argparser.parse_args()
 config = yaml.safe_load(args.config_file)
@@ -59,7 +59,12 @@
 for name in sorted(aliases.keys()):
     ips = aliases[name]
     for public, private in ips:
-        output += LUA_LINE_TEMPLATE.format(private=private, public=public, 
name=name)
+        output += LUA_LINE_TEMPLATE.format(
+            table='aliasmapping',
+            key=public,
+            value=private,
+            comment=name
+        )
 
 output += """
 function postresolve (remoteip, domain, qtype, records, origrcode)
@@ -72,6 +77,32 @@
     end
     return origrcode, records
 end
+
+"""
+
+if 'cnames' in config:
+    output += 'cnamemapping = {}\n'
+    cnames = config['cnames']
+
+    for cname in sorted(cnames.keys()):
+        output += LUA_LINE_TEMPLATE.format(
+            table='cnamemapping',
+            key=cname,
+            value=cnames[cname],
+            comment=cname
+        )
+
+    output += """
+function nxdomain(dq)
+    print("Intercepting NXDOMAIN for: ",dq.qname:toString())
+    if cnamemapping[dq.qname]
+    then
+        dq.rcode=0 -- make it a normal answer
+        dq:addAnswer(pdns.CNAME, cnamemapping[dq.qname])
+        return true
+    end
+    return false
+end
 """
 
 if os.path.exists(config['output_path']):
diff --git a/modules/dnsrecursor/manifests/labsaliaser.pp 
b/modules/dnsrecursor/manifests/labsaliaser.pp
index 447948c..166a6e0 100644
--- a/modules/dnsrecursor/manifests/labsaliaser.pp
+++ b/modules/dnsrecursor/manifests/labsaliaser.pp
@@ -3,6 +3,7 @@
     $password,
     $projects,
     $nova_api_url,
+    $cnames,
     $alias_file,
 ) {
 
@@ -14,6 +15,7 @@
         'projects'     => $projects,
         'output_path'  => $alias_file,
         'nova_api_url' => $nova_api_url,
+        'cnames'       => $cnames,
     }
 
     file { '/etc/labs-dns-alias.yaml':

-- 
To view, visit https://gerrit.wikimedia.org/r/278705
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I28b0dfaecd255490e5d60cdec9ff0fd67334b92f
Gerrit-PatchSet: 1
Gerrit-Project: operations/puppet
Gerrit-Branch: production
Gerrit-Owner: Yuvipanda <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to