Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support new-style networks for Marathon #54

Merged
merged 1 commit into from Aug 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
39 changes: 38 additions & 1 deletion deploy_config_generator/output/marathon.py
Expand Up @@ -229,6 +229,23 @@ class OutputPlugin(OutputPluginBase):
'docker_network': dict(
default='BRIDGE',
),
'networks': dict(
type='list',
description='List of networks. This param overrides the "docker_network" param',
subtype='dict',
fields=dict(
name=dict(
type='str',
),
mode=dict(
type='str',
required=True,
),
labels=dict(
type='dict',
),
),
),
'docker_privileged': dict(
type='bool',
default=False,
Expand Down Expand Up @@ -311,7 +328,6 @@ def generate_output(self, app_vars):
# TODO: make various attributes configurable
"docker": {
"image": app_vars['APP']['image'],
"network": app_vars['APP']['docker_network'],
"privileged": app_vars['APP']['docker_privileged'],
"parameters": app_vars['APP']['docker_parameters'],
"forcePullImage": True
Expand All @@ -326,6 +342,8 @@ def generate_output(self, app_vars):
self.build_port_definitions(app_vars, data)
# Container labels
self.build_container_labels(app_vars, data)
# Networks
self.build_networks(app_vars, data)
# Volumes
self.build_volumes(app_vars, data)
# Environment
Expand Down Expand Up @@ -374,6 +392,25 @@ def build_secrets(self, app_vars, data):
if secrets:
data['secrets'] = secrets

def build_networks(self, app_vars, data):
networks = []
# The 'networks' param overrides the 'docker_network' param, so look for it first
if app_vars['APP']['networks']:
for net in app_vars['APP']['networks']:
networks.append(net)
else:
# Translate 'docker_network' value to new-style network
tmp_network = {}
if app_vars['APP']['docker_network'].lower() == 'bridge':
tmp_network['mode'] = 'container/bridge'
elif app_vars['APP']['docker_network'].lower() == 'host':
tmp_network['mode'] = 'host'
else:
# TODO: do something meaningful for unknown network mode
pass
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe just fail, instead? Or simply return whatever was given.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A value that's valid for container.docker.network isn't valid for networks.mode (which is why there's a translation), and adding a failure here can open a bigger can of worms (specifying valid values for parameters).

networks.append(tmp_network)
data['networks'] = networks

def build_volumes(self, app_vars, data):
if app_vars['APP']['volumes']:
volumes = []
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -55,7 +55,7 @@ def run(self):

setup(
name='deploy-config-generator',
version='1.1.0',
version='1.2.0',
url='https://github.com/ApplauseOSS/deploy-config-generator',
license='MIT',
description='Utility to generate service deploy configurations',
Expand Down
8 changes: 6 additions & 2 deletions tests/integration/kongfig/expected_output/marathon-001.json
Expand Up @@ -3,7 +3,6 @@
"docker": {
"forcePullImage": true,
"image": "foo/bar",
"network": "BRIDGE",
"parameters": [],
"privileged": false
},
Expand All @@ -14,5 +13,10 @@
"disk": 10,
"id": "some/service",
"instances": 1,
"mem": 1024.0
"mem": 1024.0,
"networks": [
{
"mode": "container/bridge"
}
]
}
Expand Up @@ -7,7 +7,6 @@
"docker": {
"forcePullImage": true,
"image": "1234567890.dkr.ecr.us-east-1.amazonaws.com/some_service",
"network": "BRIDGE",
"parameters": [],
"privileged": false
},
Expand All @@ -23,5 +22,10 @@
"extra": "not to\n be trimmed\n",
"foo": "bar"
},
"mem": 1024.0
"mem": 1024.0,
"networks": [
{
"mode": "container/bridge"
}
]
}
Expand Up @@ -7,7 +7,6 @@
"docker": {
"forcePullImage": true,
"image": "1234567890.dkr.ecr.us-east-1.amazonaws.com/some_service",
"network": "BRIDGE",
"parameters": [],
"privileged": false
},
Expand All @@ -23,5 +22,10 @@
"extra": "not to\n be trimmed\n",
"foo": "bar"
},
"mem": 1024.0
"mem": 1024.0,
"networks": [
{
"mode": "container/bridge"
}
]
}
Expand Up @@ -3,7 +3,6 @@
"docker": {
"forcePullImage": true,
"image": "foo/bar",
"network": "BRIDGE",
"parameters": [],
"privileged": false
},
Expand All @@ -14,5 +13,10 @@
"disk": 10,
"id": "some/service",
"instances": 1,
"mem": 1024.0
"mem": 1024.0,
"networks": [
{
"mode": "container/bridge"
}
]
}