Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix delete ipaddressallocation bug #716

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions pkg/nsx/services/ipaddressallocation/compare.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@ type (

type Comparable = common.Comparable

func (iap *IpAddressAllocation) Key() string {
return *iap.Id
func (ipa *IpAddressAllocation) Key() string {
return *ipa.Id
}

func (iap *IpAddressAllocation) Value() data.DataValue {
s := &IpAddressAllocation{Id: iap.Id, DisplayName: iap.DisplayName, Tags: iap.Tags, AllocationSize: iap.AllocationSize, IpAddressBlockVisibility: iap.IpAddressBlockVisibility}
func (ipa *IpAddressAllocation) Value() data.DataValue {
if ipa == nil {
return nil
}
s := &IpAddressAllocation{Id: ipa.Id, DisplayName: ipa.DisplayName, Tags: ipa.Tags, AllocationSize: ipa.AllocationSize, IpAddressBlockVisibility: ipa.IpAddressBlockVisibility}
dataValue, _ := ComparableToIpAddressAllocation(s).GetDataValue__()
return dataValue
}
Expand Down
24 changes: 13 additions & 11 deletions pkg/nsx/services/ipaddressallocation/ipaddressallocation.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,30 +98,32 @@ func (service *IPAddressAllocationService) CreateOrUpdateIPAddressAllocation(obj

func (service *IPAddressAllocationService) Apply(nsxIPAddressAllocation *model.VpcIpAddressAllocation) error {
ns := service.GetIPAddressAllocationNamespace(nsxIPAddressAllocation)
var err error
VPCInfo := service.VPCService.ListVPCInfo(ns)
if len(VPCInfo) == 0 {
err = util.NoEffectiveOption{Desc: "no valid org and project for ipaddressallocation"}
err := util.NoEffectiveOption{Desc: "no valid org and project for ipaddressallocation"}
return err
}
err = service.NSXClient.IPAddressAllocationClient.Patch(VPCInfo[0].OrgID, VPCInfo[0].ProjectID, VPCInfo[0].ID, *nsxIPAddressAllocation.Id, *nsxIPAddressAllocation)
err = util.NSXApiError(err)
if err != nil {
errPatch := service.NSXClient.IPAddressAllocationClient.Patch(VPCInfo[0].OrgID, VPCInfo[0].ProjectID, VPCInfo[0].ID, *nsxIPAddressAllocation.Id, *nsxIPAddressAllocation)
errPatch = util.NSXApiError(errPatch)
if errPatch != nil {
// not return err, try to get it from nsx, in case if cidr not realized at the first time
// so it can be patched in the next time and reacquire cidr
log.Error(err, "patch failed, try to get it from nsx", "nsxIPAddressAllocation", nsxIPAddressAllocation)
log.Error(errPatch, "patch failed, try to get it from nsx", "nsxIPAddressAllocation", nsxIPAddressAllocation)
}
// get back from nsx, it contains path which is used to parse vpc info when deleting
nsxIPAddressAllocationNew, err := service.NSXClient.IPAddressAllocationClient.Get(VPCInfo[0].OrgID, VPCInfo[0].ProjectID, VPCInfo[0].ID, *nsxIPAddressAllocation.Id)
err = util.NSXApiError(err)
if err != nil {
return err
nsxIPAddressAllocationNew, errGet := service.NSXClient.IPAddressAllocationClient.Get(VPCInfo[0].OrgID, VPCInfo[0].ProjectID, VPCInfo[0].ID, *nsxIPAddressAllocation.Id)
errGet = util.NSXApiError(errGet)
if errGet != nil {
if errPatch != nil {
return fmt.Errorf("error get %s, error patch %s", errGet.Error(), errPatch.Error())
}
return errGet
}
if nsxIPAddressAllocationNew.AllocationIps == nil {
err := fmt.Errorf("cidr not realized yet")
return err
}
err = service.ipAddressAllocationStore.Apply(&nsxIPAddressAllocationNew)
err := service.ipAddressAllocationStore.Apply(&nsxIPAddressAllocationNew)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/nsx/services/ipaddressallocation/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func (ipAddressAllocationStore *IPAddressAllocationStore) GetByIndex(uid types.U
nsxIPAddressAllocation = t
} else {
log.Info("did not get ipaddressallocation with index", "UID", string(uid))
return nsxIPAddressAllocation, nil
return nil, nil
}
return nsxIPAddressAllocation, nil
}
Loading