Skip to content

Commit d014017

Browse files
author
Matthew Fisher
authored
Merge branch 'master' into fix-modifying-docker-socket-gid
2 parents d2ee40f + 0aec26a commit d014017

13 files changed

Lines changed: 119 additions & 16 deletions

File tree

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ postgres: check-docker
5151
@echo " export PGUSER=postgres"
5252

5353
setup-venv:
54-
@if [ ! -d venv ]; then pyvenv venv && source venv/bin/activate; fi
55-
pip install --disable-pip-version-check -q -r rootfs/requirements.txt -r rootfs/dev_requirements.txt
54+
python3 -m venv venv
55+
venv/bin/pip3 install --disable-pip-version-check -q -r rootfs/requirements.txt -r rootfs/dev_requirements.txt
5656

5757
test: test-style test-check test-unit test-functional
5858

rootfs/api/models/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def _save_service_config(self, app, component, data):
8888
component = "%s.deis.io/" % component
8989

9090
# add component to data and flatten
91-
data = {"%s%s" % (component, key): value for key, value in list(data.items())}
91+
data = {"%s%s" % (component, key): value for key, value in list(data.items()) if value}
9292
svc['metadata']['annotations'].update(morph.flatten(data))
9393

9494
# Update the k8s service for the application with new service information

rootfs/api/models/app.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ def create(self, *args, **kwargs): # noqa
203203
# create required minimum resources in k8s for the application
204204
namespace = self.id
205205
service = self.id
206+
quota_name = '{}-quota'.format(self.id)
206207
try:
207208
self.log('creating Namespace {} and services'.format(namespace), level=logging.DEBUG)
208209
# Create essential resources
@@ -211,6 +212,15 @@ def create(self, *args, **kwargs): # noqa
211212
except KubeException:
212213
self._scheduler.ns.create(namespace)
213214

215+
if settings.KUBERNETES_NAMESPACE_DEFAULT_QUOTA_SPEC != '':
216+
quota_spec = json.loads(settings.KUBERNETES_NAMESPACE_DEFAULT_QUOTA_SPEC)
217+
self.log('creating Quota {} for namespace {}'.format(quota_name, namespace),
218+
level=logging.DEBUG)
219+
try:
220+
self._scheduler.quota.get(namespace, quota_name)
221+
except KubeException:
222+
self._scheduler.quota.create(namespace, quota_name, data=quota_spec)
223+
214224
try:
215225
self._scheduler.svc.get(namespace, service)
216226
except KubeException:

rootfs/api/models/domain.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ def delete(self, *args, **kwargs):
4949
app = str(self.app)
5050
domain = str(self.domain)
5151

52+
# Deatch cert, updates k8s
53+
if self.certificate:
54+
self.certificate.detach(domain=domain)
55+
5256
# get config for the service
5357
config = self._load_service_config(app, 'router')
5458

@@ -64,10 +68,6 @@ def delete(self, *args, **kwargs):
6468

6569
self._save_service_config(app, 'router', config)
6670

67-
# Deatch cert, updates k8s
68-
if self.certificate:
69-
self.certificate.detach(domain=str(self.domain))
70-
7171
# Delete from DB
7272
return super(Domain, self).delete(*args, **kwargs)
7373

rootfs/api/settings/production.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,9 @@
299299
# How long k8s waits for a pod to finish work after a SIGTERM before sending SIGKILL
300300
KUBERNETES_POD_TERMINATION_GRACE_PERIOD_SECONDS = int(os.environ.get('KUBERNETES_POD_TERMINATION_GRACE_PERIOD_SECONDS', 30)) # noqa
301301

302+
# Default quota spec for application namespace
303+
KUBERNETES_NAMESPACE_DEFAULT_QUOTA_SPEC = os.environ.get('KUBERNETES_NAMESPACE_DEFAULT_QUOTA_SPEC', '') # noqa
304+
302305
# registry settings
303306
REGISTRY_HOST = os.environ.get('DEIS_REGISTRY_SERVICE_HOST', '127.0.0.1')
304307
REGISTRY_PORT = os.environ.get('DEIS_REGISTRY_SERVICE_PORT', 5000)

rootfs/api/settings/testing.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,4 @@
3636

