mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2025-01-20 03:36:41 +00:00
Merge pull request #1092 from balena-io/fix-network-handling
Correctly handle partial IPAM configurations for networks
This commit is contained in:
commit
b94dbb1ec4
@ -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 || {},
|
||||||
|
@ -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', ->
|
||||||
|
Loading…
Reference in New Issue
Block a user