Skip to content

Commit 1dc67ad

Browse files
committed
Function to set inventory factory function on inventory client
1 parent 79bc33b commit 1dc67ad

File tree

5 files changed

+12
-11
lines changed

5 files changed

+12
-11
lines changed

pkg/apply/applier.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ func NewApplier(factory util.Factory, ioStreams genericclioptions.IOStreams) *Ap
5050
}
5151
a.infoHelperFactoryFunc = a.infoHelperFactory
5252
a.InventoryFactoryFunc = inventory.WrapInventoryObj
53-
a.PruneOptions.InventoryFactoryFunc = inventory.WrapInventoryObj
5453
return a
5554
}
5655

@@ -98,6 +97,8 @@ func (a *Applier) Initialize(cmd *cobra.Command) error {
9897
if err != nil {
9998
return err
10099
}
100+
// Propagate inventory factory function to inventory client
101+
a.invClient.SetInventoryFactoryFunc(a.InventoryFactoryFunc)
101102
err = a.PruneOptions.Initialize(a.factory, a.invClient)
102103
if err != nil {
103104
return errors.WrapPrefix(err, "error setting up PruneOptions", 1)

pkg/apply/prune/prune.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,22 +41,13 @@ type PruneOptions struct {
4141
// structure is shared. IMPORTANT: the apply task must
4242
// always complete before this prune is run.
4343
currentUids sets.String
44-
// The set of retrieved inventory objects (as Infos) selected
45-
// by the inventory label. This set should also include the
46-
// current inventory object. Stored here to make testing
47-
// easier by manually setting the retrieved inventory infos.
48-
49-
// InventoryFactoryFunc wraps and returns an interface for the
50-
// object which will load and store the inventory.
51-
InventoryFactoryFunc func(*resource.Info) inventory.Inventory
5244
}
5345

5446
// NewPruneOptions returns a struct (PruneOptions) encapsulating the necessary
5547
// information to run the prune. Returns an error if an error occurs
5648
// gathering this information.
5749
func NewPruneOptions(currentUids sets.String) *PruneOptions {
5850
po := &PruneOptions{currentUids: currentUids}
59-
po.InventoryFactoryFunc = inventory.WrapInventoryObj
6051
return po
6152
}
6253

pkg/apply/prune/prune_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,6 @@ func TestPrune(t *testing.T) {
193193
drs := common.Strategies[i]
194194
t.Run(name, func(t *testing.T) {
195195
po := NewPruneOptions(populateObjectIds(tc.currentInfos, t))
196-
po.InventoryFactoryFunc = inventory.WrapInventoryObj
197196
// Set up the previously applied objects.
198197
clusterObjs, _ := object.InfosToObjMetas(tc.pastInfos)
199198
po.InvClient = inventory.NewFakeInventoryClient(clusterObjs)

pkg/inventory/fake-inventory-client.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ func (fic *FakeInventoryClient) ClearInventoryObj(inv *resource.Info) (*resource
7070

7171
func (fic *FakeInventoryClient) SetDryRunStrategy(drs common.DryRunStrategy) {}
7272

73+
func (fic *FakeInventoryClient) SetInventoryFactoryFunc(fn InventoryFactoryFunc) {}
74+
7375
// SetError forces an error on the subsequent client call if it returns an error.
7476
func (fic *FakeInventoryClient) SetError(err error) {
7577
fic.err = err

pkg/inventory/inventory-client.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ type InventoryClient interface {
3939
ClearInventoryObj(inv *resource.Info) (*resource.Info, error)
4040
// SetDryRunStrategy sets the dry run strategy on whether this we actually mutate.
4141
SetDryRunStrategy(drs common.DryRunStrategy)
42+
// Sets the function to create the Inventory object.
43+
SetInventoryFactoryFunc(fn InventoryFactoryFunc)
4244
}
4345

4446
// ClusterInventoryClient is a concrete implementation of the
@@ -408,3 +410,9 @@ func (cic *ClusterInventoryClient) ClearInventoryObj(invInfo *resource.Info) (*r
408410
func (cic *ClusterInventoryClient) SetDryRunStrategy(drs common.DryRunStrategy) {
409411
cic.dryRunStrategy = drs
410412
}
413+
414+
// SetDryRun sets whether the inventory client will mutate the inventory
415+
// object in the cluster.
416+
func (cic *ClusterInventoryClient) SetInventoryFactoryFunc(fn InventoryFactoryFunc) {
417+
cic.InventoryFactoryFunc = fn
418+
}

0 commit comments

Comments
 (0)