-
Notifications
You must be signed in to change notification settings - Fork 81
feat: copy labels from Disk to Snapshot #178
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
base: main
Are you sure you want to change the base?
Conversation
d270fe7
to
8330be2
Compare
this will be approved? really relevant to have in the plugin, to have this labels a good practice. @reasonerjt @blackpiglet |
+1 went looking for this today, would be a great feature in the plugin |
+1 we need to trace snapshots |
please create issue if there isnt one on tanzu/velero repo and add changelogs under this path
format name |
Hi, any chance this can be updated and merged? Having labels applied to our snapshots would be very beneficial. |
Sorry this one got lost in my inbox, issue is created here, updated with the release notes, and rebased. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #178 +/- ##
==========================================
- Coverage 28.39% 27.39% -1.01%
==========================================
Files 4 4
Lines 574 595 +21
==========================================
Hits 163 163
- Misses 399 420 +21
Partials 12 12 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
@opdude One thing I need to mention here is that Velero team lost the GCP resource to verify the PR already, so please ensure the change works in your environment. |
We've been running my patch in production since this PR was created, I'd say it works :). But as stated before it requires the updated permissions which you may want to warn users about. |
Would it be possible to gracefully fallback to not doing this? Or do some kind of |
Not a blocker, just perhaps not included in a patch version as this seems to be breaking change. |
I'm not sure there is a GCP equivalent unfortunately. Possibly the best options are either to change the version so it can be in whatever you deem necessary for a breaking change or offer the ability to turn this on/off? Not sure what would be best for you. |
You could wrap the snapshot creation with err handling, and catch lack of label perm, then create snapshot without labels. |
Here's a code example for implementing graceful error handling when the func (b *VolumeSnapshotter) createSnapshot(snapshotName, volumeID, volumeAZ string, tags map[string]string) (string, error) {
// ... existing code ...
snapshot := &compute.Snapshot{
Name: snapshotName,
Description: getSnapshotTags(tags, disk.Description, b.log),
SourceDisk: disk.SelfLink,
SnapshotType: b.snapshotType,
Labels: disk.Labels,
}
if b.snapshotLocation != "" {
snapshot.StorageLocations = []string{b.snapshotLocation}
}
// Try creating snapshot with labels
op, err := b.gce.Snapshots().Insert(b.projectID, snapshot).Do()
// If we get a permission error for labels, retry without them
if err != nil && isLabelPermissionError(err) {
b.log.WithError(err).Warn("Missing compute.snapshots.setLabels permission, creating snapshot without labels")
// Retry without labels
snapshot.Labels = nil
op, err = b.gce.Snapshots().Insert(b.projectID, snapshot).Do()
if err != nil {
return "", errors.WithStack(err)
}
} else if err != nil {
return "", errors.WithStack(err)
}
// ... rest of the existing code ...
}
// Helper function to detect label permission errors
func isLabelPermissionError(err error) bool {
if err == nil {
return false
}
// Check for specific GCP permission error
// This might need adjustment based on actual error format
errStr := err.Error()
return strings.Contains(errStr, "compute.snapshots.setLabels") ||
(strings.Contains(errStr, "permission") && strings.Contains(errStr, "label"))
} The same pattern should be applied to
This graceful degradation approach allows for a smooth migration path where users can add the permission when ready without breaking existing functionality. |
It can be very useful to be able to track your snapshots using the same labels are you have on your original disks, this PR copies over all of the labels of the disk and adds a new permission requirement of `compute.snapshots.setLabels` to allow for that however if it's not available it will fall back to the previous behaviour. Signed-off-by: Daniel Hobley <[email protected]>
686f431
to
45934b7
Compare
Sorry for the delay here. I've made the changes and tested on our setup both with and without the permissions. |
It can be very useful to be able to track your snapshots using the same labels are you have on your original disks, this PR copies over all of the labels of the disk and adds a new permission requirement of
compute.snapshots.setLabels
to allow for that.