-
Notifications
You must be signed in to change notification settings - Fork 1
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
CreateVolume() clone flow might create volume from wrong snapshot #55
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,10 @@ package driver | |
import ( | ||
"context" | ||
"fmt" | ||
"math/rand" | ||
"strconv" | ||
"strings" | ||
"time" | ||
|
||
"github.com/container-storage-interface/spec/lib/go/csi" | ||
guuid "github.com/google/uuid" | ||
|
@@ -452,7 +455,11 @@ func (d *Driver) doCreateVolume( //revive:disable-line:unused-receiver | |
// snapshot deletion strategy this will also prevent creation of | ||
// identically named clone volumes in the future due to snapshot name | ||
// collisions (see note below on cleanup). | ||
snapName := "snapshot-" + req.Name | ||
|
||
// Appending current time-unit and randome number to the snapshot name to make it unique. | ||
// e.g snapshot-<volume-name>-<current-time> <31-bit non-negative-int> snapshot-volName-YYYYMMDDHHMMSS-1279846997 | ||
formattedTime := time.Now().Format("20060102150405") | ||
snapName := "snapshot-" + req.Name + "-" + formattedTime + "-" + strconv.Itoa(int(rand.Int31())) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. UUIDv7 is exactly doing this: https://uuid7.com/ and the uuid library you are using is already capable of generating them: https://github.com/google/uuid/blob/master/version7.go In my POV this would make the code easier to understand and also follow a well known and documented standard. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see your point. |
||
log.Infof("auto-creating intermediate snapshot '%s' to clone from a volume", snapName) | ||
snap, err := doCreateSnapshot(ctx, log, clnt, snapName, *srcVid, | ||
"auto-snap for clone, by: LB CSI") | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Enhancement of Snapshot Name Uniqueness
The addition of a timestamp and a random integer to the snapshot name is a robust solution to ensure uniqueness. This change effectively addresses the issue of potential collisions in snapshot names which could lead to creating volumes from incorrect snapshots.
Suggestion for Improvement:
Consider extracting the snapshot name construction into a separate function for better readability and maintainability. This would also make unit testing easier.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see comments in ticket, lets see if we can find/address the skup on the delete