diff --git a/pkg/cmd/cli/snapshotlocation/create.go b/pkg/cmd/cli/snapshotlocation/create.go index b0e5e2f09e2..db55ad83490 100644 --- a/pkg/cmd/cli/snapshotlocation/create.go +++ b/pkg/cmd/cli/snapshotlocation/create.go @@ -124,12 +124,12 @@ func (o *CreateOptions) Run(c *cobra.Command, f client.Factory) error { return err } - client, err := f.Client() + client, err := f.KubebuilderClient() if err != nil { return err } - if _, err := client.VeleroV1().VolumeSnapshotLocations(volumeSnapshotLocation.Namespace).Create(context.TODO(), volumeSnapshotLocation, metav1.CreateOptions{}); err != nil { + if err := client.Create(context.TODO(), volumeSnapshotLocation); err != nil { return errors.WithStack(err) } diff --git a/pkg/cmd/cli/snapshotlocation/get.go b/pkg/cmd/cli/snapshotlocation/get.go index c25f6c9f9c2..2acddbf7f5e 100644 --- a/pkg/cmd/cli/snapshotlocation/get.go +++ b/pkg/cmd/cli/snapshotlocation/get.go @@ -21,6 +21,7 @@ import ( "github.com/spf13/cobra" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + kbclient "sigs.k8s.io/controller-runtime/pkg/client" api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1" "github.com/vmware-tanzu/velero/pkg/client" @@ -36,18 +37,19 @@ func NewGetCommand(f client.Factory, use string) *cobra.Command { Run: func(c *cobra.Command, args []string) { err := output.ValidateFlags(c) cmd.CheckError(err) - veleroClient, err := f.Client() + client, err := f.KubebuilderClient() cmd.CheckError(err) - var locations *api.VolumeSnapshotLocationList + locations := new(api.VolumeSnapshotLocationList) + if len(args) > 0 { - locations = new(api.VolumeSnapshotLocationList) for _, name := range args { - location, err := veleroClient.VeleroV1().VolumeSnapshotLocations(f.Namespace()).Get(context.TODO(), name, metav1.GetOptions{}) + location := new(api.VolumeSnapshotLocation) + err := client.Get(context.TODO(), kbclient.ObjectKey{Namespace: f.Namespace(), Name: name}, location) cmd.CheckError(err) locations.Items = append(locations.Items, *location) } } else { - locations, err = veleroClient.VeleroV1().VolumeSnapshotLocations(f.Namespace()).List(context.TODO(), listOptions) + err = client.List(context.TODO(), locations, &kbclient.ListOptions{Namespace: f.Namespace()}) cmd.CheckError(err) } _, err = output.PrintWithFormat(c, locations) diff --git a/pkg/restore/pv_restorer_test.go b/pkg/restore/pv_restorer_test.go index db92f6e5cdc..0d49ba4b84d 100644 --- a/pkg/restore/pv_restorer_test.go +++ b/pkg/restore/pv_restorer_test.go @@ -28,8 +28,6 @@ import ( api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1" "github.com/vmware-tanzu/velero/pkg/builder" - "github.com/vmware-tanzu/velero/pkg/generated/clientset/versioned/fake" - informers "github.com/vmware-tanzu/velero/pkg/generated/informers/externalversions" providermocks "github.com/vmware-tanzu/velero/pkg/plugin/velero/mocks/volumesnapshotter/v1" vsv1 "github.com/vmware-tanzu/velero/pkg/plugin/velero/volumesnapshotter/v1" velerotest "github.com/vmware-tanzu/velero/pkg/test" @@ -116,11 +114,6 @@ func TestExecutePVAction_NoSnapshotRestores(t *testing.T) { for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { - var ( - client = fake.NewSimpleClientset() - snapshotLocationInformer = informers.NewSharedInformerFactory(client, 0).Velero().V1().VolumeSnapshotLocations() - ) - r := &pvRestorer{ logger: velerotest.NewLogger(), restorePVs: tc.restore.Spec.RestorePVs, @@ -132,7 +125,7 @@ func TestExecutePVAction_NoSnapshotRestores(t *testing.T) { } for _, loc := range tc.locations { - require.NoError(t, snapshotLocationInformer.Informer().GetStore().Add(loc)) + require.NoError(t, r.kbclient.Create(context.TODO(), loc)) } res, err := r.executePVAction(tc.obj)