Exports Applier StatusPoller field

This commit is contained in:
Sean Sullivan 2021-11-02 11:53:52 -07:00
parent 7c3417d3a8
commit 944b7a7d63
7 changed files with 28 additions and 36 deletions

View File

@ -19,7 +19,6 @@ import (
"sigs.k8s.io/cli-utils/pkg/inventory"
"sigs.k8s.io/cli-utils/pkg/manifestreader"
"sigs.k8s.io/cli-utils/pkg/printers"
"sigs.k8s.io/cli-utils/pkg/util/factory"
)
func GetApplyRunner(factory cmdutil.Factory, invFactory inventory.InventoryClientFactory,
@ -137,10 +136,6 @@ func (r *ApplyRunner) RunE(cmd *cobra.Command, args []string) error {
}
inv := inventory.WrapInventoryInfoObj(invObj)
statusPoller, err := factory.NewStatusPoller(r.factory)
if err != nil {
return err
}
invClient, err := r.invFactory.NewInventoryClient(r.factory)
if err != nil {
return err
@ -148,7 +143,7 @@ func (r *ApplyRunner) RunE(cmd *cobra.Command, args []string) error {
// Run the applier. It will return a channel where we can receive updates
// to keep track of progress and any issues.
a, err := apply.NewApplier(r.factory, invClient, statusPoller)
a, err := apply.NewApplier(r.factory, invClient)
if err != nil {
return err
}

View File

@ -19,7 +19,6 @@ import (
"sigs.k8s.io/cli-utils/pkg/inventory"
"sigs.k8s.io/cli-utils/pkg/manifestreader"
"sigs.k8s.io/cli-utils/pkg/printers"
"sigs.k8s.io/cli-utils/pkg/util/factory"
)
// GetDestroyRunner creates and returns the DestroyRunner which stores the cobra command.
@ -107,15 +106,11 @@ func (r *DestroyRunner) RunE(cmd *cobra.Command, args []string) error {
}
inv := inventory.WrapInventoryInfoObj(invObj)
statusPoller, err := factory.NewStatusPoller(r.factory)
if err != nil {
return err
}
invClient, err := r.invFactory.NewInventoryClient(r.factory)
if err != nil {
return err
}
d, err := apply.NewDestroyer(r.factory, invClient, statusPoller)
d, err := apply.NewDestroyer(r.factory, invClient)
if err != nil {
return err
}

View File

@ -20,7 +20,6 @@ import (
"sigs.k8s.io/cli-utils/pkg/inventory"
"sigs.k8s.io/cli-utils/pkg/manifestreader"
"sigs.k8s.io/cli-utils/pkg/printers"
"sigs.k8s.io/cli-utils/pkg/util/factory"
)
var (
@ -122,11 +121,6 @@ func (r *PreviewRunner) RunE(cmd *cobra.Command, args []string) error {
}
inv := inventory.WrapInventoryInfoObj(invObj)
statusPoller, err := factory.NewStatusPoller(r.factory)
if err != nil {
return err
}
invClient, err := r.invFactory.NewInventoryClient(r.factory)
if err != nil {
return err
@ -139,7 +133,7 @@ func (r *PreviewRunner) RunE(cmd *cobra.Command, args []string) error {
if err != nil {
return err
}
a, err := apply.NewApplier(r.factory, invClient, statusPoller)
a, err := apply.NewApplier(r.factory, invClient)
if err != nil {
return err
}
@ -154,7 +148,7 @@ func (r *PreviewRunner) RunE(cmd *cobra.Command, args []string) error {
InventoryPolicy: inventoryPolicy,
})
} else {
d, err := apply.NewDestroyer(r.factory, invClient, statusPoller)
d, err := apply.NewDestroyer(r.factory, invClient)
if err != nil {
return err
}

View File

@ -27,21 +27,26 @@ import (
"sigs.k8s.io/cli-utils/pkg/inventory"
"sigs.k8s.io/cli-utils/pkg/object"
"sigs.k8s.io/cli-utils/pkg/ordering"
statusfactory "sigs.k8s.io/cli-utils/pkg/util/factory"
)
// NewApplier returns a new Applier.
func NewApplier(factory cmdutil.Factory, invClient inventory.InventoryClient, statusPoller poller.Poller) (*Applier, error) {
func NewApplier(factory cmdutil.Factory, invClient inventory.InventoryClient) (*Applier, error) {
pruner, err := prune.NewPruner(factory, invClient)
if err != nil {
return nil, err
}
statusPoller, err := statusfactory.NewStatusPoller(factory)
if err != nil {
return nil, err
}
mapper, err := factory.ToRESTMapper()
if err != nil {
return nil, err
}
return &Applier{
pruner: pruner,
statusPoller: statusPoller,
StatusPoller: statusPoller,
factory: factory,
invClient: invClient,
infoHelper: info.NewInfoHelper(mapper, factory),
@ -60,7 +65,7 @@ func NewApplier(factory cmdutil.Factory, invClient inventory.InventoryClient, st
// cluster, different sets of tasks might be needed.
type Applier struct {
pruner *prune.Pruner
statusPoller poller.Poller
StatusPoller poller.Poller
factory cmdutil.Factory
invClient inventory.InventoryClient
infoHelper info.InfoHelper
@ -224,7 +229,7 @@ func (a *Applier) Run(ctx context.Context, invInfo inventory.InventoryInfo, obje
// Create a new TaskStatusRunner to execute the taskQueue.
klog.V(4).Infoln("applier building TaskStatusRunner...")
allIds := object.UnstructuredsToObjMetasOrDie(append(applyObjs, pruneObjs...))
runner := taskrunner.NewTaskStatusRunner(allIds, a.statusPoller, resourceCache)
runner := taskrunner.NewTaskStatusRunner(allIds, a.StatusPoller, resourceCache)
klog.V(4).Infoln("applier running TaskStatusRunner...")
err = runner.Run(ctx, taskQueue.ToChannel(), eventChannel, taskrunner.Options{
PollInterval: options.PollInterval,

View File

@ -75,8 +75,9 @@ func newTestApplier(
invClient := newTestInventory(t, tf, infoHelper)
applier, err := NewApplier(tf, invClient, statusPoller)
applier, err := NewApplier(tf, invClient)
require.NoError(t, err)
applier.StatusPoller = statusPoller
// Inject the fakeInfoHelper to allow generating Info
// objects that use the FakeRESTClient as the UnstructuredClient.
@ -100,8 +101,9 @@ func newTestDestroyer(
invClient := newTestInventory(t, tf, infoHelper)
destroyer, err := NewDestroyer(tf, invClient, statusPoller)
destroyer, err := NewDestroyer(tf, invClient)
require.NoError(t, err)
destroyer.StatusPoller = statusPoller
return destroyer
}

View File

@ -21,6 +21,7 @@ import (
"sigs.k8s.io/cli-utils/pkg/common"
"sigs.k8s.io/cli-utils/pkg/inventory"
"sigs.k8s.io/cli-utils/pkg/object"
statusfactory "sigs.k8s.io/cli-utils/pkg/util/factory"
)
// NewDestroyer returns a new destroyer. It will set up the ApplyOptions and
@ -29,14 +30,18 @@ import (
// the ApplyOptions were responsible for printing progress. This is now
// handled by a separate printer with the KubectlPrinterAdapter bridging
// between the two.
func NewDestroyer(factory cmdutil.Factory, invClient inventory.InventoryClient, statusPoller poller.Poller) (*Destroyer, error) {
func NewDestroyer(factory cmdutil.Factory, invClient inventory.InventoryClient) (*Destroyer, error) {
pruner, err := prune.NewPruner(factory, invClient)
if err != nil {
return nil, fmt.Errorf("error setting up PruneOptions: %w", err)
}
statusPoller, err := statusfactory.NewStatusPoller(factory)
if err != nil {
return nil, err
}
return &Destroyer{
pruner: pruner,
statusPoller: statusPoller,
StatusPoller: statusPoller,
factory: factory,
invClient: invClient,
}, nil
@ -46,7 +51,7 @@ func NewDestroyer(factory cmdutil.Factory, invClient inventory.InventoryClient,
// prune them. This also deletes all the previous inventory objects
type Destroyer struct {
pruner *prune.Pruner
statusPoller poller.Poller
StatusPoller poller.Poller
factory cmdutil.Factory
invClient inventory.InventoryClient
}
@ -150,7 +155,7 @@ func (d *Destroyer) Run(ctx context.Context, inv inventory.InventoryInfo, option
klog.V(4).Infoln("destroyer building TaskStatusRunner...")
deleteIds := object.UnstructuredsToObjMetasOrDie(deleteObjs)
resourceCache := cache.NewResourceCacheMap()
runner := taskrunner.NewTaskStatusRunner(deleteIds, d.statusPoller, resourceCache)
runner := taskrunner.NewTaskStatusRunner(deleteIds, d.StatusPoller, resourceCache)
klog.V(4).Infoln("destroyer running TaskStatusRunner...")
// TODO(seans): Make the poll interval configurable like the applier.
err = runner.Run(ctx, taskQueue.ToChannel(), eventChannel, taskrunner.Options{

View File

@ -352,10 +352,8 @@ func newApplierFromInvFactory(invFactory inventory.InventoryClientFactory) *appl
f := newFactory()
invClient, err := invFactory.NewInventoryClient(f)
Expect(err).NotTo(HaveOccurred())
statusPoller, err := factory.NewStatusPoller(f)
Expect(err).NotTo(HaveOccurred())
a, err := apply.NewApplier(f, invClient, statusPoller)
a, err := apply.NewApplier(f, invClient)
Expect(err).NotTo(HaveOccurred())
return a
}
@ -364,10 +362,8 @@ func newDestroyerFromInvFactory(invFactory inventory.InventoryClientFactory) *ap
f := newFactory()
invClient, err := invFactory.NewInventoryClient(f)
Expect(err).NotTo(HaveOccurred())
statusPoller, err := factory.NewStatusPoller(f)
Expect(err).NotTo(HaveOccurred())
d, err := apply.NewDestroyer(f, invClient, statusPoller)
d, err := apply.NewDestroyer(f, invClient)
Expect(err).NotTo(HaveOccurred())
return d
}