Skip to content

Commit

Permalink
Fix errors when deleting ip block from ipblock store
Browse files Browse the repository at this point in the history
  • Loading branch information
seanpang-vmware committed Aug 14, 2023
1 parent 9864be7 commit 5858359
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
16 changes: 16 additions & 0 deletions pkg/nsx/services/vpc/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,19 @@ func (vs *VPCStore) GetByKey(key string) *model.Vpc {
}
return nil
}

func (is *IPBlockStore) GetByIndexAndPath(index string, value string, path string) *model.IpAddressBlock {
indexResults, err := is.ResourceStore.Indexer.ByIndex(index, value)
if err != nil {
log.Error(err, "failed to get obj by index", "index", value)
return nil
}

for _, item := range indexResults {
block := item.(model.IpAddressBlock)
if *block.Path == path {
return &block
}
}
return nil
}
13 changes: 6 additions & 7 deletions pkg/nsx/services/vpc/vpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,14 +188,13 @@ func (service *VPCService) DeleteIPBlock(vpc model.Vpc) error {
vpcCRUid = *tag.Tag
}
}
log.Info("search ip block from store using index", "index", common.TagScopeVPCCRUID, "value", vpcCRUid)
log.Info("search ip block from store using index and path", "index", common.TagScopeVPCCRUID, "value", vpcCRUid, "path", block)
// TODO: bugfix, seems using vpc cr uid can not get the ip blocks from cache, need further checking
ipblocks := service.IpblockStore.GetByIndex(common.TagScopeVPCCRUID, vpcCRUid)
if ipblocks != nil && len(ipblocks) != 0 {
log.Info("deleting ip blocks", "IPBlock", ipblocks[0])
b := ipblocks[0].(model.IpAddressBlock)
b.MarkedForDelete = &MarkedForDelete
service.IpblockStore.Operate(&ipblocks[0])
ipblock := service.IpblockStore.GetByIndexAndPath(common.TagScopeVPCCRUID, vpcCRUid, block)
if ipblock != nil {
log.Info("deleting ip blocks", "IPBlock", ipblock)
ipblock.MarkedForDelete = &MarkedForDelete
service.IpblockStore.Operate(ipblock)
}
}
log.Info("successfully deleted all ip blocks")
Expand Down

0 comments on commit 5858359

Please sign in to comment.