Skip to content

Commit ca2d8af

Browse files
committed
fix(service): update port error
1 parent 3224f84 commit ca2d8af

4 files changed

Lines changed: 42 additions & 15 deletions

File tree

charts/controller/templates/_helpers.tpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
{{- define "controller.envs" }}
33
env:
44
- name: VERSION
5-
value: {{ .Chart.appVersion }}
5+
value: {{ .Chart.AppVersion }}
66
- name: REGISTRATION_MODE
77
value: {{ .Values.registrationMode }}
88
# Environmental variable value for $GATEWAY_CLASS

charts/controller/templates/controller-job-init.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@ metadata:
55
spec:
66
template:
77
spec:
8-
initContainers:
9-
- name: drycc-controller-job-init
10-
image: {{.Values.imageRegistry}}/{{.Values.imageOrg}}/python-dev:latest
11-
imagePullPolicy: {{.Values.imagePullPolicy}}
12-
args:
8+
initContainers:
9+
- name: drycc-controller-job-init
10+
image: {{.Values.imageRegistry}}/{{.Values.imageOrg}}/python-dev:latest
11+
imagePullPolicy: {{.Values.imagePullPolicy}}
12+
args:
1313
- netcat
1414
- -v
1515
- -u
1616
- $(DRYCC_DATABASE_URL),$(DRYCC_DATABASE_REPLICA_URL),$(DRYCC_RABBITMQ_URL)
1717
- -a
1818
- $(DRYCC_REDIS_ADDRS),$(DRYCC_CONTROLLER_API_SERVICE_HOST):$(DRYCC_CONTROLLER_API_SERVICE_PORT)
19-
{{- include "controller.envs" . | indent 8 }}
19+
{{- include "controller.envs" . | indent 6 }}
2020
containers:
2121
- name: drycc-controller-job-init
2222
image: {{.Values.imageRegistry}}/{{.Values.imageOrg}}/controller:{{.Values.imageTag}}

rootfs/api/exceptions.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ def custom_exception_handler(exc, context):
4343
# No response means DRF couldn't handle it
4444
# Output a generic 500 in a JSON format
4545
if response is None:
46-
raise exc
4746
logging.exception('Uncaught Exception', exc_info=exc)
4847
set_rollback()
4948
return Response({'detail': 'Server Error'}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)

rootfs/api/models/service.py

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,48 @@
11
import logging
2-
2+
import jsonschema
3+
from functools import partial
34
from django.db import models
45
from django.conf import settings
56
from django.contrib.auth import get_user_model
7+
from rest_framework.exceptions import ValidationError
68
from api.exceptions import ServiceUnavailable
79
from scheduler import KubeException
810
from .base import AuditedModel
911

12+
1013
User = get_user_model()
1114
logger = logging.getLogger(__name__)
15+
service_ports_schema = {
16+
"$schema": "http://json-schema.org/schema#",
17+
"type": "array",
18+
"minItems": 1,
19+
"items": {
20+
"type": "object",
21+
"properties": {
22+
"name": {"type": "string"},
23+
"port": {"type": "integer"},
24+
"protocol": {"type": "string"},
25+
"targetPort": {"type": "integer"},
26+
},
27+
"required": ["name", "port", "protocol", "targetPort"],
28+
}
29+
}
30+
31+
32+
def validate_json(value, schema):
33+
if value is not None:
34+
try:
35+
jsonschema.validate(value, schema)
36+
except jsonschema.ValidationError as e:
37+
raise ValidationError(e.message)
38+
return value
1239

1340

1441
class Service(AuditedModel):
1542
owner = models.ForeignKey(User, on_delete=models.PROTECT)
1643
app = models.ForeignKey('App', on_delete=models.CASCADE)
17-
ports = models.JSONField(default=list)
44+
ports = models.JSONField(
45+
default=list, validators=[partial(validate_json, schema=service_ports_schema)])
1846
canary = models.BooleanField(default=False)
1947
procfile_type = models.TextField()
2048

@@ -58,11 +86,11 @@ def add_port(self, port, protocol, target_port):
5886
})
5987

6088
def update_port(self, port, protocol, target_port):
61-
port = self.get_port(port, "TCP")
62-
if not port or port["targetPort"] != target_port:
63-
if port and port["targetPort"] != target_port:
64-
self.remove_port(port, "TCP")
65-
self.add_port(port, "TCP", target_port)
89+
item = self.get_port(port, protocol)
90+
if not item or item["targetPort"] != target_port:
91+
if item and item["targetPort"] != target_port:
92+
self.remove_port(port, protocol)
93+
self.add_port(port, protocol, target_port)
6694
return True
6795
return False
6896

0 commit comments

Comments
 (0)