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

View File

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