Yuvipanda has submitted this change and it was merged.

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


Revert "Revert "labs: Add support for custom cnames in labs recursor""

This reverts commit fe667af6ecb23c2e5d816249e51a54f4ebbf90dc.

CNAMEs are needed if we want to get rid of /etc/hosts based
hacks for tools-db and tools-redis, which are still used by
code - https://phabricator.wikimedia.org/T139107#2421605

Change-Id: I4c90b8002409f5de9bdc48bc878c27348122ce6c
---
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(-)

Approvals:
  Yuvipanda: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/hieradata/common/dnsrecursor/labsaliaser.yaml 
b/hieradata/common/dnsrecursor/labsaliaser.yaml
new file mode 100644
index 0000000..7d68825
--- /dev/null
+++ b/hieradata/common/dnsrecursor/labsaliaser.yaml
@@ -0,0 +1,3 @@
+# CNAMEs for use in labs projects. REMEMBER THE TRAILING DOT.
+cnames:
+  tools-db.tools.eqiad.wmflabs.: tools.labsdb.
\ No newline at end of file
diff --git a/modules/dnsrecursor/files/labs-ip-alias-dump.py 
b/modules/dnsrecursor/files/labs-ip-alias-dump.py
index f30b1f5..3ce2930 100644
--- a/modules/dnsrecursor/files/labs-ip-alias-dump.py
+++ b/modules/dnsrecursor/files/labs-ip-alias-dump.py
@@ -24,7 +24,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)
@@ -78,7 +78,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)
@@ -91,6 +96,31 @@
     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 preresolve(remoteip, domain, qtype)
+    if cnamemapping[domain]
+    then
+        return 0, {
+            {qtype=pdns.CNAME, content=cnamemapping[domain], ttl=300, 
place="1"},
+        }
+    end
+    return -1, {}
+end
 """
 
 if os.path.exists(config['output_path']):
diff --git a/modules/dnsrecursor/manifests/labsaliaser.pp 
b/modules/dnsrecursor/manifests/labsaliaser.pp
index 1befb21..425760f 100644
--- a/modules/dnsrecursor/manifests/labsaliaser.pp
+++ b/modules/dnsrecursor/manifests/labsaliaser.pp
@@ -2,6 +2,7 @@
     $username,
     $password,
     $nova_api_url,
+    $cnames,
     $alias_file,
     $admin_project_name,
 ) {
@@ -13,6 +14,7 @@
         'password'           => $password,
         'output_path'        => $alias_file,
         'nova_api_url'       => $nova_api_url,
+        'cnames'             => $cnames,
         'admin_project_name' => $admin_project_name,
     }
 

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I4c90b8002409f5de9bdc48bc878c27348122ce6c
Gerrit-PatchSet: 4
Gerrit-Project: operations/puppet
Gerrit-Branch: production
Gerrit-Owner: Yuvipanda <yuvipa...@wikimedia.org>
Gerrit-Reviewer: Yuvipanda <yuvipa...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to