Skip to content

Commit 666c7fc

Browse files
author
Matthew Fisher
committed
Merge pull request #3749 from bacongobbler/3488-make-controller-hostname-configurable
feat(router): allow customizing controller subdomain
2 parents 801ae74 + db191ba commit 666c7fc

7 files changed

Lines changed: 30 additions & 6 deletions

File tree

controller/api/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def validate_app_structure(value):
9292

9393
def validate_reserved_names(value):
9494
"""A value cannot use some reserved names."""
95-
if value in ['deis']:
95+
if value in settings.DEIS_RESERVED_NAMES:
9696
raise ValidationError('{} is a reserved name.'.format(value))
9797

9898

controller/api/tests/test_app.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,6 @@ def test_app_errors(self):
156156
HTTP_AUTHORIZATION='token {}'.format(self.token))
157157
self.assertContains(response, 'App IDs can only contain [a-z0-9-]', status_code=400)
158158
url = '/v1/apps'
159-
body = {'id': 'deis'}
160-
response = self.client.post(url, json.dumps(body), content_type='application/json',
161-
HTTP_AUTHORIZATION='token {}'.format(self.token))
162-
self.assertContains(response, 'deis is a reserved name.', status_code=400)
163159
body = {'id': app_id}
164160
response = self.client.post(url, json.dumps(body), content_type='application/json',
165161
HTTP_AUTHORIZATION='token {}'.format(self.token))
@@ -175,6 +171,20 @@ def test_app_errors(self):
175171
HTTP_AUTHORIZATION='token {}'.format(self.token))
176172
self.assertEquals(response.status_code, 404)
177173

174+
def test_app_reserved_names(self):
175+
"""Nobody should be able to create applications with names which are reserved."""
176+
url = '/v1/apps'
177+
reserved_names = ['foo', 'bar']
178+
with self.settings(DEIS_RESERVED_NAMES=reserved_names):
179+
for name in reserved_names:
180+
body = {'id': name}
181+
response = self.client.post(url, json.dumps(body), content_type='application/json',
182+
HTTP_AUTHORIZATION='token {}'.format(self.token))
183+
self.assertContains(
184+
response,
185+
'{} is a reserved name.'.format(name),
186+
status_code=400)
187+
178188
def test_app_structure_is_valid_json(self):
179189
"""Application structures should be valid JSON objects."""
180190
url = '/v1/apps'

controller/deis/settings.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,9 @@
287287
# standard datetime format used for logging, model timestamps, etc.
288288
DEIS_DATETIME_FORMAT = '%Y-%m-%dT%H:%M:%S%Z'
289289

290+
# names which apps cannot reserve for routing
291+
DEIS_RESERVED_NAMES = ['deis']
292+
290293
# default scheduler settings
291294
SCHEDULER_MODULE = 'scheduler.mock'
292295
SCHEDULER_TARGET = '' # path to scheduler endpoint (e.g. /var/run/fleet.sock)

controller/templates/confd_settings.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@
4949
{{ end }}
5050
UNIT_HOSTNAME = '{{ if exists "/deis/controller/unitHostname" }}{{ getv "/deis/controller/unitHostname" }}{{ else }}default{{ end }}'
5151

52+
{{ if exists "/deis/controller/subdomain" }}
53+
DEIS_RESERVED_NAMES = ['{{ getv "/deis/controller/subdomain" }}']
54+
{{ end }}
55+
5256
# AUTH
5357
# LDAP
5458
{{ if exists "/deis/controller/auth/ldap/endpoint" }}

docs/customizing_deis/controller_settings.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ setting description
4141
==================================== ======================================================
4242
/deis/controller/registrationMode set registration to "enabled", "disabled", or "admin_only" (default: "enabled")
4343
/deis/controller/schedulerModule scheduler backend (default: "fleet")
44+
/deis/controller/subdomain subdomain used by the router for API requests (default: "deis")
4445
/deis/controller/webEnabled enable controller web UI (default: 0)
4546
/deis/controller/workers number of web worker processes (default: CPU cores * 2 + 1)
4647
/deis/cache/host host of the cache component (set by cache)

docs/using_deis/register-user.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ Note that you always use ``deis.<domain>`` to communicate with the controller.
2929

3030
For Vagrant clusters: ``deis register http://deis.local3.deisapp.com``
3131

32+
.. note::
33+
34+
The subdomain can be customized by using ``deisctl config controller set subdomain=foo``. The
35+
router will then route requests from ``foo.<domain>`` to the controller. See
36+
:ref:`controller_settings` for more info on how to customize the controller.
37+
3238
.. important::
3339

3440
The first user to register with Deis receives "superuser" privileges. Additional users who

router/image/templates/nginx.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ http {
7979
{{ end }}
8080

8181
server {
82-
server_name ~^deis\.(?<domain>.+)$;
82+
server_name ~^{{ or (getv "/deis/controller/subdomain") "deis" }}\.(?<domain>.+)$;
8383
include deis.conf;
8484

8585
{{ if exists "/deis/controller/host" }}

0 commit comments

Comments
 (0)