Skip to content

Commit

Permalink
Remove StatusPoller factory and support custom status readers
Browse files Browse the repository at this point in the history
  • Loading branch information
mortent committed Dec 16, 2021
1 parent 3064f8b commit f33a0cd
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 41 deletions.
4 changes: 2 additions & 2 deletions cmd/status/cmdstatus.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ import (
"sigs.k8s.io/cli-utils/pkg/kstatus/polling"
"sigs.k8s.io/cli-utils/pkg/kstatus/polling/aggregator"
"sigs.k8s.io/cli-utils/pkg/kstatus/polling/collector"
"sigs.k8s.io/cli-utils/pkg/kstatus/polling/engine"
"sigs.k8s.io/cli-utils/pkg/kstatus/polling/event"
"sigs.k8s.io/cli-utils/pkg/kstatus/status"
"sigs.k8s.io/cli-utils/pkg/manifestreader"
"sigs.k8s.io/cli-utils/pkg/util/factory"
)

func GetStatusRunner(factory cmdutil.Factory, invFactory inventory.InventoryClientFactory, loader manifestreader.ManifestLoader) *StatusRunner {
Expand Down Expand Up @@ -193,5 +193,5 @@ func allKnownNotifierFunc(cancelFunc context.CancelFunc) collector.ObserverFunc
}

func pollerFactoryFunc(f cmdutil.Factory) (poller.Poller, error) {
return factory.NewStatusPoller(f)
return polling.NewStatusPollerFromFactory(f, []engine.StatusReader{})
}
5 changes: 3 additions & 2 deletions pkg/apply/applier.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ import (
"sigs.k8s.io/cli-utils/pkg/apply/taskrunner"
"sigs.k8s.io/cli-utils/pkg/common"
"sigs.k8s.io/cli-utils/pkg/inventory"
"sigs.k8s.io/cli-utils/pkg/kstatus/polling"
"sigs.k8s.io/cli-utils/pkg/kstatus/polling/engine"
"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.
Expand All @@ -35,7 +36,7 @@ func NewApplier(factory cmdutil.Factory, invClient inventory.InventoryClient) (*
if err != nil {
return nil, err
}
statusPoller, err := statusfactory.NewStatusPoller(factory)
statusPoller, err := polling.NewStatusPollerFromFactory(factory, []engine.StatusReader{})
if err != nil {
return nil, err
}
Expand Down
5 changes: 3 additions & 2 deletions pkg/apply/destroyer.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ import (
"sigs.k8s.io/cli-utils/pkg/apply/taskrunner"
"sigs.k8s.io/cli-utils/pkg/common"
"sigs.k8s.io/cli-utils/pkg/inventory"
"sigs.k8s.io/cli-utils/pkg/kstatus/polling"
"sigs.k8s.io/cli-utils/pkg/kstatus/polling/engine"
"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 @@ -35,7 +36,7 @@ func NewDestroyer(factory cmdutil.Factory, invClient inventory.InventoryClient)
if err != nil {
return nil, fmt.Errorf("error setting up PruneOptions: %w", err)
}
statusPoller, err := statusfactory.NewStatusPoller(factory)
statusPoller, err := polling.NewStatusPollerFromFactory(factory, []engine.StatusReader{})
if err != nil {
return nil, err
}
Expand Down
24 changes: 24 additions & 0 deletions pkg/kstatus/polling/polling.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ package polling

import (
"context"
"fmt"
"time"

"k8s.io/apimachinery/pkg/api/meta"
cmdutil "k8s.io/kubectl/pkg/cmd/util"
"k8s.io/kubectl/pkg/scheme"
"sigs.k8s.io/cli-utils/pkg/kstatus/polling/clusterreader"
"sigs.k8s.io/cli-utils/pkg/kstatus/polling/engine"
"sigs.k8s.io/cli-utils/pkg/kstatus/polling/event"
Expand Down Expand Up @@ -37,6 +40,27 @@ func NewStatusPoller(reader client.Reader, mapper meta.RESTMapper, customStatusR
}
}

// NewStatusPollerFromFactory creates a new StatusPoller instance from the
// passed in factory.
func NewStatusPollerFromFactory(f cmdutil.Factory, statusReaders []engine.StatusReader) (*StatusPoller, error) {
config, err := f.ToRESTConfig()
if err != nil {
return nil, fmt.Errorf("error getting RESTConfig: %w", err)
}

mapper, err := f.ToRESTMapper()
if err != nil {
return nil, fmt.Errorf("error getting RESTMapper: %w", err)
}

c, err := client.New(config, client.Options{Scheme: scheme.Scheme, Mapper: mapper})
if err != nil {
return nil, fmt.Errorf("error creating client: %w", err)
}

return NewStatusPoller(c, mapper, statusReaders), nil
}

// StatusPoller provides functionality for polling a cluster for status for a set of resources.
type StatusPoller struct {
engine *engine.PollerEngine
Expand Down
35 changes: 0 additions & 35 deletions pkg/util/factory/statuspoller.go

This file was deleted.

0 comments on commit f33a0cd

Please sign in to comment.