Skip to content

Commit

Permalink
ipam/allocator: Fix nil check on node CIDR
Browse files Browse the repository at this point in the history
[ upstream commit 8c5c737 ]

Previously, the nil check was useless because the variable is never
going to be nil, as it was initialized to an empty `nodeCIDRs` instance.
This made the "Unable to allocate node CIDR" error impossible to
surface.

This commit fixes this by making the variable not a pointer, but rather
a value, and reworking the further checks to ensure that the error in
allocating a node CIDR can be surfaced.

Fixes: ef6ecbd ("add error log When ipam allocate nodecidr failure")
Fixes: #13299

Signed-off-by: Chris Tarazi <chris@isovalent.com>
Signed-off-by: Tom Payne <tom@isovalent.com>
  • Loading branch information
christarazi authored and twpayne committed Nov 13, 2020
1 parent 96a074d commit 4d622e5
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions pkg/ipam/allocator/podcidr/podcidr.go
Original file line number Diff line number Diff line change
Expand Up @@ -849,42 +849,46 @@ func (n *NodesPodCIDRManager) allocateNext(nodeName string) (*nodeCIDRs, bool, e
}
}()

var v4CIDR, v6CIDR *net.IPNet

nCIDRs := &nodeCIDRs{}
var (
cidrs nodeCIDRs
v4CIDR, v6CIDR *net.IPNet
)

// Only allocate a v4 CIDR if the v4CIDR allocator is available
if len(n.v4CIDRAllocators) != 0 {
revertFunc, v4CIDR, err = allocateFirstFreeCIDR(n.v4CIDRAllocators)
if err != nil {
return nil, false, err
}

log.WithField("CIDR", v4CIDR).Debug("v4 allocated CIDR")
cidrs.v4PodCIDRs = []*net.IPNet{v4CIDR}

revertStack.Push(revertFunc)
log.Debug("v4CIDR", v4CIDR)
nCIDRs.v4PodCIDRs = []*net.IPNet{v4CIDR}
}
if len(n.v6CIDRAllocators) != 0 {
revertFunc, v6CIDR, err = allocateFirstFreeCIDR(n.v6CIDRAllocators)
if err != nil {
return nil, false, err
}

log.WithField("CIDR", v6CIDR).Debug("v6 allocated CIDR")
cidrs.v6PodCIDRs = []*net.IPNet{v6CIDR}

revertStack.Push(revertFunc)
log.Debug("v6CIDR", v6CIDR)
nCIDRs.v6PodCIDRs = []*net.IPNet{v6CIDR}
}

if nCIDRs == nil {
if cidrs.v4PodCIDRs == nil && cidrs.v6PodCIDRs == nil {
return nil, false, ErrNoAllocators{
name: nodeName,
v4: getCIDRAllocatorsInfo(n.v4CIDRAllocators, v4AllocatorType),
v6: getCIDRAllocatorsInfo(n.v6CIDRAllocators, v6AllocatorType),
}
}

n.nodes[nodeName] = nCIDRs

return nCIDRs, true, nil
n.nodes[nodeName] = &cidrs

return &cidrs, true, nil
}

func getCIDRAllocatorsInfo(cidrAllocators []CIDRAllocator, netTypes string) string {
Expand Down

0 comments on commit 4d622e5

Please sign in to comment.