Remove Provider interface

This commit is contained in:
Mikhail Mazurskiy 2021-06-24 22:49:41 +10:00
parent 3a81895d9d
commit c1c7c9ef9c
No known key found for this signature in database
GPG Key ID: FA7917C48932DD55
15 changed files with 145 additions and 206 deletions

View File

@ -19,15 +19,16 @@ import (
"sigs.k8s.io/cli-utils/pkg/common"
"sigs.k8s.io/cli-utils/pkg/inventory"
"sigs.k8s.io/cli-utils/pkg/manifestreader"
"sigs.k8s.io/cli-utils/pkg/provider"
"sigs.k8s.io/cli-utils/pkg/util/factory"
)
func GetApplyRunner(provider provider.Provider, loader manifestreader.ManifestLoader, ioStreams genericclioptions.IOStreams) *ApplyRunner {
func GetApplyRunner(factory cmdutil.Factory, invFactory inventory.InventoryClientFactory,
loader manifestreader.ManifestLoader, ioStreams genericclioptions.IOStreams) *ApplyRunner {
r := &ApplyRunner{
ioStreams: ioStreams,
provider: provider,
loader: loader,
ioStreams: ioStreams,
factory: factory,
invFactory: invFactory,
loader: loader,
}
cmd := &cobra.Command{
Use: "apply (DIRECTORY | STDIN)",
@ -63,17 +64,17 @@ func GetApplyRunner(provider provider.Provider, loader manifestreader.ManifestLo
return r
}
func ApplyCommand(f cmdutil.Factory, ioStreams genericclioptions.IOStreams) *cobra.Command {
provider := provider.NewProvider(f)
loader := manifestreader.NewManifestLoader(f)
return GetApplyRunner(provider, loader, ioStreams).Command
func ApplyCommand(f cmdutil.Factory, invFactory inventory.InventoryClientFactory, loader manifestreader.ManifestLoader,
ioStreams genericclioptions.IOStreams) *cobra.Command {
return GetApplyRunner(f, invFactory, loader, ioStreams).Command
}
type ApplyRunner struct {
Command *cobra.Command
PreProcess func(info inventory.InventoryInfo, strategy common.DryRunStrategy) (inventory.InventoryPolicy, error)
ioStreams genericclioptions.IOStreams
provider provider.Provider
factory cmdutil.Factory
invFactory inventory.InventoryClientFactory
loader manifestreader.ManifestLoader
serverSideOptions common.ServerSideOptions
@ -131,15 +132,18 @@ func (r *ApplyRunner) RunE(cmd *cobra.Command, args []string) error {
return err
}
}
f := r.provider.Factory()
statusPoller, err := factory.NewStatusPoller(f)
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.provider, statusPoller)
a, err := apply.NewApplier(r.factory, invClient, statusPoller)
if err != nil {
return err
}

View File

@ -18,16 +18,17 @@ import (
"sigs.k8s.io/cli-utils/pkg/common"
"sigs.k8s.io/cli-utils/pkg/inventory"
"sigs.k8s.io/cli-utils/pkg/manifestreader"
"sigs.k8s.io/cli-utils/pkg/provider"
"sigs.k8s.io/cli-utils/pkg/util/factory"
)
// GetDestroyRunner creates and returns the DestroyRunner which stores the cobra command.
func GetDestroyRunner(provider provider.Provider, loader manifestreader.ManifestLoader, ioStreams genericclioptions.IOStreams) *DestroyRunner {
func GetDestroyRunner(factory cmdutil.Factory, invFactory inventory.InventoryClientFactory,
loader manifestreader.ManifestLoader, ioStreams genericclioptions.IOStreams) *DestroyRunner {
r := &DestroyRunner{
ioStreams: ioStreams,
provider: provider,
loader: loader,
ioStreams: ioStreams,
factory: factory,
invFactory: invFactory,
loader: loader,
}
cmd := &cobra.Command{
Use: "destroy (DIRECTORY | STDIN)",
@ -51,10 +52,9 @@ func GetDestroyRunner(provider provider.Provider, loader manifestreader.Manifest
}
// DestroyCommand creates the DestroyRunner, returning the cobra command associated with it.
func DestroyCommand(f cmdutil.Factory, ioStreams genericclioptions.IOStreams) *cobra.Command {
provider := provider.NewProvider(f)
loader := manifestreader.NewManifestLoader(f)
return GetDestroyRunner(provider, loader, ioStreams).Command
func DestroyCommand(f cmdutil.Factory, invFactory inventory.InventoryClientFactory, loader manifestreader.ManifestLoader,
ioStreams genericclioptions.IOStreams) *cobra.Command {
return GetDestroyRunner(f, invFactory, loader, ioStreams).Command
}
// DestroyRunner encapsulates data necessary to run the destroy command.
@ -62,7 +62,8 @@ type DestroyRunner struct {
Command *cobra.Command
PreProcess func(info inventory.InventoryInfo, strategy common.DryRunStrategy) (inventory.InventoryPolicy, error)
ioStreams genericclioptions.IOStreams
provider provider.Provider
factory cmdutil.Factory
invFactory inventory.InventoryClientFactory
loader manifestreader.ManifestLoader
output string
@ -101,11 +102,15 @@ func (r *DestroyRunner) RunE(cmd *cobra.Command, args []string) error {
}
}
statusPoller, err := factory.NewStatusPoller(r.provider.Factory())
statusPoller, err := factory.NewStatusPoller(r.factory)
if err != nil {
return err
}
d, err := apply.NewDestroyer(r.provider, statusPoller)
invClient, err := r.invFactory.NewInventoryClient(r.factory)
if err != nil {
return err
}
d, err := apply.NewDestroyer(r.factory, invClient, statusPoller)
if err != nil {
return err
}

View File

@ -19,6 +19,8 @@ import (
"sigs.k8s.io/cli-utils/cmd/preview"
"sigs.k8s.io/cli-utils/cmd/status"
"sigs.k8s.io/cli-utils/pkg/errors"
"sigs.k8s.io/cli-utils/pkg/inventory"
"sigs.k8s.io/cli-utils/pkg/manifestreader"
"sigs.k8s.io/cli-utils/pkg/util/factory"
// This is here rather than in the libraries because of
@ -57,15 +59,17 @@ func main() {
names := []string{"init", "apply", "preview", "diff", "destroy", "status"}
initCmd := initcmd.NewCmdInit(f, ioStreams)
updateHelp(names, initCmd)
applyCmd := apply.ApplyCommand(f, ioStreams)
loader := manifestreader.NewManifestLoader(f)
invFactory := inventory.ClusterInventoryClientFactory{}
applyCmd := apply.ApplyCommand(f, invFactory, loader, ioStreams)
updateHelp(names, applyCmd)
previewCmd := preview.PreviewCommand(f, ioStreams)
previewCmd := preview.PreviewCommand(f, invFactory, loader, ioStreams)
updateHelp(names, previewCmd)
diffCmd := diff.NewCmdDiff(f, ioStreams)
updateHelp(names, diffCmd)
destroyCmd := destroy.DestroyCommand(f, ioStreams)
destroyCmd := destroy.DestroyCommand(f, invFactory, loader, ioStreams)
updateHelp(names, destroyCmd)
statusCmd := status.StatusCommand(f)
statusCmd := status.StatusCommand(f, invFactory, loader)
updateHelp(names, statusCmd)
cmd.AddCommand(initCmd, applyCmd, diffCmd, destroyCmd, previewCmd, statusCmd)

View File

@ -19,7 +19,6 @@ import (
"sigs.k8s.io/cli-utils/pkg/common"
"sigs.k8s.io/cli-utils/pkg/inventory"
"sigs.k8s.io/cli-utils/pkg/manifestreader"
"sigs.k8s.io/cli-utils/pkg/provider"
"sigs.k8s.io/cli-utils/pkg/util/factory"
)
@ -29,11 +28,13 @@ var (
)
// GetPreviewRunner creates and returns the PreviewRunner which stores the cobra command.
func GetPreviewRunner(provider provider.Provider, loader manifestreader.ManifestLoader, ioStreams genericclioptions.IOStreams) *PreviewRunner {
func GetPreviewRunner(factory cmdutil.Factory, invFactory inventory.InventoryClientFactory,
loader manifestreader.ManifestLoader, ioStreams genericclioptions.IOStreams) *PreviewRunner {
r := &PreviewRunner{
ioStreams: ioStreams,
provider: provider,
loader: loader,
factory: factory,
invFactory: invFactory,
loader: loader,
ioStreams: ioStreams,
}
cmd := &cobra.Command{
Use: "preview (DIRECTORY | STDIN)",
@ -62,19 +63,19 @@ func GetPreviewRunner(provider provider.Provider, loader manifestreader.Manifest
}
// PreviewCommand creates the PreviewRunner, returning the cobra command associated with it.
func PreviewCommand(f cmdutil.Factory, ioStreams genericclioptions.IOStreams) *cobra.Command {
provider := provider.NewProvider(f)
loader := manifestreader.NewManifestLoader(f)
return GetPreviewRunner(provider, loader, ioStreams).Command
func PreviewCommand(f cmdutil.Factory, invFactory inventory.InventoryClientFactory, loader manifestreader.ManifestLoader,
ioStreams genericclioptions.IOStreams) *cobra.Command {
return GetPreviewRunner(f, invFactory, loader, ioStreams).Command
}
// PreviewRunner encapsulates data necessary to run the preview command.
type PreviewRunner struct {
Command *cobra.Command
PreProcess func(info inventory.InventoryInfo, strategy common.DryRunStrategy) (inventory.InventoryPolicy, error)
ioStreams genericclioptions.IOStreams
provider provider.Provider
factory cmdutil.Factory
invFactory inventory.InventoryClientFactory
loader manifestreader.ManifestLoader
ioStreams genericclioptions.IOStreams
serverSideOptions common.ServerSideOptions
output string
@ -116,7 +117,12 @@ func (r *PreviewRunner) RunE(cmd *cobra.Command, args []string) error {
}
}
statusPoller, err := factory.NewStatusPoller(r.provider.Factory())
statusPoller, err := factory.NewStatusPoller(r.factory)
if err != nil {
return err
}
invClient, err := r.invFactory.NewInventoryClient(r.factory)
if err != nil {
return err
}
@ -128,7 +134,7 @@ func (r *PreviewRunner) RunE(cmd *cobra.Command, args []string) error {
if err != nil {
return err
}
a, err := apply.NewApplier(r.provider, statusPoller)
a, err := apply.NewApplier(r.factory, invClient, statusPoller)
if err != nil {
return err
}
@ -146,7 +152,7 @@ func (r *PreviewRunner) RunE(cmd *cobra.Command, args []string) error {
InventoryPolicy: inventoryPolicy,
})
} else {
d, err := apply.NewDestroyer(r.provider, statusPoller)
d, err := apply.NewDestroyer(r.factory, invClient, statusPoller)
if err != nil {
return err
}

View File

@ -16,19 +16,20 @@ import (
"sigs.k8s.io/cli-utils/cmd/status/printers"
"sigs.k8s.io/cli-utils/pkg/apply/poller"
"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/aggregator"
"sigs.k8s.io/cli-utils/pkg/kstatus/polling/collector"
"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/provider"
"sigs.k8s.io/cli-utils/pkg/util/factory"
)
func GetStatusRunner(provider provider.Provider, loader manifestreader.ManifestLoader) *StatusRunner {
func GetStatusRunner(factory cmdutil.Factory, invFactory inventory.InventoryClientFactory, loader manifestreader.ManifestLoader) *StatusRunner {
r := &StatusRunner{
provider: provider,
factory: factory,
invFactory: invFactory,
loader: loader,
pollerFactoryFunc: pollerFactoryFunc,
}
@ -48,18 +49,17 @@ func GetStatusRunner(provider provider.Provider, loader manifestreader.ManifestL
return r
}
func StatusCommand(f cmdutil.Factory) *cobra.Command {
provider := provider.NewProvider(f)
loader := manifestreader.NewManifestLoader(f)
return GetStatusRunner(provider, loader).Command
func StatusCommand(f cmdutil.Factory, invFactory inventory.InventoryClientFactory, loader manifestreader.ManifestLoader) *cobra.Command {
return GetStatusRunner(f, invFactory, loader).Command
}
// StatusRunner captures the parameters for the command and contains
// the run function.
type StatusRunner struct {
Command *cobra.Command
provider provider.Provider
loader manifestreader.ManifestLoader
Command *cobra.Command
factory cmdutil.Factory
invFactory inventory.InventoryClientFactory
loader manifestreader.ManifestLoader
period time.Duration
pollUntil string
@ -92,7 +92,7 @@ func (r *StatusRunner) runE(cmd *cobra.Command, args []string) error {
return err
}
invClient, err := r.provider.InventoryClient()
invClient, err := r.invFactory.NewInventoryClient(r.factory)
if err != nil {
return err
}
@ -110,7 +110,7 @@ func (r *StatusRunner) runE(cmd *cobra.Command, args []string) error {
return nil
}
statusPoller, err := r.pollerFactoryFunc(r.provider.Factory())
statusPoller, err := r.pollerFactoryFunc(r.factory)
if err != nil {
return err
}

View File

@ -16,12 +16,12 @@ import (
cmdtesting "k8s.io/kubectl/pkg/cmd/testing"
cmdutil "k8s.io/kubectl/pkg/cmd/util"
"sigs.k8s.io/cli-utils/pkg/apply/poller"
"sigs.k8s.io/cli-utils/pkg/inventory"
"sigs.k8s.io/cli-utils/pkg/kstatus/polling"
pollevent "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/object"
"sigs.k8s.io/cli-utils/pkg/provider"
)
var (
@ -222,11 +222,11 @@ deployment.apps/foo is InProgress: inProgress
tf := cmdtesting.NewTestFactory().WithNamespace("namespace")
defer tf.Cleanup()
provider := provider.NewFakeProvider(tf, tc.inventory)
loader := manifestreader.NewFakeLoader(tf, tc.inventory)
runner := &StatusRunner{
provider: provider,
loader: loader,
factory: tf,
invFactory: inventory.FakeInventoryClientFactory(tc.inventory),
loader: loader,
pollerFactoryFunc: func(c cmdutil.Factory) (poller.Poller, error) {
return &fakePoller{tc.events}, nil
},

View File

@ -14,7 +14,7 @@ import (
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/klog/v2"
"k8s.io/kubectl/pkg/cmd/util"
cmdutil "k8s.io/kubectl/pkg/cmd/util"
"sigs.k8s.io/cli-utils/pkg/apply/event"
"sigs.k8s.io/cli-utils/pkg/apply/filter"
"sigs.k8s.io/cli-utils/pkg/apply/info"
@ -26,21 +26,10 @@ import (
"sigs.k8s.io/cli-utils/pkg/inventory"
"sigs.k8s.io/cli-utils/pkg/object"
"sigs.k8s.io/cli-utils/pkg/ordering"
"sigs.k8s.io/cli-utils/pkg/provider"
)
// NewApplier returns a new Applier. It will set up the ApplyOptions and
// StatusOptions which are responsible for capturing any command line flags.
// It currently requires IOStreams, but this is a legacy from when
// the ApplyOptions were responsible for printing progress. This is now
// handled by a separate printer with the KubectlPrinterAdapter bridging
// between the two.
func NewApplier(provider provider.Provider, statusPoller poller.Poller) (*Applier, error) {
invClient, err := provider.InventoryClient()
if err != nil {
return nil, err
}
factory := provider.Factory()
// NewApplier returns a new Applier.
func NewApplier(factory cmdutil.Factory, invClient inventory.InventoryClient, statusPoller poller.Poller) (*Applier, error) {
pruneOpts, err := prune.NewPruneOptions(factory, invClient)
if err != nil {
return nil, err
@ -67,7 +56,7 @@ func NewApplier(provider provider.Provider, statusPoller poller.Poller) (*Applie
type Applier struct {
pruneOptions *prune.PruneOptions
statusPoller poller.Poller
factory util.Factory
factory cmdutil.Factory
invClient inventory.InventoryClient
infoHelper info.InfoHelper
}

View File

@ -36,7 +36,6 @@ import (
pollevent "sigs.k8s.io/cli-utils/pkg/kstatus/polling/event"
"sigs.k8s.io/cli-utils/pkg/kstatus/status"
"sigs.k8s.io/cli-utils/pkg/object"
"sigs.k8s.io/cli-utils/pkg/provider"
"sigs.k8s.io/cli-utils/pkg/testutil"
)
@ -552,20 +551,22 @@ func TestApplier(t *testing.T) {
tf.UnstructuredClient = newFakeRESTClient(t, handlers)
tf.FakeDynamicClient = fakeDynamicClient(t, mapper, objs...)
cf := provider.NewProvider(tf)
poller := &fakePoller{
events: tc.statusEvents,
start: make(chan struct{}),
}
applier, err := NewApplier(cf, poller)
invClient, err := inventory.ClusterInventoryClientFactory{}.NewInventoryClient(tf)
require.NoError(t, err)
applier.infoHelper = &fakeInfoHelper{
infoHelper := &fakeInfoHelper{
factory: tf,
}
// TODO(mortent): This is not great, but at least this keeps the
// ugliness in the test code until we can find a way to wire it
// up so to avoid it.
applier.invClient.(*inventory.ClusterInventoryClient).InfoHelper = applier.infoHelper
invClient.(*inventory.ClusterInventoryClient).InfoHelper = infoHelper
applier, err := NewApplier(tf, invClient, poller)
require.NoError(t, err)
applier.infoHelper = infoHelper
ctx := context.Background()
eventChannel := applier.Run(ctx, tc.invInfo.toWrapped(), tc.resources, Options{
ReconcileTimeout: tc.reconcileTimeout,

View File

@ -11,7 +11,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/klog/v2"
"k8s.io/kubectl/pkg/cmd/util"
cmdutil "k8s.io/kubectl/pkg/cmd/util"
"sigs.k8s.io/cli-utils/pkg/apply/event"
"sigs.k8s.io/cli-utils/pkg/apply/filter"
"sigs.k8s.io/cli-utils/pkg/apply/poller"
@ -21,7 +21,6 @@ import (
"sigs.k8s.io/cli-utils/pkg/common"
"sigs.k8s.io/cli-utils/pkg/inventory"
"sigs.k8s.io/cli-utils/pkg/object"
"sigs.k8s.io/cli-utils/pkg/provider"
)
// NewDestroyer returns a new destroyer. It will set up the ApplyOptions and
@ -30,12 +29,7 @@ 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(provider provider.Provider, statusPoller poller.Poller) (*Destroyer, error) {
invClient, err := provider.InventoryClient()
if err != nil {
return nil, errors.WrapPrefix(err, "error creating inventory client", 1)
}
factory := provider.Factory()
func NewDestroyer(factory cmdutil.Factory, invClient inventory.InventoryClient, statusPoller poller.Poller) (*Destroyer, error) {
pruneOpts, err := prune.NewPruneOptions(factory, invClient)
if err != nil {
return nil, errors.WrapPrefix(err, "error setting up PruneOptions", 1)
@ -53,7 +47,7 @@ func NewDestroyer(provider provider.Provider, statusPoller poller.Poller) (*Dest
type Destroyer struct {
pruneOptions *prune.PruneOptions
statusPoller poller.Poller
factory util.Factory
factory cmdutil.Factory
invClient inventory.InventoryClient
}

View File

@ -5,6 +5,7 @@ package inventory
import (
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
cmdutil "k8s.io/kubectl/pkg/cmd/util"
"sigs.k8s.io/cli-utils/pkg/common"
"sigs.k8s.io/cli-utils/pkg/object"
)
@ -15,7 +16,16 @@ type FakeInventoryClient struct {
Err error
}
var _ InventoryClient = &FakeInventoryClient{}
var (
_ InventoryClient = &FakeInventoryClient{}
_ InventoryClientFactory = FakeInventoryClientFactory{}
)
type FakeInventoryClientFactory []object.ObjMetadata
func (f FakeInventoryClientFactory) NewInventoryClient(factory cmdutil.Factory) (InventoryClient, error) {
return NewFakeInventoryClient(f), nil
}
// NewFakeInventoryClient returns a FakeInventoryClient.
func NewFakeInventoryClient(initObjs []object.ObjMetadata) *FakeInventoryClient {

View File

@ -0,0 +1,23 @@
// Copyright 2020 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
package inventory
import cmdutil "k8s.io/kubectl/pkg/cmd/util"
var (
_ InventoryClientFactory = ClusterInventoryClientFactory{}
)
// InventoryClientFactory is a factory that constructs new InventoryClient instances.
type InventoryClientFactory interface {
NewInventoryClient(factory cmdutil.Factory) (InventoryClient, error)
}
// ClusterInventoryClientFactory is a factory that creates instances of ClusterInventoryClient inventory client.
type ClusterInventoryClientFactory struct {
}
func (ClusterInventoryClientFactory) NewInventoryClient(factory cmdutil.Factory) (InventoryClient, error) {
return NewInventoryClient(factory, WrapInventoryObj, InvInfoToConfigMap)
}

View File

@ -1,37 +0,0 @@
// Copyright 2020 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
package provider
import (
"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/kubectl/pkg/cmd/util"
"sigs.k8s.io/cli-utils/pkg/inventory"
"sigs.k8s.io/cli-utils/pkg/object"
)
type FakeProvider struct {
factory util.Factory
InvClient *inventory.FakeInventoryClient
}
var _ Provider = &FakeProvider{}
func NewFakeProvider(f util.Factory, objs []object.ObjMetadata) *FakeProvider {
return &FakeProvider{
factory: f,
InvClient: inventory.NewFakeInventoryClient(objs),
}
}
func (f *FakeProvider) Factory() util.Factory {
return f.factory
}
func (f *FakeProvider) InventoryClient() (inventory.InventoryClient, error) {
return f.InvClient, nil
}
func (f *FakeProvider) ToRESTMapper() (meta.RESTMapper, error) {
return f.factory.ToRESTMapper()
}

View File

@ -1,45 +0,0 @@
// Copyright 2020 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
package provider
import (
"k8s.io/kubectl/pkg/cmd/util"
"sigs.k8s.io/cli-utils/pkg/inventory"
)
// InventoryProvider implements the Provider interface.
var _ Provider = &InventoryProvider{}
// Provider is an interface which wraps the kubectl factory and
// the inventory client.
type Provider interface {
Factory() util.Factory
InventoryClient() (inventory.InventoryClient, error)
}
// InventoryProvider implements the Provider interface.
type InventoryProvider struct {
factory util.Factory
}
// NewProvider returns a Provider that implements a ConfigMap inventory object.
func NewProvider(f util.Factory) *InventoryProvider {
return &InventoryProvider{
factory: f,
}
}
// Factory returns the kubectl factory.
func (f *InventoryProvider) Factory() util.Factory {
return f.factory
}
// InventoryClient returns an InventoryClient created with the stored
// factory and InventoryFactoryFunc values, or an error if one occurred.
func (f *InventoryProvider) InventoryClient() (inventory.InventoryClient, error) {
return inventory.NewInventoryClient(f.factory,
inventory.WrapInventoryObj,
inventory.InvInfoToConfigMap,
)
}

View File

@ -12,7 +12,6 @@ import (
"sigs.k8s.io/cli-utils/pkg/common"
"sigs.k8s.io/cli-utils/pkg/inventory"
"sigs.k8s.io/cli-utils/pkg/object"
"sigs.k8s.io/cli-utils/pkg/provider"
)
var InventoryCRD = []byte(strings.TrimSpace(`
@ -75,24 +74,13 @@ var InventoryGVK = schema.GroupVersionKind{
Kind: "Inventory",
}
var _ provider.Provider = &CustomProvider{}
var _ inventory.InventoryClientFactory = CustomInventoryClientFactory{}
func NewCustomProvider(f util.Factory) provider.Provider {
return &CustomProvider{
factory: f,
}
type CustomInventoryClientFactory struct {
}
type CustomProvider struct {
factory util.Factory
}
func (c *CustomProvider) Factory() util.Factory {
return c.factory
}
func (c *CustomProvider) InventoryClient() (inventory.InventoryClient, error) {
return inventory.NewInventoryClient(c.factory, WrapInventoryObj, invToUnstructuredFunc)
func (CustomInventoryClientFactory) NewInventoryClient(factory util.Factory) (inventory.InventoryClient, error) {
return inventory.NewInventoryClient(factory, WrapInventoryObj, invToUnstructuredFunc)
}
func invToUnstructuredFunc(inv inventory.InventoryInfo) *unstructured.Unstructured {

View File

@ -20,7 +20,6 @@ import (
"sigs.k8s.io/cli-utils/pkg/apply"
"sigs.k8s.io/cli-utils/pkg/common"
"sigs.k8s.io/cli-utils/pkg/inventory"
"sigs.k8s.io/cli-utils/pkg/provider"
"sigs.k8s.io/cli-utils/pkg/util/factory"
"sigs.k8s.io/cli-utils/test/e2e/customprovider"
ctrl "sigs.k8s.io/controller-runtime"
@ -205,15 +204,11 @@ func deleteNamespace(c client.Client, namespace *v1.Namespace) {
}
func newDefaultInvApplier() *apply.Applier {
return newApplierFromProvider(newDefaultInvProvider())
return newApplierFromInvFactory(inventory.ClusterInventoryClientFactory{})
}
func newDefaultInvDestroyer() *apply.Destroyer {
return newDestroyerFromProvider(newDefaultInvProvider())
}
func newDefaultInvProvider() provider.Provider {
return provider.NewProvider(newFactory())
return newDestroyerFromInvFactory(inventory.ClusterInventoryClientFactory{})
}
func defaultInvSizeVerifyFunc(c client.Client, name, namespace, id string, count int) {
@ -239,15 +234,11 @@ func defaultInvCountVerifyFunc(c client.Client, namespace string, count int) {
}
func newCustomInvApplier() *apply.Applier {
return newApplierFromProvider(newCustomInvProvider())
return newApplierFromInvFactory(customprovider.CustomInventoryClientFactory{})
}
func newCustomInvDestroyer() *apply.Destroyer {
return newDestroyerFromProvider(newCustomInvProvider())
}
func newCustomInvProvider() provider.Provider {
return customprovider.NewCustomProvider(newFactory())
return newDestroyerFromInvFactory(customprovider.CustomInventoryClientFactory{})
}
func newFactory() util.Factory {
@ -286,20 +277,26 @@ func customInvCountVerifyFunc(c client.Client, namespace string, count int) {
Expect(len(u.Items)).To(Equal(count))
}
func newApplierFromProvider(prov provider.Provider) *apply.Applier {
statusPoller, err := factory.NewStatusPoller(prov.Factory())
func newApplierFromInvFactory(invFactory inventory.InventoryClientFactory) *apply.Applier {
f := newFactory()
invClient, err := invFactory.NewInventoryClient(f)
Expect(err).NotTo(HaveOccurred())
statusPoller, err := factory.NewStatusPoller(f)
Expect(err).NotTo(HaveOccurred())
a, err := apply.NewApplier(prov, statusPoller)
a, err := apply.NewApplier(f, invClient, statusPoller)
Expect(err).NotTo(HaveOccurred())
return a
}
func newDestroyerFromProvider(prov provider.Provider) *apply.Destroyer {
statusPoller, err := factory.NewStatusPoller(prov.Factory())
func newDestroyerFromInvFactory(invFactory inventory.InventoryClientFactory) *apply.Destroyer {
f := newFactory()
invClient, err := invFactory.NewInventoryClient(f)
Expect(err).NotTo(HaveOccurred())
statusPoller, err := factory.NewStatusPoller(f)
Expect(err).NotTo(HaveOccurred())
d, err := apply.NewDestroyer(prov, statusPoller)
d, err := apply.NewDestroyer(f, invClient, statusPoller)
Expect(err).NotTo(HaveOccurred())
return d
}