Skip to content

Commit f9cbe17

Browse files
committed
feat(crt): support containerd-ctr
1 parent cde3d6b commit f9cbe17

18 files changed

Lines changed: 27 additions & 537 deletions

charts/controller/templates/controller-clusterrole.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,11 @@ rules:
5656
- apiGroups: ["certmanager.k8s.io"]
5757
resources: ["certificates", "issuers"]
5858
verbs: ["get", "list", "watch", "create", "update", "delete"]
59+
- apiGroups: ["networking.k8s.io"]
60+
resources: ["ingresses"]
61+
verbs: ["get", "list", "create", "delete", "deletecollection", "patch", "update"]
62+
- apiGroups: ["apps"]
63+
resources: ["replicasets"]
64+
verbs: ["get", "list", "watch"]
5965
{{- end -}}
6066
{{- end -}}

charts/controller/templates/controller-deployment.yaml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,15 +130,10 @@ spec:
130130
fieldRef:
131131
fieldPath: metadata.namespace
132132
volumeMounts:
133-
- mountPath: /var/run/docker.sock
134-
name: docker-socket
135133
- mountPath: /etc/slugrunner
136134
name: slugrunner-config
137135
readOnly: true
138136
volumes:
139-
- name: docker-socket
140-
hostPath:
141-
path: /var/run/docker.sock
142137
- name: slugrunner-config
143138
configMap:
144139
name: slugrunner-config

rootfs/api/models/release.py

Lines changed: 3 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from django.conf import settings
44
from django.db import models
55

