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

aws-node does not perform ip unassignment properly #1344

Closed
wants to merge 3 commits into from
Closed
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
16 changes: 13 additions & 3 deletions pkg/ipamd/datastore/data_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,18 @@ type IPAMKey struct {
IfName string `json:"ifName"`
}

// IsZero returns true iff object is equal to the golang zero/null value.
// IsZero returns true if object is equal to the golang zero/null value.
func (k IPAMKey) IsZero() bool {
return k == IPAMKey{}
}

// NoContainer returns true if IPAMKey exists but there is not ContainerID associated
// Eventually it should be processed by tryUnassignIPsFromAll in ipamd.go
// Which will decrease DS usage counter
func (k IPAMKey) NoContainer() bool {
return k.ContainerID == ""
}

// String() implements the fmt.Stringer interface.
func (k IPAMKey) String() string {
return fmt.Sprintf("%s/%s/%s", k.NetworkName, k.ContainerID, k.IfName)
Expand Down Expand Up @@ -178,9 +185,12 @@ func (e *ENI) AssignedIPv4Addresses() int {
return count
}

// Assigned returns true iff the address is allocated to a pod/sandbox.
// Assigned returns true if the address is allocated to a pod/sandbox.
func (addr AddressInfo) Assigned() bool {
return !addr.IPAMKey.IsZero()
if addr.IPAMKey.IsZero() {
return false
}
return !addr.IPAMKey.NoContainer()
}

// InCoolingPeriod checks whether an addr is in addressCoolingPeriod
Expand Down
7 changes: 6 additions & 1 deletion pkg/ipamd/datastore/data_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,18 +300,23 @@ func TestPodIPv4Address(t *testing.T) {
key4 := IPAMKey{"net0", "sandbox-4", "eth0"}
_, _, err = ds.AssignPodIPv4Address(key4)
assert.Error(t, err)

// Unassign unknown Pod
_, _, err = ds.UnassignPodIPv4Address(key4)
assert.Error(t, err)

// IPAddress not associated with any container should be considered freeable
ds.eniPool["eni-1"].IPv4Addresses["1.1.1.2"].IPAMKey.ContainerID = ""
assert.Equal(t, ds.eniPool["eni-1"].AssignedIPv4Addresses(), 1)

_, deviceNum, err := ds.UnassignPodIPv4Address(key2)
assert.NoError(t, err)
assert.Equal(t, ds.total, 3)
assert.Equal(t, ds.assigned, 2)
assert.Equal(t, deviceNum, pod1Ns2Device)
assert.Equal(t, len(ds.eniPool["eni-2"].IPv4Addresses), 1)
assert.Equal(t, ds.eniPool["eni-2"].AssignedIPv4Addresses(), 0)
assert.Equal(t, len(checkpoint.Data.(*CheckpointData).Allocations), 2)
assert.Equal(t, len(checkpoint.Data.(*CheckpointData).Allocations), 1)

noWarmIPTarget := 0
noMinimumIPTarget := 0
Expand Down