Skip to content

Commit 6451143

Browse files
committed
remove restrictions on null driver
1 parent 1ba8194 commit 6451143

File tree

2 files changed

+43
-18
lines changed

2 files changed

+43
-18
lines changed

ipams/null/null.go

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,24 @@ func (a *allocator) GetDefaultAddressSpaces() (string, string, error) {
2424
}
2525

2626
func (a *allocator) RequestPool(addressSpace, pool, subPool string, options map[string]string, v6 bool) (string, *net.IPNet, map[string]string, error) {
27-
if addressSpace != defaultAS {
28-
return "", nil, nil, types.BadRequestErrorf("unknown address space: %s", addressSpace)
27+
if addressSpace == "" {
28+
addressSpace = defaultAS
2929
}
30-
if pool != "" {
31-
return "", nil, nil, types.BadRequestErrorf("null ipam driver does not handle specific address pool requests")
32-
}
33-
if subPool != "" {
34-
return "", nil, nil, types.BadRequestErrorf("null ipam driver does not handle specific address subpool requests")
30+
31+
if pool == "" && subPool != "" {
32+
return "", nil, nil, fmt.Errorf("subpool requires a pool to be configured")
3533
}
36-
if v6 {
37-
return "", nil, nil, types.BadRequestErrorf("null ipam driver does not handle IPv6 address pool pool requests")
34+
35+
retPool := defaultPool
36+
if pool != "" {
37+
var err error
38+
retPool, err = types.ParseCIDR(pool)
39+
if err != nil {
40+
return "", nil, nil, err
41+
}
3842
}
39-
return defaultPoolID, defaultPool, nil, nil
43+
retPoolID := fmt.Sprintf("%s/%s", addressSpace, retPool.String())
44+
return retPoolID, retPool, nil, nil
4045
}
4146

4247
func (a *allocator) ReleasePool(poolID string) error {

ipams/null/null_test.go

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,44 @@ func TestPoolRequest(t *testing.T) {
2121
t.Fatalf("Unexpected pool id returned. Expected: %s. Got: %s", defaultPoolID, pid)
2222
}
2323

24-
_, _, _, err = a.RequestPool("default", "", "", nil, false)
25-
if err == nil {
26-
t.Fatal("Unexpected success")
24+
id, _, _, err := a.RequestPool("foo", "", "", nil, false)
25+
if err != nil {
26+
t.Fatal("Unexpected error")
27+
}
28+
if id != "foo/0.0.0.0/0" {
29+
t.Fatal("Wrong id")
2730
}
2831

29-
_, _, _, err = a.RequestPool(defaultAS, "192.168.0.0/16", "", nil, false)
30-
if err == nil {
31-
t.Fatal("Unexpected success")
32+
id, p, _, err := a.RequestPool(defaultAS, "192.168.0.0/16", "", nil, false)
33+
if err != nil {
34+
t.Fatal("Unexpected error")
35+
}
36+
if id != defaultAS+"/192.168.0.0/16" {
37+
t.Fatalf("Wrong id")
38+
}
39+
if p.String() != "192.168.0.0/16" {
40+
t.Fatalf("Wrong pool")
3241
}
3342

3443
_, _, _, err = a.RequestPool(defaultAS, "", "192.168.0.0/24", nil, false)
3544
if err == nil {
3645
t.Fatal("Unexpected success")
3746
}
3847

48+
id, p, _, err = a.RequestPool(defaultAS, "192.168.0.0/16", "192.168.0.0/24", nil, false)
49+
if err != nil {
50+
t.Fatal("Unexpected error")
51+
}
52+
if id != defaultAS+"/192.168.0.0/16" {
53+
t.Fatalf("Wrong id")
54+
}
55+
if p.String() != "192.168.0.0/16" {
56+
t.Fatalf("Wrong pool")
57+
}
58+
3959
_, _, _, err = a.RequestPool(defaultAS, "", "", nil, true)
40-
if err == nil {
41-
t.Fatal("Unexpected success")
60+
if err != nil {
61+
t.Fatal("Unexpected error")
4262
}
4363
}
4464

0 commit comments

Comments
 (0)