Skip to content

Commit 721c06a

Browse files
committed
chore(controller): add reserved names config
1 parent d581390 commit 721c06a

7 files changed

Lines changed: 45 additions & 11 deletions

File tree

charts/controller/templates/_helpers.tpl

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ env:
130130
name: victoriametrics-vmauth-creds
131131
key: password
132132
- name: "DRYCC_VICTORIAMETRICS_URL"
133-
value: "http://$(DRYCC_VICTORIAMETRICS_USERNAME):$(DRYCC_VICTORIAMETRICS_PASSWORD)@drycc-victoriametrics-vmauth.{{$.Release.Namespace}}.svc.{{$.Values.global.clusterDomain}}:8481"
133+
value: "http://$(DRYCC_VICTORIAMETRICS_USERNAME):$(DRYCC_VICTORIAMETRICS_PASSWORD)@drycc-victoriametrics-vmauth.{{$.Release.Namespace}}.svc.{{$.Values.global.clusterDomain}}:8427"
134134
{{- end }}
135135
{{- if .Values.passport.enabled }}
136136
- name: "DRYCC_PASSPORT_URL"
@@ -172,7 +172,6 @@ env:
172172
{{- end }}
173173
{{- end }}
174174

175-
176175
{{- define "controller-job.envs" }}
177176
{{- include "controller.envs" . }}
178177
- name: DRYCC_DATABASE_ROUTERS
@@ -329,6 +328,29 @@ kubelet_volume_stats_inodes_free: [namespace, persistentvolumeclaim, job]
329328
kubelet_volume_stats_inodes_used: [namespace, persistentvolumeclaim, job]
330329
{{- end }}
331330

331+
{{/* Generate controller config default reserved names */}}
332+
{{ define "controller.config.defaultReservedNames" }}
333+
backup
334+
catalog
335+
cert-manager
336+
default
337+
drycc
338+
drycc-manager
339+
drycc-helmbroker
340+
drycc-builder
341+
drycc-grafana
342+
drycc-passport
343+
istio-gateway
344+
istio-system
345+
kube-node-lease
346+
kube-public
347+
kube-system
348+
longhorn-system
349+
metallb
350+
mount-s3
351+
topolvm
352+
rook-ceph
353+
{{- end }}
332354

333355
{{/* Generate controller config default secrets template */}}
334356
{{ define "controller.config.defaultSecretTemplate" }}

charts/controller/templates/controller-configmap.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ data:
2323
{{- else}}
2424
{{- include "controller.config.defaultLimitPlans" . | fromYamlArray | toPrettyJson | nindent 4 }}
2525
{{- end }}
26+
reserved-names.txt: |-
27+
{{- if .Values.config.reservedNames }}
28+
{{- (tpl .Values.config.reservedNames $) | nindent 4 }}
29+
{{- else}}
30+
{{- include "controller.config.defaultReservedNames" . | nindent 4 }}
31+
{{- end }}
2632
secret-template.json: |
2733
{{- if .Values.config.secretTemplate }}
2834
{{- (tpl .Values.config.secretTemplate $) | nindent 4 }}

charts/controller/values.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ config:
7676
metrics: ""
7777
limitSpecs: ""
7878
limitPlans: ""
79+
reservedNames: ""
7980
secretTemplate: ""
8081
volumeTemplate: ""
8182
volumeClaimTemplate: ""
@@ -88,8 +89,7 @@ service:
8889
# Any custom controller environment variables
8990
# can be specified as key-value pairs under environment
9091
# this is usually a non required setting.
91-
environment:
92-
RESERVED_NAMES: "drycc, drycc-builder, drycc-grafana, drycc-passport, drycc-helmbroker, drycc-manager"
92+
environment: {}
9393

9494
api:
9595
resources: {}