3737
# How long k8s waits for a pod to finish work after a SIGTERM before sending SIGKILL
3838
KUBERNETES_POD_TERMINATION_GRACE_PERIOD_SECONDS = int(os.environ.get('KUBERNETES_POD_TERMINATION_GRACE_PERIOD_SECONDS', 2)) # noqa
39+
KUBERNETES_NAMESPACE_DEFAULT_QUOTA_SPEC = '{"spec":{"hard":{"pods":"10"}}}'

rootfs/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ jmespath==0.9.0
1010
jsonfield==1.0.3
1111
morph==0.1.2
1212
ndg-httpsclient==0.4.2
13+
packaging==16.8
1314
psycopg2==2.6.2
1415
pyOpenSSL==16.2.0
1516
pytz==2016.10

rootfs/scheduler/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from collections import OrderedDict
22
from datetime import datetime
33
import logging
4+
from packaging.version import Version
45
import requests
56
import requests.exceptions
67
from requests_toolbelt import user_agent
@@ -77,13 +78,13 @@ def __getattr__(self, name):
7778
return object.__getattribute__(self, name)
7879

7980
def version(self):
80-
"""Get Kubernetes version as a float"""
81+
"""Get Kubernetes version"""
8182
response = self.http_get('/version')
8283
if self.unhealthy(response.status_code):
8384
raise KubeHTTPException(response, 'fetching Kubernetes version')
8485

8586
data = response.json()
86-
return float('{}.{}'.format(data['major'], data['minor']))
87+
return Version('{}.{}'.format(data['major'], data['minor']))
8788

8889
@staticmethod
8990
def parse_date(date):

rootfs/scheduler/mock.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def _acquire(self):
8080
resources = [
8181
'namespaces', 'nodes', 'pods', 'replicationcontrollers',
8282
'secrets', 'services', 'events', 'deployments', 'replicasets',
83-
'horizontalpodautoscalers', 'scale',
83+
'horizontalpodautoscalers', 'scale', 'resourcequotas'
8484
]
8585

8686

rootfs/scheduler/resources/horizontalpodautoscaler.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import json
2+
from packaging.version import parse
3+
24
from scheduler.resources import Resource
35
from scheduler.exceptions import KubeException, KubeHTTPException
46

@@ -11,7 +13,7 @@ class HorizontalPodAutoscaler(Resource):
1113
def api_version(self):
1214
# API location changes between versions
1315
# http://kubernetes.io/docs/user-guide/horizontal-pod-autoscaling/#api-object
14-
if self.version() >= 1.3:
16+
if self.version() >= parse("1.3.0"):
1517
return 'autoscaling/v1'
1618

1719
# 1.2 and older
@@ -69,15 +71,15 @@ def manifest(self, namespace, name, app_type, target, **kwargs):
6971
}
7072
}
7173

72-
if self.version() >= 1.3:
74+
if self.version() >= parse("1.3.0"):
7375
manifest['spec']['targetCPUUtilizationPercentage'] = cpu_percent
7476

7577
manifest['spec']['scaleTargetRef'] = {
7678
# only works with Deployments, RS and RC
7779
'kind': target['kind'],
7880
'name': target['metadata']['name'],
7981
}
80-
elif self.version() <= 1.2:
82+
elif self.version() <= parse("1.2.0"):
8183
# api changed between version
8284
manifest['spec']['cpuUtilization'] = {
8385
'targetPercentage': cpu_percent
@@ -149,10 +151,10 @@ def wait(self, namespace, name):
149151
# ideally it would use the resources wait commands but they vary
150152
for _ in range(30):
151153
# fetch resource attached to it
152-
if self.version() >= 1.3:
154+
if self.version() >= parse("1.3.0"):
153155
resource_kind = hpa['spec']['scaleTargetRef']['kind'].lower()
154156
resource_name = hpa['spec']['scaleTargetRef']['name']
155-
elif self.version() <= 1.2:
157+
elif self.version() <= parse("1.2.0"):
156158
resource_kind = hpa['spec']['scaleRef']['kind'].lower()
157159
resource_name = hpa['spec']['scaleRef']['name']
158160

0 commit comments

Comments
 (0)