Skip to content

Commit d68c75c

Browse files
authored
log what ips we got and make defer pickup when no ips are found (#720)
* log what ips we got and make defer pickup when no ips are found * fix typos * differentiate success from failure
1 parent c856bc1 commit d68c75c

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

go.mod

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ require (
2222
github.com/petar/GoLLRB v0.0.0-20190514000832-33fb24c13b99 // indirect
2323
github.com/prometheus/client_golang v1.0.0
2424
github.com/prometheus/client_model v0.2.0
25-
github.com/satori/go.uuid v1.2.0 // indirect
2625
github.com/spf13/cobra v0.0.5
2726
github.com/spf13/pflag v1.0.5
2827
github.com/spf13/viper v1.3.2
@@ -32,7 +31,6 @@ require (
3231
golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e
3332
golang.org/x/time v0.0.0-20191024005414-555d28b269f0 // indirect
3433
google.golang.org/appengine v1.6.5 // indirect
35-
gopkg.in/fsnotify.v1 v1.4.7 // indirect
3634
k8s.io/api v0.18.2
3735
k8s.io/apimachinery v0.18.2
3836
k8s.io/client-go v0.18.2

ipam/azure.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ func (s *azureSource) refresh() error {
158158
continue
159159
}
160160

161+
addressCount := 0
161162
// For each address in the subnet...
162163
for _, a := range s.IPAddress {
163164
// Primary addresses are reserved for the host.
@@ -172,7 +173,9 @@ func (s *azureSource) refresh() error {
172173
log.Printf("[ipam] Failed to create address:%v err:%v.", address, err)
173174
continue
174175
}
176+
addressCount++
175177
}
178+
log.Printf("[ipam] got %d addresses from interface %s, subnet %s", addressCount, ifName, subnet)
176179
}
177180
}
178181

ipam/pool.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -474,24 +474,22 @@ func (ap *addressPool) newAddressRecord(addr *net.IP) (*addressRecord, error) {
474474
func (ap *addressPool) requestAddress(address string, options map[string]string) (string, error) {
475475
var ar *addressRecord
476476
var addr *net.IPNet
477-
var err error
478477
id := options[OptAddressID]
479478

480479
log.Printf("[ipam] Requesting address with address:%v options:%+v.", address, options)
481-
defer func() { log.Printf("[ipam] Address request completed with address:%v err:%v.", addr, err) }()
482480

483481
if address != "" {
484482
// Return the specific address requested.
485483
ar = ap.Addresses[address]
486484
if ar == nil {
487-
err = errAddressNotFound
488-
return "", err
485+
log.Printf("[ipam] Address request failed with %v", errAddressNotFound)
486+
return "", errAddressNotFound
489487
}
490488
if ar.InUse {
491489
// Return the same address if IDs match.
492490
if id == "" || id != ar.ID {
493-
err = errAddressInUse
494-
return "", err
491+
log.Printf("[ipam] Address request failed with %v", errAddressInUse)
492+
return "", errAddressInUse
495493
}
496494
}
497495
} else if options[OptAddressType] == OptAddressTypeGateway {
@@ -515,6 +513,7 @@ func (ap *addressPool) requestAddress(address string, options map[string]string)
515513
}
516514

517515
if ar == nil {
516+
log.Printf("[ipam] Address request failed with %v", errNoAvailableAddresses)
518517
return "", errNoAvailableAddresses
519518
}
520519
}
@@ -532,6 +531,8 @@ func (ap *addressPool) requestAddress(address string, options map[string]string)
532531
Mask: ap.Subnet.Mask,
533532
}
534533

534+
log.Printf("[ipam] Address request completed with address:%v", addr)
535+
535536
return addr.String(), nil
536537
}
537538

0 commit comments

Comments
 (0)