From 97b02cd107225c3144b8e639b41bdc51eaf27fed Mon Sep 17 00:00:00 2001 From: Haiyan Meng Date: Thu, 7 Oct 2021 10:02:30 -0700 Subject: [PATCH] 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. --- pkg/apply/applier.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pkg/apply/applier.go b/pkg/apply/applier.go index b169f405..35b444e5 100644 --- a/pkg/apply/applier.go +++ b/pkg/apply/applier.go @@ -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{},