Skip to content

Commit 46c0c03

Browse files
author
Matthew Fisher
committed
ref(router): split domains to its own custom directive
In order to support multiple certs on multiple custom domains bound to the same application, we need to split out each custom domain to its own `server {}` directive. In master, the domain etcd keys are set like so: SET /deis/domains/go "www.bacongobbler.com foo.bacongobbler.com" In confd v0.5.0, there is no way to split strings by whitespace so there's no way to iterate through each domain bound to an application. In this commit, there's a controller data migration script which will migrate existing etcd keys for custom domain endpoints over to the new syntax: SET /deis/domains/www.bacongobbler.com "go" SET /deis/domains/foo.bacongobbler.com "go" Confd v0.8.0 has support for splitting strings, but with this approach we can start providing support for migrations such as the one proposed in #3399.
1 parent 6bf23b1 commit 46c0c03

3 files changed

Lines changed: 41 additions & 17 deletions

File tree

api/models.py

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -977,29 +977,26 @@ def _etcd_publish_cert(**kwargs):
977977

978978
def _etcd_purge_cert(**kwargs):
979979
cert = kwargs['instance']
980-
_etcd_client.delete('/deis/certs/{}'.format(cert),
981-
prevExist=True, dir=True, recursive=True)
980+
try:
981+
_etcd_client.delete('/deis/certs/{}'.format(cert),
982+
prevExist=True, dir=True, recursive=True)
983+
except KeyError:
984+
pass
982985

983986

984987
def _etcd_publish_domains(**kwargs):
985-
app = kwargs['instance'].app
986-
app_domains = app.domain_set.all()
987-
if app_domains:
988-
_etcd_client.write('/deis/domains/{}'.format(app),
989-
' '.join(str(d.domain) for d in app_domains))
988+
domain = kwargs['instance']
989+
if kwargs['created']:
990+
_etcd_client.write('/deis/domains/{}'.format(domain), domain.app)
990991

991992

992993
def _etcd_purge_domains(**kwargs):
993-
app = kwargs['instance'].app
994-
app_domains = app.domain_set.all()
995-
if app_domains:
996-
_etcd_client.write('/deis/domains/{}'.format(app),
997-
' '.join(str(d.domain) for d in app_domains))
998-
else:
999-
try:
1000-
_etcd_client.delete('/deis/domains/{}'.format(app))
1001-
except KeyError:
1002-
pass
994+
domain = kwargs['instance']
995+
try:
996+
_etcd_client.delete('/deis/certs/{}'.format(domain),
997+
prevExist=True, dir=True, recursive=True)
998+
except KeyError:
999+
pass
10031000

10041001

10051002
# Log significant app-related events

bin/boot

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@ etcd_safe_mkdir /deis/services
5656
etcd_safe_mkdir /deis/domains
5757
etcd_safe_mkdir /deis/platform
5858

59+
# run etcd data migrations
60+
echo "controller: running etcd data migrations..."
61+
for script in $(ls /app/migrations/data/*.sh);
62+
do
63+
. $script;
64+
done
65+
echo "controller: done running etcd data migrations."
66+
5967
# wait for confd to run once and install initial templates
6068
until confd -onetime -node $ETCD --confdir /app --interval 5 --quiet 2>/dev/null; do
6169
echo "controller: waiting for confd to write initial templates..."

migrations/data/0001.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env bash
2+
3+
ETCD_PORT=${ETCD_PORT:-4001}
4+
ETCD="$HOST:$ETCD_PORT"
5+
ETCDCTL="etcdctl -C $ETCD"
6+
7+
if [[ "$($ETCDCTL get /deis/migrations/data/0001 2> /dev/null)" != "done" ]];
8+
then
9+
for i in $($ETCDCTL ls /deis/domains 2> /dev/null);
10+
do
11+
for j in $($ETCDCTL get $i);
12+
do
13+
$ETCDCTL set /deis/domains/$j "$(basename $i)" 1> /dev/null;
14+
echo "migrated $j"
15+
done;
16+
$ETCDCTL rm $i;
17+
done
18+
$ETCDCTL set /deis/migrations/data/0001 "done"
19+
fi

0 commit comments

Comments
 (0)