diff --git a/cni/network/invoker_azure.go b/cni/network/invoker_azure.go index 437f6c8137..e378a11022 100644 --- a/cni/network/invoker_azure.go +++ b/cni/network/invoker_azure.go @@ -102,6 +102,10 @@ func (invoker *AzureIPAMInvoker) deleteIpamState() { return } + if cniStateExists { + return + } + ipamStateExists, err := platform.CheckIfFileExists(platform.CNIIpamStatePath) if err != nil { log.Printf("[cni] Error checking IPAM state exist: %v", err) diff --git a/ipam/api.go b/ipam/api.go index 641d755d9c..0b570cfaf9 100644 --- a/ipam/api.go +++ b/ipam/api.go @@ -9,21 +9,17 @@ import ( var ( // Error responses returned by AddressManager. - errInvalidAddressSpace = fmt.Errorf("Invalid address space") - errInvalidPoolId = fmt.Errorf("Invalid address pool") - errInvalidAddress = fmt.Errorf("Invalid address") - errInvalidScope = fmt.Errorf("Invalid scope") - errInvalidConfiguration = fmt.Errorf("Invalid configuration") - errAddressPoolExists = fmt.Errorf("Address pool already exists") - errAddressPoolNotFound = fmt.Errorf("Address pool not found") - errAddressPoolInUse = fmt.Errorf("Address pool already in use") - errAddressPoolNotInUse = fmt.Errorf("Address pool not in use") - ErrNoAvailableAddressPools = fmt.Errorf("No available address pools") - errAddressExists = fmt.Errorf("Address already exists") - errAddressNotFound = fmt.Errorf("Address not found") - errAddressInUse = fmt.Errorf("Address already in use") - errAddressNotInUse = fmt.Errorf("Address not in use") - errNoAvailableAddresses = fmt.Errorf("No available addresses") + errInvalidAddressSpace = fmt.Errorf("Invalid address space") + errInvalidPoolID = fmt.Errorf("Invalid address pool") + errInvalidAddress = fmt.Errorf("Invalid address") + errInvalidScope = fmt.Errorf("Invalid scope") + errInvalidConfiguration = fmt.Errorf("Invalid configuration") + errAddressPoolExists = fmt.Errorf("Address pool already exists") + errAddressPoolNotFound = fmt.Errorf("Address pool not found") + errAddressExists = fmt.Errorf("Address already exists") + errAddressNotFound = fmt.Errorf("Address not found") + errAddressInUse = fmt.Errorf("Address already in use") + errNoAvailableAddresses = fmt.Errorf("No available addresses") // Options used by AddressManager. OptInterfaceName = "azure.interface.name" @@ -31,3 +27,6 @@ var ( OptAddressType = "azure.address.type" OptAddressTypeGateway = "gateway" ) + +// Exportable errors returned by AddressManager +var ErrNoAvailableAddressPools = fmt.Errorf("no available address pools") diff --git a/ipam/pool.go b/ipam/pool.go index 7483e61259..d61142986c 100644 --- a/ipam/pool.go +++ b/ipam/pool.go @@ -103,7 +103,7 @@ func NewAddressPoolIdFromString(s string) (*addressPoolId, error) { p := strings.Split(s, "|") if len(p) > 3 { - return nil, errInvalidPoolId + return nil, errInvalidPoolID } pid.AsId = p[0] @@ -282,7 +282,7 @@ func (as *addressSpace) newAddressPool(ifName string, priority int, subnet *net. func (as *addressSpace) getAddressPool(poolId string) (*addressPool, error) { ap := as.Pools[poolId] if ap == nil { - return nil, fmt.Errorf("Pool id %v not found :%v", poolId, errInvalidPoolId) + return nil, fmt.Errorf("Pool id %v not found :%w", poolId, errInvalidPoolID) } return ap, nil diff --git a/store/json.go b/store/json.go index a52706e6a1..7ae7172560 100644 --- a/store/json.go +++ b/store/json.go @@ -39,7 +39,7 @@ type jsonFileStore struct { // NewJsonFileStore creates a new jsonFileStore object, accessed as a KeyValueStore. func NewJsonFileStore(fileName string, lockclient processlock.Interface) (KeyValueStore, error) { if fileName == "" { - return &jsonFileStore{}, errors.New("Need to pass in a json file path") + return &jsonFileStore{}, errors.New("need to pass in a json file path") } kvs := &jsonFileStore{ fileName: fileName,