fix: Correctly type top level network IPAM config

Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
This commit is contained in:
Cameron Diver 2018-12-19 17:43:04 +00:00
parent 2d014d2a5d
commit 9fab0fc5cc
No known key found for this signature in database
GPG Key ID: 49690ED87032539F
2 changed files with 19 additions and 12 deletions

View File

@ -63,17 +63,21 @@ export class Network {
ipam: { ipam: {
driver: network.IPAM.Driver, driver: network.IPAM.Driver,
config: _.map(network.IPAM.Config, conf => { config: _.map(network.IPAM.Config, conf => {
const newConf: NetworkConfig['ipam']['config'][0] = { const newConf: NetworkConfig['ipam']['config'][0] = {};
subnet: conf.Subnet,
gateway: conf.Gateway,
};
if (conf.Subnet != null) {
newConf.subnet = conf.Subnet;
}
if (conf.Gateway != null) {
newConf.gateway = conf.Gateway;
}
if (conf.IPRange != null) { if (conf.IPRange != null) {
newConf.ipRange = conf.IPRange; newConf.ipRange = conf.IPRange;
} }
if (conf.AuxAddress != null) { if (conf.AuxAddress != null) {
newConf.auxAddress = conf.AuxAddress; newConf.auxAddress = conf.AuxAddress;
} }
return newConf; return newConf;
}), }),
options: network.IPAM.Options == null ? {} : network.IPAM.Options, options: network.IPAM.Options == null ? {} : network.IPAM.Options,
@ -162,10 +166,13 @@ export class Network {
IPAM: { IPAM: {
Driver: this.config.ipam.driver, Driver: this.config.ipam.driver,
Config: _.map(this.config.ipam.config, conf => { Config: _.map(this.config.ipam.config, conf => {
const ipamConf: DockerIPAMConfig = { const ipamConf: DockerIPAMConfig = {};
Subnet: conf.subnet, if (conf.subnet != null) {
Gateway: conf.gateway, ipamConf.Subnet = conf.subnet;
}; }
if (conf.gateway != null) {
ipamConf.Gateway = conf.gateway;
}
if (conf.auxAddress != null) { if (conf.auxAddress != null) {
ipamConf.AuxAddress = conf.auxAddress; ipamConf.AuxAddress = conf.auxAddress;
} }

View File

@ -39,8 +39,8 @@ export interface NetworkConfig {
ipam: { ipam: {
driver: string; driver: string;
config: Array<{ config: Array<{
subnet: string; subnet?: string;
gateway: string; gateway?: string;
ipRange?: string; ipRange?: string;
auxAddress?: string; auxAddress?: string;
}>; }>;
@ -53,9 +53,9 @@ export interface NetworkConfig {
} }
export interface DockerIPAMConfig { export interface DockerIPAMConfig {
Subnet: string; Subnet?: string;
IPRange?: string; IPRange?: string;
Gateway: string; Gateway?: string;
AuxAddress?: string; AuxAddress?: string;
} }