Skip InventoryPolicyApplyFilter for the `AdoptAll` inventory policy to

improve the performance

Running InventoryPolicyApplyFilter involves getting every object in the
current inventory from the live cluster, which can be expensive if the
inventory includes lots of objects.

If the inventory policy is `AdoptAll`, the current inventory can take
ownership of any objects. Therefore, it is not necessary to run
InventoryPolicyApplyFilter.
This commit is contained in:
Haiyan Meng 2021-10-07 10:02:30 -07:00
parent 231f3f4a69
commit 97b02cd107
1 changed files with 5 additions and 3 deletions

View File

@ -173,14 +173,16 @@ func (a *Applier) Run(ctx context.Context, invInfo inventory.InventoryInfo, obje
InventoryPolicy: options.InventoryPolicy,
}
// Build list of apply validation filters.
applyFilters := []filter.ValidationFilter{
filter.InventoryPolicyApplyFilter{
applyFilters := []filter.ValidationFilter{}
if options.InventoryPolicy != inventory.AdoptAll {
applyFilters = append(applyFilters, filter.InventoryPolicyApplyFilter{
Client: client,
Mapper: mapper,
Inv: invInfo,
InvPolicy: options.InventoryPolicy,
},
})
}
// Build list of prune validation filters.
pruneFilters := []filter.ValidationFilter{
filter.PreventRemoveFilter{},