Skip to content

Commit 7c24e65

Browse files
committed
wip
1 parent 107e282 commit 7c24e65

File tree

3 files changed

+85
-5
lines changed

3 files changed

+85
-5
lines changed

cmd/nerdctl/network/network_create_linux_test.go

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,83 @@ func TestNetworkCreate(t *testing.T) {
156156
}
157157
},
158158
},
159+
{
160+
Description: "with static IPv4 address",
161+
Setup: func(data test.Data, helpers test.Helpers) {
162+
networkName := data.Identifier()
163+
staticIP := "172.19.0.100"
164+
data.Labels().Set("networkName", networkName)
165+
data.Labels().Set("staticIP", staticIP)
166+
helpers.Ensure("network", "create", networkName, "--driver", "bridge", "--subnet", "172.19.0.0/24")
167+
},
168+
Cleanup: func(data test.Data, helpers test.Helpers) {
169+
helpers.Anyhow("network", "rm", data.Labels().Get("networkName"))
170+
},
171+
Command: func(data test.Data, helpers test.Helpers) test.TestableCommand {
172+
return helpers.Command("run", "--rm", "--net", data.Labels().Get("networkName"), "--ip", data.Labels().Get("staticIP"), testutil.CommonImage, "ip", "addr", "show", "eth0")
173+
},
174+
Expected: func(data test.Data, helpers test.Helpers) *test.Expected {
175+
return &test.Expected{
176+
ExitCode: 0,
177+
Output: func(stdout string, t tig.T) {
178+
assert.Assert(t, strings.Contains(stdout, fmt.Sprintf("inet %s/24", data.Labels().Get("staticIP"))))
179+
},
180+
}
181+
},
182+
},
183+
{
184+
Description: "with static IPv6 address",
185+
Require: nerdtest.OnlyIPv6,
186+
Setup: func(data test.Data, helpers test.Helpers) {
187+
networkName := data.Identifier()
188+
staticIPv6 := "2001:db8:1::100"
189+
data.Labels().Set("networkName", networkName)
190+
data.Labels().Set("staticIPv6", staticIPv6)
191+
helpers.Ensure("network", "create", networkName, "--driver", "bridge", "--ipv6", "--subnet", "2001:db8:1::/64")
192+
},
193+
Cleanup: func(data test.Data, helpers test.Helpers) {
194+
helpers.Anyhow("network", "rm", data.Labels().Get("networkName"))
195+
},
196+
Command: func(data test.Data, helpers test.Helpers) test.TestableCommand {
197+
return helpers.Command("run", "--rm", "--net", data.Labels().Get("networkName"), "--ip", data.Labels().Get("staticIPv6"), testutil.CommonImage, "ip", "addr", "show", "eth0")
198+
},
199+
Expected: func(data test.Data, helpers test.Helpers) *test.Expected {
200+
return &test.Expected{
201+
ExitCode: 0,
202+
Output: func(stdout string, t tig.T) {
203+
assert.Assert(t, strings.Contains(stdout, fmt.Sprintf("inet6 %s/64", data.Labels().Get("staticIPv6"))))
204+
},
205+
}
206+
},
207+
},
208+
{
209+
Description: "with dual-stack static IP addresses",
210+
Require: nerdtest.OnlyIPv6,
211+
Setup: func(data test.Data, helpers test.Helpers) {
212+
networkName := data.Identifier()
213+
staticIPv4 := "172.20.0.100"
214+
staticIPv6 := "2001:db8:2::100"
215+
data.Labels().Set("networkName", networkName)
216+
data.Labels().Set("staticIPv4", staticIPv4)
217+
data.Labels().Set("staticIPv6", staticIPv6)
218+
helpers.Ensure("network", "create", networkName, "--driver", "bridge", "--subnet", "172.20.0.0/24", "--ipv6", "--subnet", "2001:db8:2::/64")
219+
},
220+
Cleanup: func(data test.Data, helpers test.Helpers) {
221+
helpers.Anyhow("network", "rm", data.Labels().Get("networkName"))
222+
},
223+
Command: func(data test.Data, helpers test.Helpers) test.TestableCommand {
224+
return helpers.Command("run", "--rm", "--net", data.Labels().Get("networkName"), "--ip", data.Labels().Get("staticIPv4"), "--ip", data.Labels().Get("staticIPv6"), testutil.CommonImage, "ip", "addr", "show", "eth0")
225+
},
226+
Expected: func(data test.Data, helpers test.Helpers) *test.Expected {
227+
return &test.Expected{
228+
ExitCode: 0,
229+
Output: func(stdout string, t tig.T) {
230+
assert.Assert(t, strings.Contains(stdout, fmt.Sprintf("inet %s/24", data.Labels().Get("staticIPv4"))))
231+
assert.Assert(t, strings.Contains(stdout, fmt.Sprintf("inet6 %s/64", data.Labels().Get("staticIPv6"))))
232+
},
233+
}
234+
},
235+
},
159236
}
160237

161238
testCase.Run(t)

pkg/netutil/cni_plugin_unix.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,12 @@ func (*tuningConfig) GetPluginType() string {
136136

137137
// https://github.com/containernetworking/plugins/blob/v1.0.1/plugins/ipam/host-local/backend/allocator/config.go#L47-L56
138138
type hostLocalIPAMConfig struct {
139-
Type string `json:"type"`
140-
Routes []IPAMRoute `json:"routes,omitempty"`
141-
ResolveConf string `json:"resolveConf,omitempty"`
142-
DataDir string `json:"dataDir,omitempty"`
143-
Ranges [][]IPAMRange `json:"ranges,omitempty"`
139+
Type string `json:"type"`
140+
Routes []IPAMRoute `json:"routes,omitempty"`
141+
ResolveConf string `json:"resolveConf,omitempty"`
142+
DataDir string `json:"dataDir,omitempty"`
143+
Ranges [][]IPAMRange `json:"ranges,omitempty"`
144+
Capabilities map[string]bool `json:"capabilities,omitempty"`
144145
}
145146

146147
func newHostLocalIPAMConfig() *hostLocalIPAMConfig {

pkg/netutil/netutil_unix.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ func (e *CNIEnv) generateCNIPlugins(driver string, name string, ipam map[string]
138138
bridge.HairpinMode = true
139139
if ipv6 {
140140
bridge.Capabilities["ips"] = true
141+
// Add "dns" capability to test the hypothesis that it's being implicitly dropped.
142+
bridge.Capabilities["dns"] = true
141143
}
142144

143145
// Determine the appropriate firewall ingress policy based on icc setting

0 commit comments

Comments
 (0)