1212// permissions and limitations under the License. 
1313
1414/* 
15-   Package vmconf defines an interface for converting particular CNI invocation
16-   results to networking configuration usable by a VM. It expects the CNI result
17-   to have the following properties:
18-  *  The results should contain an interface for a tap device, which will be used 
19-    as the VM's tap device. 
20-  *  The results should contain an interface with the same name as the tap device 
21-    but with sandbox ID set to the containerID provided during CNI invocation. 
22-    This should be a "pseudo-interface", not one that has actually been created. 
23-    It represents the configuration that should be applied to the VM internally. 
24-    The CNI "containerID" is, in this case, used more as a "vmID" to represent 
25-    the VM's internal network interface. 
26-      *  If the CNI results specify an IP associated with this interface, that IP 
27-         should be used to statically configure the VM's internal network interface. 
15+ Package vmconf defines an interface for converting particular CNI invocation 
16+ results to networking configuration usable by a VM. It expects the CNI result 
17+ to have the following properties: 
18+   -  The results should contain an interface for a tap device, which will be used 
19+      as the VM's tap device. 
20+   -  The results should contain an interface with the same name as the tap device 
21+      but with sandbox ID set to the containerID provided during CNI invocation. 
22+      This should be a "pseudo-interface", not one that has actually been created. 
23+      It represents the configuration that should be applied to the VM internally. 
24+      The CNI "containerID" is, in this case, used more as a "vmID" to represent 
25+      the VM's internal network interface. 
26+   -  If the CNI results specify an IP associated with this interface, that IP 
27+     should be used to statically configure the VM's internal network interface. 
2828*/ 
2929package  vmconf
3030
@@ -62,7 +62,7 @@ type StaticNetworkConf struct {
6262	VMMTU  int 
6363	// VMIPConfig is the ip configuration that callers should configure their VM's internal 
6464	// primary interface to use. 
65- 	VMIPConfig  * current.IPConfig 
65+ 	VMIPConfig  [] * current.IPConfig 
6666	// VMRoutes are the routes that callers should configure their VM's internal route table 
6767	// to have 
6868	VMRoutes  []* types.Route 
@@ -88,32 +88,32 @@ type StaticNetworkConf struct {
8888// 
8989// Due to the limitation of "ip=", not all configuration specified in StaticNetworkConf can be 
9090// applied automatically. In particular: 
91- // *  The MacAddr and MTU cannot be applied 
92- // *  The only routes created will match what's specified in VMIPConfig; VMRoutes will be ignored. 
93- // *  Only up to two namesevers can be supplied. If VMNameservers is has more than 2 entries, only 
94- //   the first two in the slice will be applied in the VM. 
95- // *  VMDomain, VMSearchDomains and VMResolverOptions will be ignored 
96- // *  Nameserver settings are also only set in /proc/net/pnp. Most applications will thus require 
97- //   /etc/resolv.conf to be a symlink to /proc/net/pnp in order to resolve names as expected. 
91+ //   -  The MacAddr and MTU cannot be applied 
92+ //   -  The only routes created will match what's specified in VMIPConfig; VMRoutes will be ignored. 
93+ //   -  Only up to two namesevers can be supplied. If VMNameservers is has more than 2 entries, only 
94+ //      the first two in the slice will be applied in the VM. 
95+ //   -  VMDomain, VMSearchDomains and VMResolverOptions will be ignored 
96+ //   -  Nameserver settings are also only set in /proc/net/pnp. Most applications will thus require 
97+ //      /etc/resolv.conf to be a symlink to /proc/net/pnp in order to resolve names as expected. 
9898func  (c  StaticNetworkConf ) IPBootParam () string  {
9999	// See "ip=" section of kernel linked above for details on each field listed below. 
100100
101101	// client-ip is really just the ip that will be assigned to the primary interface 
102- 	clientIP  :=  c .VMIPConfig .Address .IP .String ()
102+ 	clientIP  :=  c .VMIPConfig [ 0 ] .Address .IP .String ()
103103
104104	// don't set nfs server IP 
105105	const  serverIP  =  "" 
106106
107107	// default gateway for the network; used to generate a corresponding route table entry 
108- 	defaultGateway  :=  c .VMIPConfig .Gateway .String ()
108+ 	defaultGateway  :=  c .VMIPConfig [ 0 ] .Gateway .String ()
109109
110110	// subnet mask used to generate a corresponding route table entry for the primary interface 
111111	// (must be provided in dotted decimal notation) 
112112	subnetMask  :=  fmt .Sprintf ("%d.%d.%d.%d" ,
113- 		c .VMIPConfig .Address .Mask [0 ],
114- 		c .VMIPConfig .Address .Mask [1 ],
115- 		c .VMIPConfig .Address .Mask [2 ],
116- 		c .VMIPConfig .Address .Mask [3 ],
113+ 		c .VMIPConfig [ 0 ] .Address .Mask [0 ],
114+ 		c .VMIPConfig [ 0 ] .Address .Mask [1 ],
115+ 		c .VMIPConfig [ 0 ] .Address .Mask [2 ],
116+ 		c .VMIPConfig [ 0 ] .Address .Mask [3 ],
117117	)
118118
119119	// the "hostname" field actually just configures a hostname value for DHCP requests, thus no need to set it 
@@ -168,11 +168,6 @@ func StaticNetworkConfFrom(result types.Result, containerID string) (*StaticNetw
168168
169169	// find the IP associated with the VM iface 
170170	vmIPs  :=  internal .InterfaceIPs (currentResult , vmIface .Name , vmIface .Sandbox )
171- 	if  len (vmIPs ) !=  1  {
172- 		return  nil , fmt .Errorf ("expected to find 1 IP for vm interface %q, but instead found %+v" ,
173- 			vmIface .Name , vmIPs )
174- 	}
175- 	vmIP  :=  vmIPs [0 ]
176171
177172	netNS , err  :=  ns .GetNS (tapIface .Sandbox )
178173	if  err  !=  nil  {
@@ -189,7 +184,7 @@ func StaticNetworkConfFrom(result types.Result, containerID string) (*StaticNetw
189184		NetNSPath :         tapIface .Sandbox ,
190185		VMMacAddr :         vmIface .Mac ,
191186		VMMTU :             tapMTU ,
192- 		VMIPConfig :        vmIP ,
187+ 		VMIPConfig :        vmIPs ,
193188		VMRoutes :          currentResult .Routes ,
194189		VMNameservers :     currentResult .DNS .Nameservers ,
195190		VMDomain :          currentResult .DNS .Domain ,
0 commit comments