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

Skip snap store specific sanity check when not configured #122

Merged
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pkg/initializer/initializer.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ func (e *EtcdInitializer) restoreCorruptData() error {

if e.Config.SnapstoreConfig == nil {
logger.Warnf("No snapstore storage provider configured.")
logger.Infof("Removing data directory(%s) for snapshot restoration.", dataDir)
if err := os.RemoveAll(filepath.Join(dataDir)); err != nil {
return fmt.Errorf("failed to delete data directory %s with err: %v", dataDir, err)
}
return nil
}
store, err := snapstore.GetSnapstore(e.Config.SnapstoreConfig)
Expand Down
20 changes: 12 additions & 8 deletions pkg/initializer/validator/datavalidator.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,14 @@ func (d *DataValidator) Validate() (DataDirStatus, error) {
return DataDirectoryInvStruct, nil
}

d.Logger.Info("Checking for revision consistency...")
if err = d.CheckRevisionConsistency(); err != nil {
d.Logger.Infof("Etcd revision inconsistent with latest snapshot revision: %v", err)
return RevisionConsistencyError, nil
if d.Config.SnapstoreConfig != nil {
d.Logger.Info("Checking for revision consistency...")
if err = checkRevisionConsistency(d.backendPath(), *d.Config.SnapstoreConfig); err != nil {
d.Logger.Infof("Etcd revision inconsistent with latest snapshot revision: %v", err)
return RevisionConsistencyError, nil
}
} else {
d.Logger.Info("Skipping check for revision consistency, since no snapstore configured.")
}

d.Logger.Info("Checking for data directory files corruption...")
Expand Down Expand Up @@ -338,14 +342,14 @@ func verifyDB(path string) error {
})
}

// CheckRevisionConsistency compares the latest revisions on the etcd db file and the latest snapshot to verify that the etcd revision is not lesser than snapshot revision.
func (d *DataValidator) CheckRevisionConsistency() error {
etcdRevision, err := getLatestEtcdRevision(d.backendPath())
// checkRevisionConsistency compares the latest revisions on the etcd db file and the latest snapshot to verify that the etcd revision is not lesser than snapshot revision.
func checkRevisionConsistency(dbPath string, config snapstore.Config) error {
etcdRevision, err := getLatestEtcdRevision(dbPath)
if err != nil {
return fmt.Errorf("unable to get current etcd revision from backend db file: %v", err)
}

store, err := snapstore.GetSnapstore(d.Config.SnapstoreConfig)
store, err := snapstore.GetSnapstore(&config)
if err != nil {
return fmt.Errorf("unable to fetch snapstore: %v", err)
}
Expand Down