Skip to content

Commit

Permalink
Use external-snapshotter/v7
Browse files Browse the repository at this point in the history
Signed-off-by: Tamal Saha <tamal@appscode.com>
  • Loading branch information
tamalsaha committed Feb 9, 2024
1 parent c221c37 commit 2d78596
Show file tree
Hide file tree
Showing 61 changed files with 1,901 additions and 2,279 deletions.
6 changes: 3 additions & 3 deletions go.mod
Expand Up @@ -5,7 +5,7 @@ go 1.21.7
require (
github.com/go-sql-driver/mysql v1.7.1
github.com/gogo/protobuf v1.3.2
github.com/kubernetes-csi/external-snapshotter/client/v4 v4.2.0
github.com/kubernetes-csi/external-snapshotter/client/v7 v7.0.0
github.com/onsi/ginkgo/v2 v2.14.0
github.com/onsi/gomega v1.30.0
github.com/pkg/errors v0.9.1
Expand Down Expand Up @@ -37,13 +37,13 @@ require (
k8s.io/kubernetes v1.13.0
kmodules.xyz/client-go v0.29.6
kmodules.xyz/constants v0.0.0-20230304030334-d2d1f28732a5
kmodules.xyz/csi-utils v0.25.4
kmodules.xyz/csi-utils v0.29.1
kmodules.xyz/custom-resources v0.29.1
kmodules.xyz/objectstore-api v0.29.1
kmodules.xyz/offshoot-api v0.29.0
kmodules.xyz/openshift v0.29.0
kmodules.xyz/prober v0.29.0
kmodules.xyz/webhook-runtime v0.29.1
kmodules.xyz/webhook-runtime v0.29.0
sigs.k8s.io/controller-runtime v0.17.0
stash.appscode.dev/apimachinery v0.32.1-0.20240209175028-1fb8e3376f2c
)
Expand Down
92 changes: 6 additions & 86 deletions go.sum

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions pkg/cmds/create_volumesnapshot.go
Expand Up @@ -31,8 +31,8 @@ import (
"stash.appscode.dev/stash/pkg/status"
"stash.appscode.dev/stash/pkg/volumesnapshot"

vsapi "github.com/kubernetes-csi/external-snapshotter/client/v4/apis/volumesnapshot/v1"
vscs "github.com/kubernetes-csi/external-snapshotter/client/v4/clientset/versioned"
vsapi "github.com/kubernetes-csi/external-snapshotter/client/v7/apis/volumesnapshot/v1"
vscs "github.com/kubernetes-csi/external-snapshotter/client/v7/clientset/versioned"
"github.com/spf13/cobra"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
Expand All @@ -44,7 +44,7 @@ import (
"k8s.io/klog/v2"
kmapi "kmodules.xyz/client-go/api/v1"
"kmodules.xyz/client-go/meta"
vsu "kmodules.xyz/csi-utils/volumesnapshot"
vsu "kmodules.xyz/csi-utils/volumesnapshot/v1"
prober "kmodules.xyz/prober/probe"
)

Expand Down Expand Up @@ -189,7 +189,7 @@ func (opt *VSoption) createVolumeSnapshot(bsMeta metav1.ObjectMeta, inv invoker.
// use timestamp suffix of BackupSession name as suffix of the VolumeSnapshots name
parts := strings.Split(bsMeta.Name, "-")
volumeSnapshot := opt.getVolumeSnapshotDefinition(targetInfo.Target, inv.GetObjectMeta().Namespace, pvcName, parts[len(parts)-1])
snapshot, err := vsu.CreateVolumeSnapshot(context.TODO(), opt.snapshotClient, &volumeSnapshot)
snapshot, err := opt.snapshotClient.SnapshotV1().VolumeSnapshots(volumeSnapshot.Namespace).Create(context.TODO(), &volumeSnapshot, metav1.CreateOptions{})
if err != nil {
return nil, err
}
Expand Down
6 changes: 2 additions & 4 deletions pkg/cmds/restore_volumesnapshot.go
Expand Up @@ -31,19 +31,17 @@ import (
"stash.appscode.dev/stash/pkg/status"
"stash.appscode.dev/stash/pkg/util"

vscs "github.com/kubernetes-csi/external-snapshotter/client/v4/clientset/versioned"
vscs "github.com/kubernetes-csi/external-snapshotter/client/v7/clientset/versioned"
"github.com/spf13/cobra"
"gomodules.xyz/pointer"
core "k8s.io/api/core/v1"
storage_api_v1 "k8s.io/api/storage/v1"
kerr "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/klog/v2"
"kmodules.xyz/client-go/meta"
vsu "kmodules.xyz/csi-utils/volumesnapshot"
prober "kmodules.xyz/prober/probe"
)

Expand Down Expand Up @@ -161,7 +159,7 @@ func (opt *VSoption) restoreVolumeSnapshot(targetInfo invoker.RestoreTargetInfo)
for i := range pvcList {
// verify that the respective VolumeSnapshot exist
if pvcList[i].Spec.DataSource != nil {
_, err := vsu.GetVolumeSnapshot(context.TODO(), opt.snapshotClient, types.NamespacedName{Namespace: opt.namespace, Name: pvcList[i].Spec.DataSource.Name})
_, err := opt.snapshotClient.SnapshotV1().VolumeSnapshots(opt.namespace).Get(context.TODO(), pvcList[i].Spec.DataSource.Name, metav1.GetOptions{})
if err != nil {
if kerr.IsNotFound(err) { // respective VolumeSnapshot does not exist
restoreOutput.RestoreTargetStatus.Stats = append(restoreOutput.RestoreTargetStatus.Stats, api_v1beta1.HostRestoreStats{
Expand Down
2 changes: 1 addition & 1 deletion pkg/rbac/volume_snapshot.go
Expand Up @@ -24,7 +24,7 @@ import (
api_v1alpha1 "stash.appscode.dev/apimachinery/apis/stash/v1alpha1"
api_v1beta1 "stash.appscode.dev/apimachinery/apis/stash/v1beta1"

vsapi "github.com/kubernetes-csi/external-snapshotter/client/v4/apis/volumesnapshot/v1"
vsapi "github.com/kubernetes-csi/external-snapshotter/client/v7/apis/volumesnapshot/v1"
apps "k8s.io/api/apps/v1"
core "k8s.io/api/core/v1"
rbac "k8s.io/api/rbac/v1"
Expand Down
11 changes: 5 additions & 6 deletions pkg/volumesnapshot/volumesnapshot_cleanup_policy.go
Expand Up @@ -24,13 +24,12 @@ import (
"stash.appscode.dev/apimachinery/apis/stash/v1alpha1"
"stash.appscode.dev/apimachinery/apis/stash/v1beta1"

vsapi "github.com/kubernetes-csi/external-snapshotter/client/v4/apis/volumesnapshot/v1"
vscs "github.com/kubernetes-csi/external-snapshotter/client/v4/clientset/versioned"
vsapi "github.com/kubernetes-csi/external-snapshotter/client/v7/apis/volumesnapshot/v1"
vscs "github.com/kubernetes-csi/external-snapshotter/client/v7/clientset/versioned"
kerr "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/klog/v2"
vsu "kmodules.xyz/csi-utils/volumesnapshot"
)

// Some of the code of this file has been copied from restic/restic repository.
Expand Down Expand Up @@ -146,7 +145,7 @@ func applyRetentionPolicy(policy v1alpha1.RetentionPolicy, volumeSnapshots Volum
}

for _, vs := range removed {
err := vsu.DeleteVolumeSnapshot(context.TODO(), vsClient, types.NamespacedName{Namespace: namespace, Name: vs.VolumeSnap.Name})
err := vsClient.SnapshotV1().VolumeSnapshots(namespace).Delete(context.TODO(), vs.VolumeSnap.Name, metav1.DeleteOptions{})
if err != nil {
if kerr.IsNotFound(err) {
return nil
Expand All @@ -160,7 +159,7 @@ func applyRetentionPolicy(policy v1alpha1.RetentionPolicy, volumeSnapshots Volum
}

func CleanupSnapshots(policy v1alpha1.RetentionPolicy, hostBackupStats []v1beta1.HostBackupStats, namespace string, vsClient vscs.Interface) error {
vsList, err := vsu.ListVolumeSnapshot(context.TODO(), vsClient, namespace, v1.ListOptions{})
vsList, err := vsClient.SnapshotV1().VolumeSnapshots(namespace).List(context.TODO(), v1.ListOptions{})
if err != nil {
if kerr.IsNotFound(err) || len(vsList.Items) == 0 {
return nil
Expand Down
4 changes: 2 additions & 2 deletions pkg/volumesnapshot/volumesnapshot_cleanup_policy_test.go
Expand Up @@ -25,8 +25,8 @@ import (
"stash.appscode.dev/apimachinery/apis/stash/v1alpha1"
"stash.appscode.dev/apimachinery/apis/stash/v1beta1"

vsapi "github.com/kubernetes-csi/external-snapshotter/client/v4/apis/volumesnapshot/v1"
vsfake "github.com/kubernetes-csi/external-snapshotter/client/v4/clientset/versioned/fake"
vsapi "github.com/kubernetes-csi/external-snapshotter/client/v7/apis/volumesnapshot/v1"
vsfake "github.com/kubernetes-csi/external-snapshotter/client/v7/clientset/versioned/fake"
type_util "gomodules.xyz/pointer"
"gomodules.xyz/x/strings"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down

0 comments on commit 2d78596

Please sign in to comment.