Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add VolumeSnapshotContent APIs to snapshot pkg #687

Merged
merged 1 commit into from
May 28, 2020
Merged

Conversation

vkamra
Copy link

@vkamra vkamra commented May 28, 2020

Change Overview

Adds API support to operate on VolumeSnapshotContent.
Specifically, it adds a CreateContentFromSource and DeleteContent API.

This supports use cases where a namespaced VolumeSnapshot object
is not required.

Additional changes:

  • Return the snapshot class deletion policy from GetVolumeSnapshotClass
  • Modify Delete to also delete the underlying VolumeSnapshotContent.
    This supports cases where the VolumeSnapshot is marked Retain
  • Fix a unit test bug which caused the test to fail on DigitalOcean (no
    restore size set)

Pull request type

Please check the type of change your PR introduces:

  • 🚧 Work in Progress
  • 🌈 Refactoring (no functional changes, no api changes)
  • 🐹 Trivial/Minor
  • 🐛 Bugfix
  • 🌻 Feature
  • 🗺️ Documentation
  • 🤖 Test

Test Plan

  • 💪 Manual
  • ⚡ Unit test
  • 💚 E2E

@@ -320,7 +321,7 @@ func (s *SnapshotTestSuite) testVolumeSnapshot(c *C, snapshotter snapshot.Snapsh
VolumeName: volumeCloneName,
StorageClassName: "",
SnapshotName: snapshotCloneName,
RestoreSize: nil,
RestoreSize: &sizeOriginal,
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixes test that was failing on DigitalOcean

if err != nil {
return "", "", err
}
deletionPolicy, err := sna.getDeletionPolicyFromClass(scName)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Modified to also return deletionPolicy

@@ -97,11 +107,28 @@ func (sna *SnapshotAlpha) Get(ctx context.Context, name, namespace string) (*v1a

// Delete will delete the VolumeSnapshot and returns any error as a result.
func (sna *SnapshotAlpha) Delete(ctx context.Context, name, namespace string) error {
snap, err := sna.Get(ctx, name, namespace)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete now also gets and deletes the underlying VolumeSnapshotContent.

NotFound errors are ignored

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should modify the comment in the interface and probably here too.

return sna.DeleteContent(ctx, snap.Spec.SnapshotContentName)
}

// DeleteContent will delete the specified VolumeSnapshotContent
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New API - DeleteContent

@@ -171,6 +197,15 @@ func (sna *SnapshotAlpha) CreateFromSource(ctx context.Context, source *Source,
return sna.WaitOnReadyToUse(ctx, snapshotName, namespace)
}

// CreateContentFromSource will create a 'VolumesnaphotContent' for the underlying snapshot source.
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New API - CreateContentFromSource. Allows caller to create just a VolumeSnapshotContent if needed.

Copy link
Contributor

@carlbraganza carlbraganza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor nits

@@ -52,6 +53,10 @@ type Snapshotter interface {
// 'name' is the name of the VolumeSnapshot that will be deleted.
// 'namespace' is the namespace of the VolumeSnapshot that will be deleted.
Delete(ctx context.Context, name, namespace string) error
// Delete will delete the VolumeSnapshot and returns any error as a result.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] DeleteContent / VolumeSnapshotContent

Comment on lines +85 to +86
// 'snapshotName' is the name of the snapshot that will be reference the VSC
// 'namespace' is the namespace of the snapshot.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] snapshot => VolumeSnapshot

//
// 'annotationKey' is the annotation key which has to be present on VolumeSnapshotClass.
// 'annotationValue' is the value for annotationKey in VolumeSnapshotClass spec.
// 'storageClassName' is the name of the storageClass that shares the same driver as the VolumeSnapshotClass.
// This returns error if no VolumeSnapshotClass found.
GetVolumeSnapshotClass(annotationKey, annotationValue, storageClassName string) (string, error)
GetVolumeSnapshotClass(annotationKey, annotationValue, storageClassName string) (string, string, error)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Q: Since the lookup is via an annotation, how do you know that at most 1 object will be found?
The code returns the first matching VolumeSnapshotClass.

@@ -97,11 +107,28 @@ func (sna *SnapshotAlpha) Get(ctx context.Context, name, namespace string) (*v1a

// Delete will delete the VolumeSnapshot and returns any error as a result.
func (sna *SnapshotAlpha) Delete(ctx context.Context, name, namespace string) error {
snap, err := sna.Get(ctx, name, namespace)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should modify the comment in the interface and probably here too.

@mergify mergify bot merged commit 9c5ba61 into master May 28, 2020
@mergify mergify bot deleted the snapshot_api_updates branch May 28, 2020 04:04
@bathina2
Copy link
Contributor

Little late but looks good.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants