Skip to content

Commit

Permalink
Remove support for Snapshot alpha and beta APIs (#3309)
Browse files Browse the repository at this point in the history
Signed-off-by: Prasad Ghangal <[email protected]>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
PrasadG193 and mergify[bot] authored Jan 6, 2025
1 parent 276f676 commit 0abc731
Show file tree
Hide file tree
Showing 17 changed files with 636 additions and 2,347 deletions.
10 changes: 1 addition & 9 deletions pkg/function/create_csi_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"fmt"
"time"

"github.com/kanisterio/errkit"
v1 "github.com/kubernetes-csi/external-snapshotter/client/v4/apis/volumesnapshot/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/rand"
Expand Down Expand Up @@ -100,14 +99,7 @@ func (c *createCSISnapshotFunc) Exec(ctx context.Context, tp param.TemplateParam
if err != nil {
return nil, err
}
snapshotter, err := snapshot.NewSnapshotter(kubeCli, dynCli)
if err != nil {
if errkit.Is(context.DeadlineExceeded, err) {
timeoutMsg := "SnapshotContent not provisioned within given timeout. Please check if CSI driver is installed correctly and supports VolumeSnapshot feature"
return nil, errkit.Wrap(err, timeoutMsg)
}
return nil, err
}
snapshotter := snapshot.NewSnapshotter(kubeCli, dynCli)
// waitForReady is set to true by default because snapshot information is needed as output artifacts
waitForReady := true
vs, err := createCSISnapshot(ctx, snapshotter, name, namespace, pvc, snapshotClass, waitForReady, labels)
Expand Down
6 changes: 1 addition & 5 deletions pkg/function/create_csi_snapshot_static.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,7 @@ func (c *createCSISnapshotStaticFunc) Exec(ctx context.Context, tp param.Templat
return nil, err
}

snapshotter, err := snapshot.NewSnapshotter(kubeCli, dynCli)
if err != nil {
return nil, err
}

snapshotter := snapshot.NewSnapshotter(kubeCli, dynCli)
// waitForReady is set to true by default because snapshot information is needed as output artifacts
waitForReady := true
vs, err := createCSISnapshotStatic(ctx, snapshotter, name, namespace, driver, snapshotHandle, snapshotClass, waitForReady)
Expand Down
108 changes: 44 additions & 64 deletions pkg/function/create_csi_snapshot_static_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,80 +39,60 @@ func (testSuite *CreateCSISnapshotStaticTestSuite) SetUpSuite(c *check.C) {}
func (testSuite *CreateCSISnapshotStaticTestSuite) TestCreateCSISnapshotStatic(c *check.C) {
const (
snapshotName = "test-snapshot"
namespace = "test-namespace"
deletionPolicy = "Retain"
driver = "test-driver"
snapshotClass = "test-snapshot-class"
snapshotHandle = "test-snapshot-handle"
)

for _, api := range []*metav1.APIResourceList{
{
TypeMeta: metav1.TypeMeta{
Kind: snapshot.VolSnapKind,
APIVersion: "v1alpha1",
},
GroupVersion: fmt.Sprintf("%s/v1alpha1", snapshot.GroupName),
api := &metav1.APIResourceList{
TypeMeta: metav1.TypeMeta{
Kind: snapshot.VolSnapKind,
APIVersion: "v1",
},
{
TypeMeta: metav1.TypeMeta{
Kind: snapshot.VolSnapKind,
APIVersion: "v1beta1",
},
GroupVersion: fmt.Sprintf("%s/v1beta1", snapshot.GroupName),
},
{
TypeMeta: metav1.TypeMeta{
Kind: snapshot.VolSnapKind,
APIVersion: "v1",
},
GroupVersion: fmt.Sprintf("%s/%s", snapshot.GroupName, snapshot.Version),
},
} {
ctx := context.Background()
fakeCli := fake.NewSimpleClientset()
fakeCli.Resources = []*metav1.APIResourceList{api}
GroupVersion: fmt.Sprintf("%s/%s", snapshot.GroupName, snapshot.Version),
}
ctx := context.Background()
fakeCli := fake.NewSimpleClientset()
fakeCli.Resources = []*metav1.APIResourceList{api}

scheme := runtime.NewScheme()
dynCli := dynfake.NewSimpleDynamicClient(scheme)
fakeSnapshotter, err := snapshot.NewSnapshotter(fakeCli, dynCli)
c.Assert(err, check.IsNil)
scheme := runtime.NewScheme()
dynCli := dynfake.NewSimpleDynamicClient(scheme)
fakeSnapshotter := snapshot.NewSnapshotter(fakeCli, dynCli)

namespace := &corev1.Namespace{
ObjectMeta: metav1.ObjectMeta{
Name: namespace,
},
}
_, err = fakeCli.CoreV1().Namespaces().Create(ctx, namespace, metav1.CreateOptions{})
c.Assert(err, check.IsNil)
namespace := &corev1.Namespace{
ObjectMeta: metav1.ObjectMeta{
Name: "test-namespace",
},
}
_, err := fakeCli.CoreV1().Namespaces().Create(ctx, namespace, metav1.CreateOptions{})
c.Assert(err, check.IsNil)

gv := strings.Split(api.GroupVersion, "/")
gvr := schema.GroupVersionResource{
Group: gv[0],
Version: gv[1],
Resource: snapshot.VolumeSnapshotClassResourcePlural,
}
gv := strings.Split(api.GroupVersion, "/")
gvr := schema.GroupVersionResource{
Group: gv[0],
Version: gv[1],
Resource: snapshot.VolumeSnapshotClassResourcePlural,
}

snapshotClass := snapshot.UnstructuredVolumeSnapshotClass(
gvr,
snapshotClass,
driver,
deletionPolicy,
nil)
_, err = dynCli.Resource(gvr).Create(ctx, snapshotClass, metav1.CreateOptions{})
c.Assert(err, check.IsNil)
snapshotClass := snapshot.UnstructuredVolumeSnapshotClass(
gvr,
snapshotClass,
driver,
deletionPolicy,
nil)
_, err = dynCli.Resource(gvr).Create(ctx, snapshotClass, metav1.CreateOptions{})
c.Assert(err, check.IsNil)

_, err = createCSISnapshotStatic(
ctx,
fakeSnapshotter,
snapshotName,
namespace.GetName(),
driver,
snapshotHandle,
snapshotClass.GetName(), false)
c.Assert(err, check.IsNil)
_, err = createCSISnapshotStatic(
ctx,
fakeSnapshotter,
snapshotName,
namespace.GetName(),
driver,
snapshotHandle,
snapshotClass.GetName(), false)
c.Assert(err, check.IsNil)

err = fakeCli.CoreV1().Namespaces().Delete(ctx, namespace.GetName(), metav1.DeleteOptions{})
c.Assert(err, check.IsNil)
}
err = fakeCli.CoreV1().Namespaces().Delete(ctx, namespace.GetName(), metav1.DeleteOptions{})
c.Assert(err, check.IsNil)
}
56 changes: 19 additions & 37 deletions pkg/function/create_csi_snapshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,49 +60,31 @@ func (testSuite *CreateCSISnapshotTestSuite) SetUpSuite(c *check.C) {
}

func (testSuite *CreateCSISnapshotTestSuite) TestCreateCSISnapshot(c *check.C) {
for _, apiResourceList := range []*metav1.APIResourceList{
{
TypeMeta: metav1.TypeMeta{
Kind: "VolumeSnapshot",
APIVersion: "v1alpha1",
},
GroupVersion: "snapshot.storage.k8s.io/v1alpha1",
},
{
TypeMeta: metav1.TypeMeta{
Kind: "VolumeSnapshot",
APIVersion: "v1beta1",
},
GroupVersion: "snapshot.storage.k8s.io/v1beta1",
api := &metav1.APIResourceList{
TypeMeta: metav1.TypeMeta{
Kind: "VolumeSnapshot",
APIVersion: "v1",
},
{
TypeMeta: metav1.TypeMeta{
Kind: "VolumeSnapshot",
APIVersion: "v1",
},
GroupVersion: "snapshot.storage.k8s.io/v1",
},
} {
ctx := context.Background()
fakeCli := fake.NewSimpleClientset()
fakeCli.Resources = []*metav1.APIResourceList{apiResourceList}
GroupVersion: "snapshot.storage.k8s.io/v1",
}
ctx := context.Background()
fakeCli := fake.NewSimpleClientset()
fakeCli.Resources = []*metav1.APIResourceList{api}

_, err := fakeCli.CoreV1().Namespaces().Create(ctx, &corev1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: testSuite.namespace}}, metav1.CreateOptions{})
c.Assert(err, check.IsNil)
_, err := fakeCli.CoreV1().Namespaces().Create(ctx, &corev1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: testSuite.namespace}}, metav1.CreateOptions{})
c.Assert(err, check.IsNil)

scheme := runtime.NewScheme()
fakeSnapshotter, err := snapshot.NewSnapshotter(fakeCli, dynfake.NewSimpleDynamicClient(scheme))
c.Assert(err, check.IsNil)
scheme := runtime.NewScheme()
fakeSnapshotter := snapshot.NewSnapshotter(fakeCli, dynfake.NewSimpleDynamicClient(scheme))

_, err = fakeCli.CoreV1().PersistentVolumeClaims(testSuite.namespace).Create(ctx, getPVCManifest(testSuite.pvcName, testSuite.storageClass), metav1.CreateOptions{})
c.Assert(err, check.IsNil)
_, err = fakeCli.CoreV1().PersistentVolumeClaims(testSuite.namespace).Create(ctx, getPVCManifest(testSuite.pvcName, testSuite.storageClass), metav1.CreateOptions{})
c.Assert(err, check.IsNil)

_, err = createCSISnapshot(ctx, fakeSnapshotter, testSuite.snapName, testSuite.namespace, testSuite.pvcName, testSuite.volumeSnapshotClass, false, nil)
c.Assert(err, check.IsNil)
_, err = createCSISnapshot(ctx, fakeSnapshotter, testSuite.snapName, testSuite.namespace, testSuite.pvcName, testSuite.volumeSnapshotClass, false, nil)
c.Assert(err, check.IsNil)

err = fakeCli.CoreV1().Namespaces().Delete(ctx, testSuite.namespace, metav1.DeleteOptions{})
c.Assert(err, check.IsNil)
}
err = fakeCli.CoreV1().Namespaces().Delete(ctx, testSuite.namespace, metav1.DeleteOptions{})
c.Assert(err, check.IsNil)
}

