|
4 | 4 | import logging |
5 | 5 | import operator |
6 | 6 | import os |
7 | | -import string |
8 | 7 | import time |
9 | 8 | from urllib.parse import urljoin |
10 | 9 | import base64 |
11 | 10 |
|
12 | 11 | from django.conf import settings |
13 | 12 | from docker.auth import auth as docker_auth |
14 | 13 | from .states import PodState |
15 | | -import ruamel.yaml |
16 | 14 | import requests |
17 | 15 | from requests_toolbelt import user_agent |
18 | 16 | from .utils import dict_merge |
|
22 | 20 |
|
23 | 21 | logger = logging.getLogger(__name__) |
24 | 22 |
|
25 | | -# Ports and app type will be overwritten as required |
26 | | -SERVICE_TEMPLATE = """\ |
27 | | -kind: Service |
28 | | -apiVersion: v1 |
29 | | -metadata: |
30 | | - name: $name |
31 | | - labels: |
32 | | - app: $name |
33 | | - heritage: deis |
34 | | - annotations: {} |
35 | | -spec: |
36 | | - ports: |
37 | | - - name: http |
38 | | - port: 80 |
39 | | - targetPort: 5000 |
40 | | - protocol: TCP |
41 | | - selector: |
42 | | - app: $name |
43 | | - heritage: deis |
44 | | -""" |
45 | | - |
46 | 23 |
|
47 | 24 | class KubeException(Exception): |
48 | 25 | def __init__(self, *args, **kwargs): |
@@ -1054,7 +1031,7 @@ def create_rc(self, namespace, name, image, entrypoint, command, **kwargs): |
1054 | 1031 | resp, |
1055 | 1032 | 'create ReplicationController "{}" in Namespace "{}"', name, namespace |
1056 | 1033 | ) |
1057 | | - self.log(namespace, 'manifest used: {}'.format(ruamel.yaml.dump(manifest)), logging.DEBUG) # noqa |
| 1034 | + self.log(namespace, 'manifest used: {}'.format(json.dumps(manifest, indent=4)), logging.DEBUG) # noqa |
1058 | 1035 |
|
1059 | 1036 | self._wait_until_rc_is_updated(namespace, name) |
1060 | 1037 |
|
@@ -1292,10 +1269,32 @@ def get_services(self, namespace, **kwargs): |
1292 | 1269 | return response |
1293 | 1270 |
|
1294 | 1271 | def create_service(self, namespace, name, data={}, **kwargs): |
1295 | | - l = {"name": namespace} |
| 1272 | + # Ports and app type will be overwritten as required |
| 1273 | + manifest = { |
| 1274 | + 'kind': 'Service', |
| 1275 | + 'apiVersion': 'v1', |
| 1276 | + 'metadata': { |
| 1277 | + 'name': namespace, |
| 1278 | + 'labels': { |
| 1279 | + 'app': namespace, |
| 1280 | + 'heritage': 'deis' |
| 1281 | + }, |
| 1282 | + 'annotations': {} |
| 1283 | + }, |
| 1284 | + 'spec': { |
| 1285 | + 'ports': [{ |
| 1286 | + 'name': 'http', |
| 1287 | + 'port': 80, |
| 1288 | + 'targetPort': 5000, |
| 1289 | + 'protocol': 'TCP' |
| 1290 | + }], |
| 1291 | + 'selector': { |
| 1292 | + 'app': namespace, |
| 1293 | + 'heritage': 'deis' |
| 1294 | + } |
| 1295 | + } |
| 1296 | + } |
1296 | 1297 |
|
1297 | | - # Merge external data on to the prefined manifest |
1298 | | - manifest = ruamel.yaml.load(string.Template(SERVICE_TEMPLATE).substitute(l)) |
1299 | 1298 | data = dict_merge(manifest, data) |
1300 | 1299 | url = self._api("/namespaces/{}/services", namespace) |
1301 | 1300 | response = self.session.post(url, json=data) |
|
0 commit comments