12
12
// permissions and limitations under the License.
13
13
14
14
/*
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.
28
28
*/
29
29
package vmconf
30
30
@@ -62,7 +62,7 @@ type StaticNetworkConf struct {
62
62
VMMTU int
63
63
// VMIPConfig is the ip configuration that callers should configure their VM's internal
64
64
// primary interface to use.
65
- VMIPConfig * current.IPConfig
65
+ VMIPConfig [] * current.IPConfig
66
66
// VMRoutes are the routes that callers should configure their VM's internal route table
67
67
// to have
68
68
VMRoutes []* types.Route
@@ -88,32 +88,32 @@ type StaticNetworkConf struct {
88
88
//
89
89
// Due to the limitation of "ip=", not all configuration specified in StaticNetworkConf can be
90
90
// 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.
98
98
func (c StaticNetworkConf ) IPBootParam () string {
99
99
// See "ip=" section of kernel linked above for details on each field listed below.
100
100
101
101
// 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 ()
103
103
104
104
// don't set nfs server IP
105
105
const serverIP = ""
106
106
107
107
// 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 ()
109
109
110
110
// subnet mask used to generate a corresponding route table entry for the primary interface
111
111
// (must be provided in dotted decimal notation)
112
112
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 ],
117
117
)
118
118
119
119
// 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
168
168
169
169
// find the IP associated with the VM iface
170
170
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 ]
176
171
177
172
netNS , err := ns .GetNS (tapIface .Sandbox )
178
173
if err != nil {
@@ -189,7 +184,7 @@ func StaticNetworkConfFrom(result types.Result, containerID string) (*StaticNetw
189
184
NetNSPath : tapIface .Sandbox ,
190
185
VMMacAddr : vmIface .Mac ,
191
186
VMMTU : tapMTU ,
192
- VMIPConfig : vmIP ,
187
+ VMIPConfig : vmIPs ,
193
188
VMRoutes : currentResult .Routes ,
194
189
VMNameservers : currentResult .DNS .Nameservers ,
195
190
VMDomain : currentResult .DNS .Domain ,
0 commit comments