func getPVCManifest(pvcName, storageClassName string) *corev1.PersistentVolumeClaim {
Expand Down
5 changes: 1 addition & 4 deletions pkg/function/delete_csi_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,7 @@ func (d *deleteCSISnapshotFunc) Exec(ctx context.Context, tp param.TemplateParam
if err != nil {
return nil, err
}
snapshotter, err := snapshot.NewSnapshotter(kubeCli, dynCli)
if err != nil {
return nil, err
}
snapshotter := snapshot.NewSnapshotter(kubeCli, dynCli)
if _, err := deleteCSISnapshot(ctx, snapshotter, name, namespace); err != nil {
return nil, err
}
Expand Down
6 changes: 1 addition & 5 deletions pkg/function/delete_csi_snapshot_content.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,7 @@ func (d *deleteCSISnapshotContentFunc) Exec(ctx context.Context, tp param.Templa
return nil, err
}

snapshotter, err := snapshot.NewSnapshotter(kubeCli, dynCli)
if err != nil {
return nil, err
}

snapshotter := snapshot.NewSnapshotter(kubeCli, dynCli)
return nil, deleteCSISnapshotContent(ctx, snapshotter, name)
}

Expand Down
88 changes: 35 additions & 53 deletions pkg/function/delete_csi_snapshot_content_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,64 +45,46 @@ func (testSuite *DeleteCSISnapshotContentTestSuite) TestDeleteCSISnapshotContent
driver = "test-delete-driver"
handle = "test-delete-handle"
)
for _, api := range []*metav1.APIResourceList{
{
TypeMeta: metav1.TypeMeta{
Kind: snapshot.VolSnapContentKind,
APIVersion: "v1alpha1",
},
GroupVersion: fmt.Sprintf("%s/v1alpha1", snapshot.GroupName),
api := &metav1.APIResourceList{
TypeMeta: metav1.TypeMeta{
Kind: snapshot.VolSnapContentKind,
APIVersion: "v1",
},
{
TypeMeta: metav1.TypeMeta{
Kind: snapshot.VolSnapContentKind,
APIVersion: "v1beta1",
},
GroupVersion: fmt.Sprintf("%s/v1beta1", snapshot.GroupName),
},
{
TypeMeta: metav1.TypeMeta{
Kind: snapshot.VolSnapContentKind,
APIVersion: "v1",
},
GroupVersion: fmt.Sprintf("%s/%s", snapshot.GroupName, snapshot.Version),
},
} {
ctx := context.Background()
fakeCli := fake.NewSimpleClientset()
fakeCli.Resources = []*metav1.APIResourceList{api}
GroupVersion: fmt.Sprintf("%s/%s", snapshot.GroupName, snapshot.Version),
}
ctx := context.Background()
fakeCli := fake.NewSimpleClientset()
fakeCli.Resources = []*metav1.APIResourceList{api}

scheme := runtime.NewScheme()
dynCli := dynfake.NewSimpleDynamicClient(scheme)
fakeSnapshotter, err := snapshot.NewSnapshotter(fakeCli, dynCli)
c.Assert(err, check.IsNil)
scheme := runtime.NewScheme()
dynCli := dynfake.NewSimpleDynamicClient(scheme)
fakeSnapshotter := snapshot.NewSnapshotter(fakeCli, dynCli)

source := &snapshot.Source{
Handle: snapshotNamespace,
Driver: driver,
VolumeSnapshotClassName: snapshotClassName,
}
fakeSnapshotContentMeta := snapshot.ObjectMeta{
Name: snapshotContentName,
}
err = fakeSnapshotter.CreateContentFromSource(ctx, source, snapshotName,
snapshotNamespace, deletionPolicy, fakeSnapshotContentMeta)
c.Assert(err, check.IsNil)
source := &snapshot.Source{
Handle: snapshotNamespace,
Driver: driver,
VolumeSnapshotClassName: snapshotClassName,
}
fakeSnapshotContentMeta := snapshot.ObjectMeta{
Name: snapshotContentName,
}
err := fakeSnapshotter.CreateContentFromSource(ctx, source, snapshotName,
snapshotNamespace, deletionPolicy, fakeSnapshotContentMeta)
c.Assert(err, check.IsNil)

gv := strings.Split(api.GroupVersion, "/")
gvr := schema.GroupVersionResource{
Group: gv[0],
Version: gv[1],
Resource: snapshot.VolumeSnapshotContentResourcePlural,
}
gv := strings.Split(api.GroupVersion, "/")
gvr := schema.GroupVersionResource{
Group: gv[0],
Version: gv[1],
Resource: snapshot.VolumeSnapshotContentResourcePlural,
}

_, err = dynCli.Resource(gvr).Get(ctx, snapshotContentName, metav1.GetOptions{})
c.Assert(err, check.IsNil)
_, err = dynCli.Resource(gvr).Get(ctx, snapshotContentName, metav1.GetOptions{})
c.Assert(err, check.IsNil)

err = deleteCSISnapshotContent(ctx, fakeSnapshotter, snapshotContentName)
c.Assert(err, check.IsNil)
err = deleteCSISnapshotContent(ctx, fakeSnapshotter, snapshotContentName)
c.Assert(err, check.IsNil)

_, err = dynCli.Resource(gvr).Get(ctx, snapshotContentName, metav1.GetOptions{})
c.Assert(err, check.NotNil)
}
_, err = dynCli.Resource(gvr).Get(ctx, snapshotContentName, metav1.GetOptions{})
c.Assert(err, check.NotNil)
}
3 changes: 1 addition & 2 deletions pkg/function/delete_csi_snapshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ func (testSuite *DeleteCSISnapshotTestSuite) TestDeleteCSISnapshot(c *check.C) {
c.Assert(err, check.IsNil)

scheme := runtime.NewScheme()
fakeSnapshotter, err := snapshot.NewSnapshotter(fakeCli, dynfake.NewSimpleDynamicClient(scheme))
c.Assert(err, check.IsNil)
fakeSnapshotter := snapshot.NewSnapshotter(fakeCli, dynfake.NewSimpleDynamicClient(scheme))

originalPVC := &corev1.PersistentVolumeClaim{
ObjectMeta: metav1.ObjectMeta{
Expand Down
3 changes: 1 addition & 2 deletions pkg/function/restore_csi_snapshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ func (testSuite *RestoreCSISnapshotTestSuite) TestRestoreCSISnapshot(c *check.C)
c.Assert(err, check.IsNil)

scheme := runtime.NewScheme()
fakeSnapshotter, err := snapshot.NewSnapshotter(fakeCli, dynfake.NewSimpleDynamicClient(scheme))
c.Assert(err, check.IsNil)
fakeSnapshotter := snapshot.NewSnapshotter(fakeCli, dynfake.NewSimpleDynamicClient(scheme))

originalPVC := getOriginalPVCManifest(testSuite.pvcName, testSuite.storageClass)
createPVC(c, testSuite.namespace, originalPVC, fakeCli)
Expand Down
Loading

0 comments on commit 0abc731

Please sign in to comment.