6-
from registry import publish_release, get_port as docker_get_port, RegistryException # noqa
76
from api.utils import dict_diff
87
from api.models import UuidAuditedModel
98
from api.exceptions import DryccException, AlreadyExists
@@ -66,7 +65,7 @@ def image(self):
6665
return '{}/{}:git-{}'.format(settings.REGISTRY_URL, self.app.id, str(self.build.sha))
6766
elif self.build.type == 'image':
6867
# Drycc Pull, docker image in local registry
69-
return '{}/{}:v{}'.format(settings.REGISTRY_URL, self.app.id, str(self.version))
68+
return self.build.image
7069
elif self.build.type == 'buildpack':
7170
# Build Pack - Registry URL not prepended since slugrunner image will download slug
7271
return self.build.image
@@ -81,69 +80,18 @@ def new(self, user, config, build, summary=None, source_version='latest'):
8180
# construct fully-qualified target image
8281
new_version = self.app.release_set.latest().version + 1
8382
# create new release and auto-increment version
84-
release = Release.objects.create(
83+
return Release.objects.create(
8584
owner=user, app=self.app, config=config,
8685
build=build, version=new_version, summary=summary
8786
)
8887

89-
try:
90-
release.publish()
91-
except DryccException as e:
92-
# If we cannot publish this app, just log and carry on
93-
self.app.log(e)
94-
pass
95-
except RegistryException as e:
96-
self.app.log(e)
97-
raise DryccException(str(e)) from e
98-
99-
return release
100-
101-
def publish(self):
102-
if self.build is None:
103-
raise DryccException('No build associated with this release to publish')
104-
105-
# If the build has a SHA, assume it's from drycc-builder and in the drycc-registry already
106-
if self.build.source_based:
107-
return
108-
109-
# Builder pushes to internal registry, exclude SHA based images from being returned early
110-
registry = self.config.registry
111-
if (
112-
registry.get('username', None) and
113-
registry.get('password', None) and
114-
# SHA means it came from a git push (builder)
115-
not self.build.sha and
116-
# hostname tells Builder where to push images
117-
not registry.get('hostname', None)
118-
) or (settings.REGISTRY_LOCATION != 'on-cluster'):
119-
self.app.log('{} exists in the target registry. Using image for release {} of app {}'.format(self.build.image, self.version, self.app)) # noqa
120-
return
121-
122-
# return image if it is already in the registry, test host and then host + port
123-
if (
124-
self.build.image.startswith(settings.REGISTRY_HOST) or
125-
self.build.image.startswith(settings.REGISTRY_URL)
126-
):
127-
self.app.log('{} exists in the target registry. Using image for release {} of app {}'.format(self.build.image, self.version, self.app)) # noqa
128-
return
129-
130-
# add tag if it was not provided
131-
source_image = self.build.image
132-
if ':' not in source_image:
133-
source_image = "{}:{}".format(source_image, self.build.version)
134-
135-
# if build is source based then it was pushed into the drycc registry
136-
drycc_registry = bool(self.build.source_based)
137-
publish_release(source_image, self.image, drycc_registry, self.get_registry_auth())
138-
13988
def get_port(self):
14089
"""
14190
Get application port for a given release. If pulling from private registry
14291
then use default port or read from ENV var, otherwise attempt to pull from
14392
the docker image
14493
"""
14594
try:
146-
drycc_registry = bool(self.build.source_based)
14795
envs = self.config.values
14896
creds = self.get_registry_auth()
14997

@@ -165,17 +113,8 @@ def get_port(self):
165113
return int(envs.get('PORT'))
166114

167115
# If the user provides PORT
168-
if envs.get('PORT', None):
169-
return int(envs.get('PORT'))
170-
171-
# discover port from docker image
172-
port = docker_get_port(self.image, drycc_registry, creds)
173-
if port is None and self.app.appsettings_set.latest().routable:
174-
msg = "Expose a port or make the app non routable by changing the process type"
175-
self.app.log(msg, logging.ERROR)
176-
raise DryccException(msg)
116+
return int(envs.get('PORT', 5000))
177117

178-
return port
179118
except Exception as e:
180119
raise DryccException(str(e)) from e
181120

rootfs/api/tests/__init__.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@
99
from rest_framework.test import APITestCase, APITransactionTestCase
1010

1111

12-
def mock_port(*args, **kwargs):
13-
return 5000
14-
15-
1612
# Mock out router requests and add in some jitter
1713
# Used for application is available in router checks
1814
def fake_responses(request, context):

rootfs/api/tests/test_app.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from scheduler import KubeException, KubeHTTPException
2121

2222
from api.exceptions import DryccException
23-
from api.tests import adapter, mock_port, DryccTestCase
23+
from api.tests import adapter, DryccTestCase
2424
import requests_mock
2525

2626

@@ -33,8 +33,6 @@ def _mock_run(*args, **kwargs):
3333

3434

3535
@requests_mock.Mocker(real_http=True, adapter=adapter)
36-
@mock.patch('api.models.release.publish_release', lambda *args: None)
37-
@mock.patch('api.models.release.docker_get_port', mock_port)
3836
class AppTest(DryccTestCase):
3937
"""Tests creation of applications"""
4038

@@ -280,7 +278,6 @@ def test_run_without_release_should_error(self, mock_requests):
280278

281279
@mock.patch('api.models.App.run', _mock_run)
282280
@mock.patch('api.models.App.deploy', mock_none)
283-
@mock.patch('api.models.Release.publish', mock_none)
284281
def test_run(self, mock_requests):
285282
"""
286283
A user should be able to run a one off command

rootfs/api/tests/test_app_settings.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,10 @@
77
from api.models import App
88
from unittest import mock
99
from scheduler import KubeException
10-
from api.tests import adapter, mock_port, DryccTransactionTestCase
10+
from api.tests import adapter, DryccTransactionTestCase
1111

1212

1313
@requests_mock.Mocker(real_http=True, adapter=adapter)
14-
@mock.patch('api.models.release.publish_release', lambda *args: None)
15-
@mock.patch('api.models.release.docker_get_port', mock_port)
1614
class TestAppSettings(DryccTransactionTestCase):
1715
"""Tests setting and updating config values"""
1816

rootfs/api/tests/test_build.py

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,13 @@
1313
from rest_framework.authtoken.models import Token
1414

1515
from api.models import Build, App
16-
from registry.dockerclient import RegistryException
1716
from scheduler import KubeException
1817

19-
from api.tests import adapter, mock_port, DryccTransactionTestCase
18+
from api.tests import adapter, DryccTransactionTestCase
2019
import requests_mock
2120

2221

2322
@requests_mock.Mocker(real_http=True, adapter=adapter)
24-
@mock.patch('api.models.release.publish_release', lambda *args: None)
25-
@mock.patch('api.models.release.docker_get_port', mock_port)
2623
class BuildTest(DryccTransactionTestCase):
2724

2825
"""Tests build notification from build system"""
@@ -639,27 +636,6 @@ def test_release_create_failure(self, mock_requests):
639636
response = self.client.post(url, body)
640637
self.assertEqual(response.status_code, 400, response.data)
641638

642-
def test_release_registry_create_failure(self, mock_requests):
643-
"""
644-
Cause a RegistryException in app.deploy to cause a failed release in build.create
645-
"""
646-
app_id = self.create_app()
647-
648-
# deploy app to get a build
649-
url = "/v2/apps/{app_id}/builds".format(**locals())
650-
body = {'image': 'autotest/example', 'stack': 'container'}
651-
response = self.client.post(url, body)
652-
self.assertEqual(response.status_code, 201, response.data)
653-
self.assertEqual(response.data['image'], body['image'])
654-
655-
with mock.patch('api.models.Release.publish') as mock_registry:
656-
mock_registry.side_effect = RegistryException('Boom!')
657-
658-
url = "/v2/apps/{app_id}/builds".format(**locals())
659-
body = {'image': 'autotest/example', 'stack': 'container'}
660-
response = self.client.post(url, body)
661-
self.assertEqual(response.status_code, 400, response.data)
662-
663639
def test_build_deploy_kube_failure(self, mock_requests):
664640
"""
665641
Cause an Exception in scheduler.deploy

rootfs/api/tests/test_config.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,11 @@
1414

1515
from api.models import App, Config
1616

17-
from api.tests import adapter, mock_port, DryccTransactionTestCase
17+
from api.tests import adapter, DryccTransactionTestCase
1818
import requests_mock
1919

2020

2121
@requests_mock.Mocker(real_http=True, adapter=adapter)
22-
@mock.patch('api.models.release.publish_release', lambda *args: None)
23-
@mock.patch('api.models.release.docker_get_port', mock_port)
2422
class ConfigTest(DryccTransactionTestCase):
2523
"""Tests setting and updating config values"""
2624

rootfs/api/tests/test_healthchecks.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
import json
22
import requests_mock
3-
from unittest import mock
43

54
from django.core.cache import cache
65
from django.contrib.auth.models import User
76
from rest_framework.authtoken.models import Token
87

98
from api.models import App
10-
from api.tests import adapter, mock_port, DryccTransactionTestCase
9+
from api.tests import adapter, DryccTransactionTestCase
1110

1211

1312
@requests_mock.Mocker(real_http=True, adapter=adapter)
14-
@mock.patch('api.models.release.publish_release', lambda *args: None)
15-
@mock.patch('api.models.release.docker_get_port', mock_port)
1613
class TestHealthchecks(DryccTransactionTestCase):
1714
"""Tests setting and updating config values"""
1815

rootfs/api/tests/test_hooks.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@
66
from django.conf import settings
77
from django.contrib.auth.models import User
88
from django.core.cache import cache
9-
from unittest import mock
109
from rest_framework.authtoken.models import Token
1110

12-
from api.tests import adapter, mock_port, DryccTransactionTestCase
11+
from api.tests import adapter, DryccTransactionTestCase
1312
import requests_mock
1413

1514
RSA_PUBKEY = (
@@ -48,8 +47,6 @@
4847

4948

5049
@requests_mock.Mocker(real_http=True, adapter=adapter)
51-
@mock.patch('api.models.release.publish_release', lambda *args: None)
52-
@mock.patch('api.models.release.docker_get_port', mock_port)
5350
class HookTest(DryccTransactionTestCase):
5451

5552
"""Tests API hooks used to trigger actions from external components"""

0 commit comments

Comments
 (0)