Skip to content

Commit

Permalink
Merge pull request #465 from seans3/export-status-poller
Browse files Browse the repository at this point in the history
Exports Applier/Destroyer StatusPoller field
  • Loading branch information
k8s-ci-robot authored Nov 2, 2021
2 parents 7c3417d + 944b7a7 commit 10f3156
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 36 deletions.
7 changes: 1 addition & 6 deletions cmd/apply/cmdapply.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -137,18 +136,14 @@ 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
}

// 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
}
Expand Down
7 changes: 1 addition & 6 deletions cmd/destroy/cmddestroy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
}
Expand Down
10 changes: 2 additions & 8 deletions cmd/preview/cmdpreview.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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
Expand All @@ -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
}
Expand All @@ -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
}
Expand Down
13 changes: 9 additions & 4 deletions pkg/apply/applier.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 4 additions & 2 deletions pkg/apply/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
}
Expand Down
13 changes: 9 additions & 4 deletions pkg/apply/destroyer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
}
Expand Down Expand Up @@ -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{
Expand Down
8 changes: 2 additions & 6 deletions test/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
}

0 comments on commit 10f3156

Please sign in to comment.