Skip to content

Commit

Permalink
Remove the dependecy of the VolumeSnapshotLocation's generate
Browse files Browse the repository at this point in the history
client code.

Signed-off-by: Xun Jiang <[email protected]>
  • Loading branch information
Xun Jiang committed Nov 1, 2023
1 parent 23921e5 commit 1f0a4b3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 15 deletions.
4 changes: 2 additions & 2 deletions pkg/cmd/cli/snapshotlocation/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
12 changes: 7 additions & 5 deletions pkg/cmd/cli/snapshotlocation/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
Expand Down
9 changes: 1 addition & 8 deletions pkg/restore/pv_restorer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand All @@ -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)
Expand Down

0 comments on commit 1f0a4b3

Please sign in to comment.