Skip to content

Commit 08b07d8

Browse files
ecigar13Keith Nguyen
andauthored
return early if CNI state exist and add some style fixes (#1412)
* style: format issues * style: lint issues * style: lint issues * style: moved to new block Co-authored-by: Keith Nguyen <[email protected]>
1 parent b27fb6c commit 08b07d8

File tree

4 files changed

+21
-18
lines changed

4 files changed

+21
-18
lines changed

cni/network/invoker_azure.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ func (invoker *AzureIPAMInvoker) deleteIpamState() {
102102
return
103103
}
104104

105+
if cniStateExists {
106+
return
107+
}
108+
105109
ipamStateExists, err := platform.CheckIfFileExists(platform.CNIIpamStatePath)
106110
if err != nil {
107111
log.Printf("[cni] Error checking IPAM state exist: %v", err)

ipam/api.go

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,24 @@ import (
99

1010
var (
1111
// Error responses returned by AddressManager.
12-
errInvalidAddressSpace = fmt.Errorf("Invalid address space")
13-
errInvalidPoolId = fmt.Errorf("Invalid address pool")
14-
errInvalidAddress = fmt.Errorf("Invalid address")
15-
errInvalidScope = fmt.Errorf("Invalid scope")
16-
errInvalidConfiguration = fmt.Errorf("Invalid configuration")
17-
errAddressPoolExists = fmt.Errorf("Address pool already exists")
18-
errAddressPoolNotFound = fmt.Errorf("Address pool not found")
19-
errAddressPoolInUse = fmt.Errorf("Address pool already in use")
20-
errAddressPoolNotInUse = fmt.Errorf("Address pool not in use")
21-
ErrNoAvailableAddressPools = fmt.Errorf("No available address pools")
22-
errAddressExists = fmt.Errorf("Address already exists")
23-
errAddressNotFound = fmt.Errorf("Address not found")
24-
errAddressInUse = fmt.Errorf("Address already in use")
25-
errAddressNotInUse = fmt.Errorf("Address not in use")
26-
errNoAvailableAddresses = fmt.Errorf("No available addresses")
12+
errInvalidAddressSpace = fmt.Errorf("Invalid address space")
13+
errInvalidPoolID = fmt.Errorf("Invalid address pool")
14+
errInvalidAddress = fmt.Errorf("Invalid address")
15+
errInvalidScope = fmt.Errorf("Invalid scope")
16+
errInvalidConfiguration = fmt.Errorf("Invalid configuration")
17+
errAddressPoolExists = fmt.Errorf("Address pool already exists")
18+
errAddressPoolNotFound = fmt.Errorf("Address pool not found")
19+
errAddressExists = fmt.Errorf("Address already exists")
20+
errAddressNotFound = fmt.Errorf("Address not found")
21+
errAddressInUse = fmt.Errorf("Address already in use")
22+
errNoAvailableAddresses = fmt.Errorf("No available addresses")
2723

2824
// Options used by AddressManager.
2925
OptInterfaceName = "azure.interface.name"
3026
OptAddressID = "azure.address.id"
3127
OptAddressType = "azure.address.type"
3228
OptAddressTypeGateway = "gateway"
3329
)
30+
31+
// Exportable errors returned by AddressManager
32+
var ErrNoAvailableAddressPools = fmt.Errorf("no available address pools")

ipam/pool.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ func NewAddressPoolIdFromString(s string) (*addressPoolId, error) {
103103

104104
p := strings.Split(s, "|")
105105
if len(p) > 3 {
106-
return nil, errInvalidPoolId
106+
return nil, errInvalidPoolID
107107
}
108108

109109
pid.AsId = p[0]
@@ -282,7 +282,7 @@ func (as *addressSpace) newAddressPool(ifName string, priority int, subnet *net.
282282
func (as *addressSpace) getAddressPool(poolId string) (*addressPool, error) {
283283
ap := as.Pools[poolId]
284284
if ap == nil {
285-
return nil, fmt.Errorf("Pool id %v not found :%v", poolId, errInvalidPoolId)
285+
return nil, fmt.Errorf("Pool id %v not found :%w", poolId, errInvalidPoolID)
286286
}
287287

288288
return ap, nil

store/json.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ type jsonFileStore struct {
3939
// NewJsonFileStore creates a new jsonFileStore object, accessed as a KeyValueStore.
4040
func NewJsonFileStore(fileName string, lockclient processlock.Interface) (KeyValueStore, error) {
4141
if fileName == "" {
42-
return &jsonFileStore{}, errors.New("Need to pass in a json file path")
42+
return &jsonFileStore{}, errors.New("need to pass in a json file path")
4343
}
4444
kvs := &jsonFileStore{
4545
fileName: fileName,

0 commit comments

Comments
 (0)