rootfs/api/models/app.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def validate_app_id(value):
8484
"""
8585
Check that the value follows the kubernetes name constraints
8686
"""
87-
match = re.match(r'[a-z]([a-z0-9-]*[a-z0-9])?$', value)
87+
match = re.match(r'^[a-z]([a-z0-9-]{3,}[a-z0-9])$', value)
8888
if not match:
8989
raise ValidationError("App name must start with an alphabetic character, cannot end with a"
9090
+ " hyphen and can only contain a-z (lowercase), 0-9 and hyphens.")
@@ -101,7 +101,7 @@ def validate_app_structure(value):
101101

102102
def validate_reserved_names(value):
103103
"""A value cannot use some reserved names."""
104-
if value in settings.DRYCC_RESERVED_NAMES:
104+
if value in settings.RESERVED_NAMES:
105105
raise ValidationError('{} is a reserved name.'.format(value))
106106

107107

rootfs/api/settings/production.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,13 @@
248248
TEMPDIR = tempfile.mkdtemp(prefix='drycc')
249249

250250
# names which apps cannot reserve for routing
251-
DRYCC_RESERVED_NAMES = os.environ.get('RESERVED_NAMES', '').replace(' ', '').split(',')
251+
RESERVED_NAMES_PATH = os.environ.get(
252+
'RESERVED_NAMES_PATH', '/etc/controller/reserved-names.txt')
253+
if os.path.exists(RESERVED_NAMES_PATH):
254+
with open(RESERVED_NAMES_PATH) as f:
255+
RESERVED_NAMES = [line.strip() for line in f if line]
256+
else:
257+
RESERVED_NAMES = ["drycc", "drycc-helmbroker", "drycc-manager", "kube-system", "default"]
252258

253259
# the k8s namespace in which the controller and workflow were installed.
254260
WORKFLOW_NAMESPACE = os.environ.get('WORKFLOW_NAMESPACE', 'drycc')

rootfs/api/tests/test_app.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ def test_app_errors(self, mock_requests):
159159
def test_app_reserved_names(self, mock_requests):
160160
"""Nobody should be able to create applications with names which are reserved."""
161161
reserved_names = ['foo', 'bar']
162-
with self.settings(DRYCC_RESERVED_NAMES=reserved_names):
162+
with self.settings(RESERVED_NAMES=reserved_names):
163163
for name in reserved_names:
164164
response = self.client.post('/v2/apps', {'id': name})
165165
self.assertContains(
@@ -531,7 +531,7 @@ def test_list_ordering(self, mock_requests):
531531
"""
532532
Test that a list of apps is sorted by name
533533
"""
534-
for name in ['zulu', 'tango', 'alpha', 'foxtrot']:
534+
for name in ['zulua', 'tango', 'alpha', 'foxtrot']:
535535
response = self.client.post('/v2/apps', {'id': name})
536536
self.assertEqual(response.status_code, 201, response.data)
537537

@@ -540,7 +540,7 @@ def test_list_ordering(self, mock_requests):
540540
self.assertEqual(apps[0]['id'], 'alpha')
541541
self.assertEqual(apps[1]['id'], 'foxtrot')
542542
self.assertEqual(apps[2]['id'], 'tango')
543-
self.assertEqual(apps[3]['id'], 'zulu')
543+
self.assertEqual(apps[3]['id'], 'zulua')
544544

545545
def test_get_private_registry_config(self, mock_requests):
546546
registry = {"web": {'username': 'test', 'password': 'test'}}

rootfs/api/tests/test_release.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ def test_deploy_hooks_logged(self, mock_requests, mock_logger):
614614
"""
615615
Verifies that a configured deploy hook is dumped into the logs when a release is created.
616616
"""
617-
app_id = 'foo'
617+
app_id = 'foooo'
618618
body = {'sha': '123456', 'image': 'autotest/example', 'stack': 'heroku-18'}
619619

620620
mr_rocks = mock_requests.post(f'http://drycc.rocks?app={app_id}&user={self.user.username}&sha=&release=v1&release_summary={self.user.username}+created+initial+release') # noqa

0 commit comments

Comments
 (0)