Skip to content

Commit

Permalink
Add method to identify group version in the snapshotter interface (#2333
Browse files Browse the repository at this point in the history
)

* add groupversion field in the args

Signed-off-by: Amruta Kale <amruta.kale@veeam.com>

* remove pointer from group version field

* add comments

Signed-off-by: Amruta Kale <amruta.kale@veeam.com>

* add function to identify group version in the snapshotter interface

Signed-off-by: Amruta Kale <amruta.kale@veeam.com>

* add mock for group version function

Signed-off-by: Amruta Kale <amruta.kale@veeam.com>

* add comment for group version function in snapshotter interface

---------

Signed-off-by: Amruta Kale <amruta.kale@veeam.com>
  • Loading branch information
kale-amruta committed Sep 14, 2023
1 parent d847e11 commit 5f409fa
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 0 deletions.
15 changes: 15 additions & 0 deletions pkg/kube/snapshot/mocks/mock_snapshotter.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions pkg/kube/snapshot/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (

v1 "github.com/kubernetes-csi/external-snapshotter/client/v4/apis/volumesnapshot/v1"
"github.com/pkg/errors"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/dynamic"
"k8s.io/client-go/kubernetes"

Expand Down Expand Up @@ -111,6 +112,8 @@ type Snapshotter interface {
// List will list the volumesnapshots in a namespace that match search. If labels aren't provided,
// it will list all the snapshots in the namespace
List(ctx context.Context, namespace string, labels map[string]string) (*v1.VolumeSnapshotList, error)
// GroupVersion returns the group and version according to snapshotter version
GroupVersion(ctx context.Context) schema.GroupVersion
}

// Source represents the CSI source of the Volumesnapshot.
Expand Down
6 changes: 6 additions & 0 deletions pkg/kube/snapshot/snapshot_alpha.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,12 @@ func (sna *SnapshotAlpha) WaitOnReadyToUse(ctx context.Context, snapshotName, na
})
}

func (sna *SnapshotAlpha) GroupVersion(ctx context.Context) schema.GroupVersion {
return schema.GroupVersion{
Group: v1alpha1.GroupName,
Version: v1alpha1.Version,
}
}
func (sna *SnapshotAlpha) getContent(ctx context.Context, contentName string) (*v1alpha1.VolumeSnapshotContent, error) {
us, err := sna.dynCli.Resource(v1alpha1.VolSnapContentGVR).Get(ctx, contentName, metav1.GetOptions{})
if err != nil {
Expand Down
7 changes: 7 additions & 0 deletions pkg/kube/snapshot/snapshot_beta.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,13 @@ func (sna *SnapshotBeta) UpdateVolumeSnapshotStatusBeta(ctx context.Context, nam
return updateVolumeSnapshotStatus(ctx, sna.dynCli, v1beta1.VolSnapGVR, namespace, snapshotName, readyToUse)
}

func (sna *SnapshotBeta) GroupVersion(ctx context.Context) schema.GroupVersion {
return schema.GroupVersion{
Group: v1beta1.GroupName,
Version: v1beta1.Version,
}
}

func updateVolumeSnapshotStatus(ctx context.Context, dynCli dynamic.Interface, snapGVR schema.GroupVersionResource, namespace string, snapshotName string, readyToUse bool) error {
us, err := dynCli.Resource(snapGVR).Namespace(namespace).Get(ctx, snapshotName, metav1.GetOptions{})
if err != nil {
Expand Down
7 changes: 7 additions & 0 deletions pkg/kube/snapshot/snapshot_stable.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,10 @@ func (sna *SnapshotStable) CreateContentFromSource(ctx context.Context, source *
func (sna *SnapshotStable) WaitOnReadyToUse(ctx context.Context, snapshotName, namespace string) error {
return waitOnReadyToUse(ctx, sna.dynCli, VolSnapGVR, snapshotName, namespace)
}

func (sna *SnapshotStable) GroupVersion(ctx context.Context) schema.GroupVersion {
return schema.GroupVersion{
Group: GroupName,
Version: Version,
}
}

0 comments on commit 5f409fa

Please sign in to comment.