use restic stats instead of check to check repo existence
Signed-off-by: Steve Kriss <krisss@vmware.com>pull/1171/head
parent
3054a38bd6
commit
723cda2697
|
@ -162,10 +162,10 @@ func (c *resticRepositoryController) initializeRepo(req *v1.ResticRepository, lo
|
|||
})
|
||||
}
|
||||
|
||||
// ensureRepo first checks the repo, and returns if check passes. If it fails,
|
||||
// attempts to init the repo, and returns the result.
|
||||
// ensureRepo first tries to connect to the repo, and returns if it succeeds. If it fails,
|
||||
// it attempts to init the repo, and returns the result.
|
||||
func ensureRepo(repo *v1.ResticRepository, repoManager restic.RepositoryManager) error {
|
||||
if repoManager.CheckRepo(repo) == nil {
|
||||
if repoManager.ConnectToRepo(repo) == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -84,6 +84,13 @@ func InitCommand(repoIdentifier string) *Command {
|
|||
}
|
||||
}
|
||||
|
||||
func StatsCommand(repoIdentifier string) *Command {
|
||||
return &Command{
|
||||
Command: "stats",
|
||||
RepoIdentifier: repoIdentifier,
|
||||
}
|
||||
}
|
||||
|
||||
func CheckCommand(repoIdentifier string) *Command {
|
||||
return &Command{
|
||||
Command: "check",
|
||||
|
|
|
@ -96,6 +96,13 @@ func TestInitCommand(t *testing.T) {
|
|||
assert.Equal(t, "repo-id", c.RepoIdentifier)
|
||||
}
|
||||
|
||||
func TestStatsCommand(t *testing.T) {
|
||||
c := StatsCommand("repo-id")
|
||||
|
||||
assert.Equal(t, "stats", c.Command)
|
||||
assert.Equal(t, "repo-id", c.RepoIdentifier)
|
||||
}
|
||||
|
||||
func TestCheckCommand(t *testing.T) {
|
||||
c := CheckCommand("repo-id")
|
||||
|
||||
|
|
|
@ -42,6 +42,12 @@ type RepositoryManager interface {
|
|||
// InitRepo initializes a repo with the specified name and identifier.
|
||||
InitRepo(repo *velerov1api.ResticRepository) error
|
||||
|
||||
// ConnectToRepo runs the 'restic stats' command against the
|
||||
// specified repo, and returns an error if it fails. This is
|
||||
// intended to be used to ensure that the repo exists/can be
|
||||
// authenticated to.
|
||||
ConnectToRepo(repo *velerov1api.ResticRepository) error
|
||||
|
||||
// CheckRepo checks the specified repo for errors.
|
||||
CheckRepo(repo *velerov1api.ResticRepository) error
|
||||
|
||||
|
@ -170,6 +176,14 @@ func (rm *repositoryManager) InitRepo(repo *velerov1api.ResticRepository) error
|
|||
return rm.exec(InitCommand(repo.Spec.ResticIdentifier), repo.Spec.BackupStorageLocation)
|
||||
}
|
||||
|
||||
func (rm *repositoryManager) ConnectToRepo(repo *velerov1api.ResticRepository) error {
|
||||
// restic stats requires a non-exclusive lock
|
||||
rm.repoLocker.Lock(repo.Name)
|
||||
defer rm.repoLocker.Unlock(repo.Name)
|
||||
|
||||
return rm.exec(StatsCommand(repo.Spec.ResticIdentifier), repo.Spec.BackupStorageLocation)
|
||||
}
|
||||
|
||||
func (rm *repositoryManager) CheckRepo(repo *velerov1api.ResticRepository) error {
|
||||
// restic check requires an exclusive lock
|
||||
rm.repoLocker.LockExclusive(repo.Name)
|
||||
|
|
Loading…
Reference in New Issue