Skip to content

Commit

Permalink
Support annotation in VolumeSnapshot and VolumeSnapshotContent resour…
Browse files Browse the repository at this point in the history
…ces (#2986)

Co-authored-by: Vivek Singh <[email protected]>
  • Loading branch information
saima-s and viveksinghggits authored Aug 5, 2024
1 parent be93c81 commit ea6cb88
Show file tree
Hide file tree
Showing 13 changed files with 487 additions and 225 deletions.
8 changes: 7 additions & 1 deletion pkg/function/create_csi_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,13 @@ func (*createCSISnapshotFunc) Arguments() []string {
}

func createCSISnapshot(ctx context.Context, snapshotter snapshot.Snapshotter, name, namespace, pvc, snapshotClass string, wait bool, labels map[string]string) (*v1.VolumeSnapshot, error) {
if err := snapshotter.Create(ctx, name, namespace, pvc, &snapshotClass, wait, labels); err != nil {
snapshotMeta := snapshot.ObjectMeta{
Name: name,
Namespace: namespace,
Labels: labels,
Annotations: nil,
}
if err := snapshotter.Create(ctx, pvc, &snapshotClass, wait, snapshotMeta); err != nil {
return nil, err
}
vs, err := snapshotter.Get(ctx, name, namespace)
Expand Down
7 changes: 6 additions & 1 deletion pkg/function/create_csi_snapshot_static.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,12 @@ func createCSISnapshotStatic(
Driver: driver,
VolumeSnapshotClassName: snapshotClass,
}
if err := snapshotter.CreateFromSource(ctx, source, name, namespace, wait, nil); err != nil {
snapshotMeta := snapshot.ObjectMeta{
Name: name,
Namespace: namespace,
}
snapshotContentMeta := snapshot.ObjectMeta{}
if err := snapshotter.CreateFromSource(ctx, source, wait, snapshotMeta, snapshotContentMeta); err != nil {
return nil, err
}

Expand Down
10 changes: 5 additions & 5 deletions pkg/function/delete_csi_snapshot_content_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ func (testSuite *DeleteCSISnapshotContentTestSuite) TestDeleteCSISnapshotContent
Driver: driver,
VolumeSnapshotClassName: snapshotClassName,
}
err = fakeSnapshotter.CreateContentFromSource(ctx, source,
snapshotContentName,
snapshotName,
snapshotNamespace,
deletionPolicy)
fakeSnapshotContentMeta := snapshot.ObjectMeta{
Name: snapshotContentName,
}
err = fakeSnapshotter.CreateContentFromSource(ctx, source, snapshotName,
snapshotNamespace, deletionPolicy, fakeSnapshotContentMeta)
c.Assert(err, IsNil)

gv := strings.Split(api.GroupVersion, "/")
Expand Down
7 changes: 5 additions & 2 deletions pkg/function/delete_csi_snapshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,11 @@ func (testSuite *DeleteCSISnapshotTestSuite) TestDeleteCSISnapshot(c *C) {
}
_, err = fakeCli.CoreV1().PersistentVolumeClaims(testSuite.namespace).Create(ctx, originalPVC, metav1.CreateOptions{})
c.Assert(err, IsNil)

err = fakeSnapshotter.Create(ctx, testSuite.snapName, testSuite.namespace, testSuite.pvcName, &testSuite.volumeSnapshotClass, false, nil)
fakeSnapshotMeta := snapshot.ObjectMeta{
Name: testSuite.snapName,
Namespace: testSuite.namespace,
}
err = fakeSnapshotter.Create(ctx, testSuite.pvcName, &testSuite.volumeSnapshotClass, false, fakeSnapshotMeta)
c.Assert(err, IsNil)

vs, err := fakeSnapshotter.Get(ctx, testSuite.snapName, testSuite.namespace)
Expand Down
7 changes: 5 additions & 2 deletions pkg/function/restore_csi_snapshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,11 @@ func (testSuite *RestoreCSISnapshotTestSuite) TestRestoreCSISnapshot(c *C) {

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

err = fakeSnapshotter.Create(ctx, testSuite.snapName, testSuite.namespace, testSuite.pvcName, &testSuite.volumeSnapshotClass, false, nil)
fakeSnapshotMeta := snapshot.ObjectMeta{
Name: testSuite.snapName,
Namespace: testSuite.namespace,
}
err = fakeSnapshotter.Create(ctx, testSuite.pvcName, &testSuite.volumeSnapshotClass, false, fakeSnapshotMeta)
c.Assert(err, IsNil)

vs, err := fakeSnapshotter.Get(ctx, testSuite.snapName, testSuite.namespace)
Expand Down
104 changes: 52 additions & 52 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.

Loading

0 comments on commit ea6cb88

Please sign in to comment.