Skip to content

Commit

Permalink
store volume snapshot info as JSON in backup storage
Browse files Browse the repository at this point in the history
Signed-off-by: Steve Kriss <steve@heptio.com>
  • Loading branch information
skriss committed Oct 17, 2018
1 parent e24248e commit da9ed38
Show file tree
Hide file tree
Showing 26 changed files with 294 additions and 857 deletions.
15 changes: 0 additions & 15 deletions examples/common/00-prereqs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -177,21 +177,6 @@ spec:
plural: volumesnapshotlocations
kind: VolumeSnapshotLocation

---
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
name: volumesnapshots.ark.heptio.com
labels:
component: ark
spec:
group: ark.heptio.com
version: v1
scope: Namespaced
names:
plural: volumesnapshots
kind: VolumeSnapshot

---
apiVersion: v1
kind: Namespace
Expand Down
1 change: 0 additions & 1 deletion pkg/apis/ark/v1/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ func CustomResources() map[string]typeInfo {
"ResticRepository": newTypeInfo("resticrepositories", &ResticRepository{}, &ResticRepositoryList{}),
"BackupStorageLocation": newTypeInfo("backupstoragelocations", &BackupStorageLocation{}, &BackupStorageLocationList{}),
"VolumeSnapshotLocation": newTypeInfo("volumesnapshotlocations", &VolumeSnapshotLocation{}, &VolumeSnapshotLocationList{}),
"VolumeSnapshot": newTypeInfo("volumesnapshots", &VolumeSnapshot{}, &VolumeSnapshotList{}),
}
}

Expand Down
89 changes: 0 additions & 89 deletions pkg/apis/ark/v1/volume_snapshot.go

This file was deleted.

102 changes: 0 additions & 102 deletions pkg/apis/ark/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

64 changes: 38 additions & 26 deletions pkg/backup/item_backupper.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import (
"github.com/heptio/ark/pkg/kuberesource"
"github.com/heptio/ark/pkg/podexec"
"github.com/heptio/ark/pkg/restic"
"github.com/heptio/ark/pkg/volume"
)

type itemBackupperFactory interface {
Expand Down Expand Up @@ -401,19 +402,14 @@ func (ib *defaultItemBackupper) takePVSnapshot(obj runtime.Unstructured, log log
return errors.WithStack(err)
}

name := metadata.GetName()
var pvFailureDomainZone string
labels := metadata.GetLabels()

if labels[zoneLabel] != "" {
pvFailureDomainZone = labels[zoneLabel]
} else {
pvFailureDomainZone := metadata.GetLabels()[zoneLabel]
if pvFailureDomainZone == "" {
log.Infof("label %q is not present on PersistentVolume", zoneLabel)
}

var (
volumeID string
blockStore cloudprovider.BlockStore
volumeID, location string
blockStore cloudprovider.BlockStore
)

for _, snapshotLocation := range ib.backupRequest.SnapshotLocations {
Expand All @@ -439,6 +435,7 @@ func (ib *defaultItemBackupper) takePVSnapshot(obj runtime.Unstructured, log log

log.Infof("Got volume ID for persistent volume")
blockStore = bs
location = snapshotLocation.Name
break
}

Expand All @@ -454,30 +451,45 @@ func (ib *defaultItemBackupper) takePVSnapshot(obj runtime.Unstructured, log log
"ark.heptio.com/pv": metadata.GetName(),
}

log.Info("Snapshotting PersistentVolume")
snapshotID, err := blockStore.CreateSnapshot(volumeID, pvFailureDomainZone, tags)
if err != nil {
// log+error on purpose - log goes to the per-backup log file, error goes to the backup
log.WithError(err).Error("error creating snapshot")
return errors.WithMessage(err, "error creating snapshot")
}

log.Info("Getting volume information")
volumeType, iops, err := blockStore.GetVolumeInfo(volumeID, pvFailureDomainZone)
if err != nil {
log.WithError(err).Error("error getting volume info")
return errors.WithMessage(err, "error getting volume info")
}

if ib.backupRequest.Status.VolumeBackups == nil {
ib.backupRequest.Status.VolumeBackups = make(map[string]*api.VolumeBackupInfo)
}
log.Info("Snapshotting PersistentVolume")
snapshot := volumeSnapshot(ib.backupRequest.Backup, volumeID, volumeType, pvFailureDomainZone, location, iops)

ib.backupRequest.Status.VolumeBackups[name] = &api.VolumeBackupInfo{
SnapshotID: snapshotID,
Type: volumeType,
Iops: iops,
AvailabilityZone: pvFailureDomainZone,
var errs []error
snapshotID, err := blockStore.CreateSnapshot(snapshot.Spec.ProviderVolumeID, snapshot.Spec.VolumeAZ, tags)
if err != nil {
log.WithError(err).Error("error creating snapshot")
errs = append(errs, errors.Wrap(err, "error taking snapshot of volume"))
snapshot.Status.Phase = volume.SnapshotPhaseFailed
} else {
snapshot.Status.Phase = volume.SnapshotPhaseCompleted
snapshot.Status.ProviderSnapshotID = snapshotID
}
ib.backupRequest.VolumeSnapshots = append(ib.backupRequest.VolumeSnapshots, snapshot)

return nil
// nil errors are automatically removed
return kubeerrs.NewAggregate(errs)
}

func volumeSnapshot(backup *api.Backup, volumeID, volumeType, az, location string, iops *int64) *volume.Snapshot {
return &volume.Snapshot{
Spec: volume.SnapshotSpec{
BackupName: backup.Name,
BackupUID: string(backup.UID),
Location: location,
ProviderVolumeID: volumeID,
VolumeType: volumeType,
VolumeAZ: az,
VolumeIOPS: iops,
},
Status: volume.SnapshotStatus{
Phase: volume.SnapshotPhaseNew,
},
}
}
Loading

0 comments on commit da9ed38

Please sign in to comment.