Correctly handle partial IPAM configurations for networks

Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
This commit is contained in:
Cameron Diver 2019-09-16 10:52:18 +01:00
parent bae78386a8
commit e78f8eccdc
No known key found for this signature in database
GPG Key ID: 49690ED87032539F
2 changed files with 35 additions and 9 deletions

View File

@ -103,14 +103,10 @@ export class Network {
Network.validateComposeConfig(network);
const ipam =
network.ipam != null
? network.ipam
: {
driver: 'default',
config: [],
options: {},
};
const ipam: Partial<ComposeNetworkConfig['ipam']> = network.ipam || {};
if (ipam.driver == null) {
ipam.driver = 'default';
}
if (ipam.config == null) {
ipam.config = [];
}
@ -119,7 +115,7 @@ export class Network {
}
net.config = {
driver: network.driver || 'bridge',
ipam,
ipam: ipam as ComposeNetworkConfig['ipam'],
enableIPv6: network.enable_ipv6 || false,
internal: network.internal || false,
labels: network.labels || {},

View File

@ -37,6 +37,36 @@ describe 'compose/network', ->
options: {}
})
it 'should handle an incomplete ipam configuration', ->
network = Network.fromComposeObject('test', 123, {
ipam: {
config: [
{
subnet: '172.25.0.0/25',
gateway: '172.25.0.1'
}
]
}
}, { logger: null, docker: null })
expect(network.config).to.deep.equal({
driver: 'bridge',
enableIPv6: false,
internal: false,
labels: {}
options: {}
ipam: {
driver: 'default',
options: {},
config: [
{
subnet: '172.25.0.0/25',
gateway: '172.25.0.1'
}
]
}
})
describe 'internal config -> docker config', ->
it 'should convert an internal representation to a docker representation', ->