From 08d9ee7e78931ad4ca4f11fceaa3d016d80a7e90 Mon Sep 17 00:00:00 2001 From: Keith Nguyen Date: Wed, 1 Jun 2022 15:48:32 -0500 Subject: [PATCH 1/4] style: format issues --- cni/network/invoker_azure.go | 4 ++++ ipam/api.go | 32 +++++++++++++++++--------------- store/json.go | 2 +- 3 files changed, 22 insertions(+), 16 deletions(-) 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..aaa60ed3d9 100644 --- a/ipam/api.go +++ b/ipam/api.go @@ -9,21 +9,23 @@ 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") + errAddressPoolInUse = fmt.Errorf("Address pool already in use") + errAddressPoolNotInUse = fmt.Errorf("Address pool not in use") + 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") + + // Exportable errors returned by AddressManager + ErrNoAvailableAddressPools = fmt.Errorf("no available address pools") // Options used by AddressManager. OptInterfaceName = "azure.interface.name" 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, From 34deaa7fce25ef1336c0cb84cdd959a6cc54eacd Mon Sep 17 00:00:00 2001 From: Keith Nguyen Date: Wed, 1 Jun 2022 15:50:54 -0500 Subject: [PATCH 2/4] style: lint issues --- ipam/api.go | 5 +---- ipam/pool.go | 4 ++-- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/ipam/api.go b/ipam/api.go index aaa60ed3d9..ec4111bd94 100644 --- a/ipam/api.go +++ b/ipam/api.go @@ -10,18 +10,15 @@ import ( var ( // Error responses returned by AddressManager. errInvalidAddressSpace = fmt.Errorf("Invalid address space") - errInvalidPoolId = fmt.Errorf("Invalid address pool") + 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") 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") // Exportable errors returned by AddressManager diff --git a/ipam/pool.go b/ipam/pool.go index 7483e61259..526271230c 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 :%v", poolId, errInvalidPoolID) } return ap, nil From cb060939a90d6fb45b84fb66ff7ab31881978239 Mon Sep 17 00:00:00 2001 From: Keith Nguyen Date: Wed, 1 Jun 2022 16:06:14 -0500 Subject: [PATCH 3/4] style: lint issues --- ipam/pool.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ipam/pool.go b/ipam/pool.go index 526271230c..d61142986c 100644 --- a/ipam/pool.go +++ b/ipam/pool.go @@ -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 From 86672ec9e106412cba17e2f48ba583f797bbb98d Mon Sep 17 00:00:00 2001 From: Keith Nguyen Date: Fri, 3 Jun 2022 15:10:42 -0500 Subject: [PATCH 4/4] style: moved to new block --- ipam/api.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ipam/api.go b/ipam/api.go index ec4111bd94..0b570cfaf9 100644 --- a/ipam/api.go +++ b/ipam/api.go @@ -21,12 +21,12 @@ var ( errAddressInUse = fmt.Errorf("Address already in use") errNoAvailableAddresses = fmt.Errorf("No available addresses") - // Exportable errors returned by AddressManager - ErrNoAvailableAddressPools = fmt.Errorf("no available address pools") - // Options used by AddressManager. OptInterfaceName = "azure.interface.name" OptAddressID = "azure.address.id" OptAddressType = "azure.address.type" OptAddressTypeGateway = "gateway" ) + +// Exportable errors returned by AddressManager +var ErrNoAvailableAddressPools = fmt.Errorf("no available address pools")