Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove restrictions on null ipam driver #2078

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions ipams/null/null.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,24 @@ func (a *allocator) GetDefaultAddressSpaces() (string, string, error) {
}

func (a *allocator) RequestPool(addressSpace, pool, subPool string, options map[string]string, v6 bool) (string, *net.IPNet, map[string]string, error) {
if addressSpace != defaultAS {
return "", nil, nil, types.BadRequestErrorf("unknown address space: %s", addressSpace)
if addressSpace == "" {
addressSpace = defaultAS
}
if pool != "" {
return "", nil, nil, types.BadRequestErrorf("null ipam driver does not handle specific address pool requests")
}
if subPool != "" {
return "", nil, nil, types.BadRequestErrorf("null ipam driver does not handle specific address subpool requests")

if pool == "" && subPool != "" {
return "", nil, nil, fmt.Errorf("subpool requires a pool to be configured")
}
if v6 {
return "", nil, nil, types.BadRequestErrorf("null ipam driver does not handle IPv6 address pool pool requests")

retPool := defaultPool
if pool != "" {
var err error
retPool, err = types.ParseCIDR(pool)
if err != nil {
return "", nil, nil, err
}
}
return defaultPoolID, defaultPool, nil, nil
retPoolID := fmt.Sprintf("%s/%s", addressSpace, retPool.String())
return retPoolID, retPool, nil, nil
}

func (a *allocator) ReleasePool(poolID string) error {
Expand Down
36 changes: 28 additions & 8 deletions ipams/null/null_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,44 @@ func TestPoolRequest(t *testing.T) {
t.Fatalf("Unexpected pool id returned. Expected: %s. Got: %s", defaultPoolID, pid)
}

_, _, _, err = a.RequestPool("default", "", "", nil, false)
if err == nil {
t.Fatal("Unexpected success")
id, _, _, err := a.RequestPool("foo", "", "", nil, false)
if err != nil {
t.Fatal("Unexpected error")
}
if id != "foo/0.0.0.0/0" {
t.Fatal("Wrong id")
}

_, _, _, err = a.RequestPool(defaultAS, "192.168.0.0/16", "", nil, false)
if err == nil {
t.Fatal("Unexpected success")
id, p, _, err := a.RequestPool(defaultAS, "192.168.0.0/16", "", nil, false)
if err != nil {
t.Fatal("Unexpected error")
}
if id != defaultAS+"/192.168.0.0/16" {
t.Fatalf("Wrong id")
}
if p.String() != "192.168.0.0/16" {
t.Fatalf("Wrong pool")
}

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

id, p, _, err = a.RequestPool(defaultAS, "192.168.0.0/16", "192.168.0.0/24", nil, false)
if err != nil {
t.Fatal("Unexpected error")
}
if id != defaultAS+"/192.168.0.0/16" {
t.Fatalf("Wrong id")
}
if p.String() != "192.168.0.0/16" {
t.Fatalf("Wrong pool")
}

_, _, _, err = a.RequestPool(defaultAS, "", "", nil, true)
if err == nil {
t.Fatal("Unexpected success")
if err != nil {
t.Fatal("Unexpected error")
}
}

Expand Down