Skip to content

Commit

Permalink
Merge pull request #1130 from caseydavenport/automated-cherry-pick-of…
Browse files Browse the repository at this point in the history
…-#1129-origin-release-v3.9

Automated cherry pick of #1129: Ignore Windows reserved addresses
  • Loading branch information
caseydavenport committed Sep 18, 2019
2 parents 18c0a7f + 61a622e commit 5129d8f
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion lib/ipam/ipam_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ import (
cnet "github.com/projectcalico/libcalico-go/lib/net"
)

// windwowsReservedHandle is the handle used to reserve addresses required for Windows
// networking so that workloads do not get assigned these addresses.
const windowsReservedHandle = "windows-reserved-IPAM-handle"

// Wrap the backend AllocationBlock struct so that we can
// attach methods to it.
type allocationBlock struct {
Expand Down Expand Up @@ -145,8 +149,25 @@ func (b allocationBlock) numFreeAddresses() int {
return len(b.Unallocated)
}

// empty returns true if the block has released all of its assignable addresses,
// and returns false if any assignable addresses are in use.
func (b allocationBlock) empty() bool {
return b.numFreeAddresses() == b.NumAddresses()
return b.containsOnlyReservedIPs()
}

// containsOnlyReservedIPs returns true if the block is empty excepted for
// expected "reserved" IP addresses.
func (b *allocationBlock) containsOnlyReservedIPs() bool {
for _, attrIdx := range b.Allocations {
if attrIdx == nil {
continue
}
attrs := b.Attributes[*attrIdx]
if attrs.AttrPrimary == nil || *attrs.AttrPrimary != windowsReservedHandle {
return false
}
}
return true
}

func (b *allocationBlock) release(addresses []cnet.IP) ([]cnet.IP, map[string]int, error) {
Expand Down

0 comments on commit 5129d8f

Please sign in to comment.