-
Notifications
You must be signed in to change notification settings - Fork 20
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
Cleanup enhancement #1009
base: main
Are you sure you want to change the base?
Cleanup enhancement #1009
Conversation
d776fe1
to
2b12a1d
Compare
89d24fe
to
ae03ceb
Compare
ae03ceb
to
86367da
Compare
|
||
func (p *PolicyResourcePath[T]) Length() int { | ||
resourceTypes := ([]PolicyResourceType)(*p) | ||
return len(resourceTypes) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return len(*p)?
pkg/nsx/services/common/store.go
Outdated
} | ||
|
||
func getVPCPathFromResourcePath(path string) ([]string, error) { | ||
resInfo, err := ParseVPCResourcePath(path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
may parse the vpcPath directly:
func ParseVPCPathFromResourcePath(nsxResourcePath string) (VPCPath string, err error) {
reExp := regexp.MustCompile((/orgs/([^/]+)/projects/([^/]+)/vpcs/([^/]+))([/\S+]*)
)
matches := reExp.FindStringSubmatch(nsxResourcePath)
if len(matches) != 6 {
err := fmt.Errorf("invalid path '%s'", nsxResourcePath)
return "", err
}
return matches[1], nil
if len(objects) == 0 { | ||
return nil | ||
} | ||
fmt.Println(b.rootType, b.leafType, "count", len(objects)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use log.Info?
func PagingNSXResources[T any](resources []T, pageSize int) [][]T { | ||
totalCount := len(resources) | ||
pages := (totalCount + pageSize - 1) / pageSize | ||
pagedResources := make([][]T, 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make([][]T,0, pages)
leafWrapper LeafDataWrapper[T] | ||
pathGetter GetPath[T] | ||
idGetter GetId[T] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why the three function defined as a property?
} | ||
|
||
func wrapInfra(children []*data.StructValue) *model.Infra { | ||
// This is the outermost layer of the hierarchy infra client. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wrapInfra data.StructValue-> model.Infra
WrapVPC model.Vpc-> data.StructValue.
but they have the same WrapXXX name?
} | ||
|
||
func PagingDeleteResources[T any](ctx context.Context, builder *PolicyTreeBuilder[T], objs []T, pageSize int, nsxClient *nsx.Client, delFn func(deletedObjs []T)) error { | ||
if len(objs) == 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
name delFun to deleteObjectsFromStore?
This change is trying to use HAPI in cleanup logic, and remove unnecessary NSX API calls if a VPC is already deleted recursively. It also introduces the VPC deletion in parallel.
Test Done: