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

use GA topology labels for PVs #2219

Merged
merged 4 commits into from
Feb 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
70 changes: 69 additions & 1 deletion pkg/backup/backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1741,7 +1741,7 @@ func TestBackupWithSnapshots(t *testing.T) {
},
},
{
name: "persistent volume with zone annotation creates a snapshot",
name: "persistent volume with deprecated zone annotation creates a snapshot",
req: &Request{
Backup: defaultBackup().Result(),
SnapshotLocations: []*velerov1.VolumeSnapshotLocation{
Expand Down Expand Up @@ -1774,6 +1774,74 @@ func TestBackupWithSnapshots(t *testing.T) {
},
},
},
{
name: "persistent volume with GA zone annotation creates a snapshot",
req: &Request{
Backup: defaultBackup().Result(),
SnapshotLocations: []*velerov1.VolumeSnapshotLocation{
newSnapshotLocation("velero", "default", "default"),
},
},
apiResources: []*test.APIResource{
test.PVs(
builder.ForPersistentVolume("pv-1").ObjectMeta(builder.WithLabels("topology.kubernetes.io/zone", "zone-1")).Result(),
),
},
snapshotterGetter: map[string]velero.VolumeSnapshotter{
"default": new(fakeVolumeSnapshotter).WithVolume("pv-1", "vol-1", "zone-1", "type-1", 100, false),
},
want: []*volume.Snapshot{
{
Spec: volume.SnapshotSpec{
BackupName: "backup-1",
Location: "default",
PersistentVolumeName: "pv-1",
ProviderVolumeID: "vol-1",
VolumeAZ: "zone-1",
VolumeType: "type-1",
VolumeIOPS: int64Ptr(100),
},
Status: volume.SnapshotStatus{
Phase: volume.SnapshotPhaseCompleted,
ProviderSnapshotID: "vol-1-snapshot",
},
},
},
},
{
name: "persistent volume with both GA and deprecated zone annotation creates a snapshot and should use the GA",
req: &Request{
Backup: defaultBackup().Result(),
SnapshotLocations: []*velerov1.VolumeSnapshotLocation{
newSnapshotLocation("velero", "default", "default"),
},
},
apiResources: []*test.APIResource{
test.PVs(
builder.ForPersistentVolume("pv-1").ObjectMeta(builder.WithLabelsMap(map[string]string{"failure-domain.beta.kubernetes.io/zone": "zone-1-deprecated", "topology.kubernetes.io/zone": "zone-1-ga"})).Result(),
),
},
snapshotterGetter: map[string]velero.VolumeSnapshotter{
"default": new(fakeVolumeSnapshotter).WithVolume("pv-1", "vol-1", "zone-1-ga", "type-1", 100, false),
},
want: []*volume.Snapshot{
{
Spec: volume.SnapshotSpec{
BackupName: "backup-1",
Location: "default",
PersistentVolumeName: "pv-1",
ProviderVolumeID: "vol-1",
VolumeAZ: "zone-1-ga",
VolumeType: "type-1",
VolumeIOPS: int64Ptr(100),
},
Status: volume.SnapshotStatus{
Phase: volume.SnapshotPhaseCompleted,
ProviderSnapshotID: "vol-1-snapshot",
},
},
},
},
{
name: "error returned from CreateSnapshot results in a failed snapshot",
req: &Request{
Expand Down
19 changes: 15 additions & 4 deletions pkg/backup/item_backupper.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,9 +384,14 @@ func (ib *defaultItemBackupper) volumeSnapshotter(snapshotLocation *api.VolumeSn
return bs, nil
}

// zoneLabelDeprecated is the label that stores availability-zone info
// on PVs this is deprecated on Kubernetes >= 1.17.0
// zoneLabel is the label that stores availability-zone info
// on PVs
const zoneLabel = "failure-domain.beta.kubernetes.io/zone"
const (
zoneLabelDeprecated = "failure-domain.beta.kubernetes.io/zone"
zoneLabel = "topology.kubernetes.io/zone"
)

// takePVSnapshot triggers a snapshot for the volume/disk underlying a PersistentVolume if the provided
// backup has volume snapshots enabled and the PV is of a compatible type. Also records cloud
Expand Down Expand Up @@ -415,9 +420,15 @@ func (ib *defaultItemBackupper) takePVSnapshot(obj runtime.Unstructured, log log
}
}

pvFailureDomainZone := pv.Labels[zoneLabel]
if pvFailureDomainZone == "" {
log.Infof("label %q is not present on PersistentVolume", zoneLabel)
// TODO: -- once failure-domain.beta.kubernetes.io/zone is no longer
// supported in any velero-supported version of Kubernetes, remove fallback checking of it
pvFailureDomainZone, labelFound := pv.Labels[zoneLabel]
if !labelFound {
cpanato marked this conversation as resolved.
Show resolved Hide resolved
log.Infof("label %q is not present on PersistentVolume, checking deprecated label...", zoneLabel)
pvFailureDomainZone, labelFound = pv.Labels[zoneLabelDeprecated]
if !labelFound {
log.Infof("label %q is not present on PersistentVolume", zoneLabelDeprecated)
}
}

var (
Expand Down