Skip to content

Commit

Permalink
Add SanitizeTags to stable CreateFromSource
Browse files Browse the repository at this point in the history
  • Loading branch information
AKhoria committed Aug 17, 2023
1 parent 8161996 commit e783b35
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pkg/kube/snapshot/snapshot_stable.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package snapshot
import (
"context"

"github.com/kanisterio/kanister/pkg/blockstorage"
v1 "github.com/kubernetes-csi/external-snapshotter/client/v4/apis/volumesnapshot/v1"
"github.com/pkg/errors"
apierrors "k8s.io/apimachinery/pkg/api/errors"
Expand Down Expand Up @@ -126,7 +127,7 @@ func (sna *SnapshotStable) CreateFromSource(ctx context.Context, source *Source,
return errors.Wrap(err, "Failed to get DeletionPolicy from VolumeSnapshotClass")
}
contentName := snapshotName + "-content-" + string(uuid.NewUUID())
snap := UnstructuredVolumeSnapshot(VolSnapGVR, snapshotName, namespace, "", contentName, source.VolumeSnapshotClassName, labels)
snap := UnstructuredVolumeSnapshot(VolSnapGVR, snapshotName, namespace, "", contentName, source.VolumeSnapshotClassName, blockstorage.SanitizeTags(labels))

if err := sna.CreateContentFromSource(ctx, source, contentName, snapshotName, namespace, deletionPolicy); err != nil {
return err
Expand Down
42 changes: 42 additions & 0 deletions pkg/kube/snapshot/snapshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -998,6 +998,48 @@ func (s *SnapshotTestSuite) TestCreateFromSourceBeta(c *C) {
c.Assert(err, NotNil)
}

func (s *SnapshotTestSuite) TestCreateFromSource(c *C) {
ctx := context.Background()
namespace := "namespace"
existingSnapshotName := "existingSnapname"
snapshotName := "snapname"
snapshotClass := "volSnapClass"
driver := "driver"
labels := map[string]string{"Label": "1/"}
source := &snapshot.Source{
Handle: namespace,
Driver: driver,
VolumeSnapshotClassName: snapshotClass,
}
scheme := runtime.NewScheme()

volSnap := snapshot.UnstructuredVolumeSnapshot(v1alpha1.VolSnapGVR, existingSnapshotName, namespace, "pvcName", "content", snapshotClass, nil)
volSnapClass := snapshot.UnstructuredVolumeSnapshotClass(v1alpha1.VolSnapClassGVR, snapshotClass, "driver", "DELETE", nil)
dynCli := dynfake.NewSimpleDynamicClient(scheme, volSnap, volSnapClass)
kubeCli := fake.NewSimpleClientset()
snapshoterAlpha := snapshot.NewSnapshotAlpha(kubeCli, dynCli)

volSnap = snapshot.UnstructuredVolumeSnapshot(v1beta1.VolSnapGVR, existingSnapshotName, namespace, "pvcName", "content", snapshotClass, nil)
volSnapClass = snapshot.UnstructuredVolumeSnapshotClass(v1beta1.VolSnapClassGVR, snapshotClass, "driver", "DELETE", nil)
dynCli = dynfake.NewSimpleDynamicClient(scheme, volSnap, volSnapClass)
kubeCli = fake.NewSimpleClientset()
snapshoterBeta := snapshot.NewSnapshotBeta(kubeCli, dynCli)

volSnap = snapshot.UnstructuredVolumeSnapshot(snapshot.VolSnapGVR, existingSnapshotName, namespace, "pvcName", "content", snapshotClass, nil)
volSnapClass = snapshot.UnstructuredVolumeSnapshotClass(snapshot.VolSnapClassGVR, snapshotClass, "driver", "DELETE", nil)
dynCli = dynfake.NewSimpleDynamicClient(scheme, volSnap, volSnapClass)
kubeCli = fake.NewSimpleClientset()
snapshoterStable := snapshot.NewSnapshotStable(kubeCli, dynCli)

for _, snapshoter := range []snapshot.Snapshotter{snapshoterAlpha, snapshoterBeta, snapshoterStable} {
err := snapshoter.CreateFromSource(ctx, source, snapshotName, namespace, false, labels)
foundSns, err := snapshoter.List(ctx, namespace, labels)
c.Assert(err, IsNil)
c.Assert(foundSns.Items, HasLen, 1)
c.Assert(foundSns.Items[0].Name, Equals, snapshotName)
}
}

func (s *SnapshotTestSuite) TestCreateFromSourceStable(c *C) {
ctx := context.Background()
namespace := "namespace"
Expand Down

0 comments on commit e783b35

Please sign in to comment.