Skip to content

Commit

Permalink
Add Ark version to backup-version file in backup tarball
Browse files Browse the repository at this point in the history
Signed-off-by: Wayne Witzel III <wayne@riotousliving.com>
  • Loading branch information
wwitzel3 committed Dec 5, 2018
1 parent 5464b3d commit 0ed5ff0
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions pkg/backup/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
kuberrs "k8s.io/apimachinery/pkg/util/errors"

api "github.com/heptio/ark/pkg/apis/ark/v1"
"github.com/heptio/ark/pkg/buildinfo"
"github.com/heptio/ark/pkg/client"
"github.com/heptio/ark/pkg/cloudprovider"
"github.com/heptio/ark/pkg/discovery"
Expand Down Expand Up @@ -221,6 +222,10 @@ func (kb *kubernetesBackupper) Backup(logger logrus.FieldLogger, backupRequest *
log := logger.WithField("backup", kubeutil.NamespaceAndName(backupRequest))
log.Info("Starting backup")

if err := kb.writeBackupVersion(tw); err != nil {
return errors.WithStack(err)
}

backupRequest.NamespaceIncludesExcludes = getNamespaceIncludesExcludes(backupRequest.Backup)
log.Infof("Including namespaces: %s", backupRequest.NamespaceIncludesExcludes.IncludesString())
log.Infof("Excluding namespaces: %s", backupRequest.NamespaceIncludesExcludes.ExcludesString())
Expand Down Expand Up @@ -292,6 +297,23 @@ func (kb *kubernetesBackupper) Backup(logger logrus.FieldLogger, backupRequest *
return err
}

func (kb *kubernetesBackupper) writeBackupVersion(tw *tar.Writer) error {
hdr := &tar.Header{
Name: "backup-version",
Size: int64(len(buildinfo.Version)),
Typeflag: tar.TypeReg,
Mode: 0644,
ModTime: time.Now(),
}
if err := tw.WriteHeader(hdr); err != nil {
return err
}
if _, err := tw.Write([]byte(buildinfo.Version)); err != nil {
return err
}
return nil
}

type tarWriter interface {
io.Closer
Write([]byte) (int, error)
Expand Down

0 comments on commit 0ed5ff0

Please sign in to comment.