Merge pull request #1092 from balena-io/fix-network-handling

Correctly handle partial IPAM configurations for networks
This commit is contained in:
CameronDiver 2019-09-16 13:31:35 +01:00 committed by GitHub
commit b94dbb1ec4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 9 deletions

View File

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

View File

@ -37,6 +37,36 @@ describe 'compose/network', ->
options: {} 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', -> describe 'internal config -> docker config', ->
it 'should convert an internal representation to a docker representation', -> it 'should convert an internal representation to a docker representation', ->