Skip to content

Commit

Permalink
Incorporated review comments
Browse files Browse the repository at this point in the history
Signed-off-by: Rensy Thomas <[email protected]>
  • Loading branch information
rensycthomas committed Dec 5, 2024
1 parent c767666 commit 6c05d6f
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 77 deletions.
91 changes: 37 additions & 54 deletions components/automate-cli/cmd/chef-automate/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -1435,7 +1435,7 @@ func getBackupStatusAsCompletedOrFailed(backup *api.BackupTask) bool {

}

func compareBackupPaths(infra *AutomateHAInfraDetails, sshUtil SSHUtil, pullConfig PullConfigs) (bool, error) {
func compareBackupPaths(infra *AutomateHAInfraDetails, sshUtil SSHUtil, pullConfig PullConfigs) (bool, error) {
automateIps := infra.Outputs.AutomatePrivateIps.Value
if automateIps == nil || len(automateIps) < 1 {
return false, errors.New("Automate private IPs are empty")
Expand Down Expand Up @@ -1470,7 +1470,7 @@ func compareBackupPaths(infra *AutomateHAInfraDetails, sshUtil SSHUtil, pullConf
return false, errors.New("There is discrepancy in indices of snapshot locations of services. Indices of all snapshots should be the same. ")
}
logrus.Debugf("SnapshotServiceBackupPath: %s", snapshotServiceBackupPath)

if backupType == "fileStorage" {
osPath, err := pullConfig.getBackupPathFromOpensearchConfig()
if err != nil {
Expand All @@ -1495,8 +1495,9 @@ func compareBackupPaths(infra *AutomateHAInfraDetails, sshUtil SSHUtil, pullConf

func compareSnapshotLocationOfServices(backupLocation string, sshUtil SSHUtil) (string, bool, error) {
var isEs5Service, isEs6Service, allowRestore bool
var snapshotEs5ServicePath, snapshotEs6ServicePath, complianceServicePath, eventFeedServicePath, erchefServicePath, ingestServicePath string
var snapshotEs5ServicePath, snapshotEs6ServicePath string
osSnapshot, err := getSnapshotLocationsOfServices(sshUtil)

if err != nil {
return "", false, err
}
Expand All @@ -1519,30 +1520,19 @@ func compareSnapshotLocationOfServices(backupLocation string, sshUtil SSHUtil) (
case "fs":
if isEs6Service {
if osSnapshot.Es6Compliance.Type == backupLocation && osSnapshot.Es6Erchef.Type == backupLocation && osSnapshot.Es6EventFeed.Type == backupLocation && osSnapshot.Es6Ingest.Type == backupLocation {
complianceServicePath = getSnapshotPathDetails(osSnapshot.Es6Compliance.Settings.Location)
erchefServicePath = getSnapshotPathDetails(osSnapshot.Es6Erchef.Settings.Location)
eventFeedServicePath = getSnapshotPathDetails(osSnapshot.Es6EventFeed.Settings.Location)
ingestServicePath = getSnapshotPathDetails(osSnapshot.Es6Ingest.Settings.Location)
if complianceServicePath == erchefServicePath && erchefServicePath == eventFeedServicePath && erchefServicePath == ingestServicePath {
allowRestore = true
snapshotEs6ServicePath = complianceServicePath
}
snapshotEs6ServicePath, allowRestore = getSnapshotPath(getSnapshotPathDetails(osSnapshot.Es6Compliance.Settings.Location),
getSnapshotPathDetails(osSnapshot.Es6Erchef.Settings.Location), getSnapshotPathDetails(osSnapshot.Es6EventFeed.Settings.Location),
getSnapshotPathDetails(osSnapshot.Es6Ingest.Settings.Location))
} else {
err := fmt.Errorf("discrepancy in the backup types. Backup path of all indices should be %s. Refer `https://docs.chef.io/automate/ha_backup_restore_file_system/#troubleshooting` to do a clean up of the snapshot repo", backupLocation)
return "", false, err
}

}
if isEs5Service {
if osSnapshot.Es5Compliance.Type == backupLocation && osSnapshot.Es5Erchef.Type == backupLocation && osSnapshot.Es5EventFeed.Type == backupLocation && osSnapshot.Es5Ingest.Type == backupLocation {
complianceServicePath = getSnapshotPathDetails(osSnapshot.Es5Compliance.Settings.Location)
erchefServicePath = getSnapshotPathDetails(osSnapshot.Es5Erchef.Settings.Location)
eventFeedServicePath = getSnapshotPathDetails(osSnapshot.Es5EventFeed.Settings.Location)
ingestServicePath = getSnapshotPathDetails(osSnapshot.Es5Ingest.Settings.Location)
if complianceServicePath == erchefServicePath && erchefServicePath == eventFeedServicePath && erchefServicePath == ingestServicePath {
allowRestore = true
snapshotEs5ServicePath = complianceServicePath
}
snapshotEs5ServicePath, allowRestore = getSnapshotPath(getSnapshotPathDetails(osSnapshot.Es5Compliance.Settings.Location),
getSnapshotPathDetails(osSnapshot.Es5Erchef.Settings.Location), getSnapshotPathDetails(osSnapshot.Es5EventFeed.Settings.Location),
getSnapshotPathDetails(osSnapshot.Es5Ingest.Settings.Location))
} else {
err := fmt.Errorf("discrepancy in the backup types. Backup type of all indices should be %s. Refer `https://docs.chef.io/automate/ha_backup_restore_file_system/#troubleshooting` to do a clean up of the snapshot repo", backupLocation)
return "", false, err
Expand All @@ -1552,29 +1542,19 @@ func compareSnapshotLocationOfServices(backupLocation string, sshUtil SSHUtil) (
case "s3":
if isEs6Service {
if osSnapshot.Es6Compliance.Type == backupLocation && osSnapshot.Es6Erchef.Type == backupLocation && osSnapshot.Es6EventFeed.Type == backupLocation && osSnapshot.Es6Ingest.Type == backupLocation {
complianceServicePath = getSnapshotPathDetails(osSnapshot.Es6Compliance.Settings.BasePath)
erchefServicePath = getSnapshotPathDetails(osSnapshot.Es6Erchef.Settings.BasePath)
eventFeedServicePath = getSnapshotPathDetails(osSnapshot.Es6EventFeed.Settings.BasePath)
ingestServicePath = getSnapshotPathDetails(osSnapshot.Es6Ingest.Settings.BasePath)
if complianceServicePath == erchefServicePath && erchefServicePath == eventFeedServicePath && erchefServicePath == ingestServicePath {
allowRestore = true
snapshotEs6ServicePath = complianceServicePath
}
snapshotEs6ServicePath, allowRestore = getSnapshotPath(getSnapshotPathDetails(osSnapshot.Es6Compliance.Settings.BasePath),
getSnapshotPathDetails(osSnapshot.Es6Erchef.Settings.BasePath), getSnapshotPathDetails(osSnapshot.Es6EventFeed.Settings.BasePath),
getSnapshotPathDetails(osSnapshot.Es6Ingest.Settings.BasePath))
} else {
err := fmt.Errorf("discrepancy in the backup types. Backup type of all indices should be %s. Refer `https://docs.chef.io/automate/ha_backup_restore_object_storage/#troubleshooting` to do a clean up of the snapshot repo", backupLocation)
return "", false, err
}
}
if isEs5Service {
if osSnapshot.Es5Compliance.Type == backupLocation && osSnapshot.Es5Erchef.Type == backupLocation && osSnapshot.Es5EventFeed.Type == backupLocation && osSnapshot.Es5Ingest.Type == backupLocation {
complianceServicePath = getSnapshotPathDetails(osSnapshot.Es5Compliance.Settings.BasePath)
erchefServicePath = getSnapshotPathDetails(osSnapshot.Es5Erchef.Settings.BasePath)
eventFeedServicePath = getSnapshotPathDetails(osSnapshot.Es5EventFeed.Settings.BasePath)
ingestServicePath = getSnapshotPathDetails(osSnapshot.Es5Ingest.Settings.BasePath)
if complianceServicePath == erchefServicePath && erchefServicePath == eventFeedServicePath && erchefServicePath == ingestServicePath {
allowRestore = true
snapshotEs5ServicePath = complianceServicePath
}
snapshotEs5ServicePath, allowRestore = getSnapshotPath(getSnapshotPathDetails(osSnapshot.Es5Compliance.Settings.BasePath),
getSnapshotPathDetails(osSnapshot.Es5Erchef.Settings.BasePath), getSnapshotPathDetails(osSnapshot.Es5EventFeed.Settings.BasePath),
getSnapshotPathDetails(osSnapshot.Es5Ingest.Settings.BasePath))
} else {
err := fmt.Errorf("discrepancy in the backup types. Backup type of all indices should be %s. Refer `https://docs.chef.io/automate/ha_backup_restore_object_storage/#troubleshooting` to do a clean up of the snapshot repo", backupLocation)
return "", false, err
Expand All @@ -1584,29 +1564,19 @@ func compareSnapshotLocationOfServices(backupLocation string, sshUtil SSHUtil) (
case "gcs":
if isEs6Service {
if osSnapshot.Es6Compliance.Type == backupLocation && osSnapshot.Es6Erchef.Type == backupLocation && osSnapshot.Es6EventFeed.Type == backupLocation && osSnapshot.Es6Ingest.Type == backupLocation {
complianceServicePath = getSnapshotPathDetails(osSnapshot.Es6Compliance.Settings.BasePath)
erchefServicePath = getSnapshotPathDetails(osSnapshot.Es6Erchef.Settings.BasePath)
eventFeedServicePath = getSnapshotPathDetails(osSnapshot.Es6EventFeed.Settings.BasePath)
ingestServicePath = getSnapshotPathDetails(osSnapshot.Es6Ingest.Settings.BasePath)
if complianceServicePath == erchefServicePath && erchefServicePath == eventFeedServicePath && erchefServicePath == ingestServicePath {
allowRestore = true
snapshotEs6ServicePath = complianceServicePath
}
snapshotEs6ServicePath, allowRestore = getSnapshotPath(getSnapshotPathDetails(osSnapshot.Es6Compliance.Settings.BasePath),
getSnapshotPathDetails(osSnapshot.Es6Erchef.Settings.BasePath), getSnapshotPathDetails(osSnapshot.Es6EventFeed.Settings.BasePath),
getSnapshotPathDetails(osSnapshot.Es6Ingest.Settings.BasePath))
} else {
err := fmt.Errorf("discrepancy in the backup types. Backup type of all indices should be %s. Refer `https://docs.chef.io/automate/ha_backup_restore_object_storage/#troubleshooting` to do a clean up of the snapshot repo", backupLocation)
return "", false, err
}
}
if isEs5Service {
if osSnapshot.Es5Compliance.Type == backupLocation && osSnapshot.Es5Erchef.Type == backupLocation && osSnapshot.Es5EventFeed.Type == backupLocation && osSnapshot.Es5Ingest.Type == backupLocation {
complianceServicePath = getSnapshotPathDetails(osSnapshot.Es5Compliance.Settings.BasePath)
erchefServicePath = getSnapshotPathDetails(osSnapshot.Es5Erchef.Settings.BasePath)
eventFeedServicePath = getSnapshotPathDetails(osSnapshot.Es5EventFeed.Settings.BasePath)
ingestServicePath = getSnapshotPathDetails(osSnapshot.Es5Ingest.Settings.BasePath)
if complianceServicePath == erchefServicePath && erchefServicePath == eventFeedServicePath && erchefServicePath == ingestServicePath {
allowRestore = true
snapshotEs5ServicePath = complianceServicePath
}
snapshotEs5ServicePath, allowRestore = getSnapshotPath(getSnapshotPathDetails(osSnapshot.Es5Compliance.Settings.BasePath),
getSnapshotPathDetails(osSnapshot.Es5Erchef.Settings.BasePath), getSnapshotPathDetails(osSnapshot.Es5EventFeed.Settings.BasePath),
getSnapshotPathDetails(osSnapshot.Es5Ingest.Settings.BasePath))
} else {
err := fmt.Errorf("discrepancy in the backup types. Backup type of all indices should be %s. Refer `https://docs.chef.io/automate/ha_backup_restore_object_storage/#troubleshooting` to do a clean up of the snapshot repo", backupLocation)
return "", false, err
Expand All @@ -1620,7 +1590,7 @@ func compareSnapshotLocationOfServices(backupLocation string, sshUtil SSHUtil) (
allowRestore = true
return snapshotEs6ServicePath, allowRestore, nil
}
logrus.Debugf("Response from compareSnapshotLocationOfServices. allowRestore flag: %t, isEs5Service flag: %t, isEs6Service: %t, snapshotEs5ServicePath: %s, snapshotEs6ServicePath: %s",
logrus.Debugf("Response from compareSnapshotLocationOfServices. allowRestore flag: %t, isEs5Service flag: %t, isEs6Service: %t, snapshotEs5ServicePath: %s, snapshotEs6ServicePath: %s",
allowRestore, isEs5Service, isEs6Service, snapshotEs5ServicePath, snapshotEs6ServicePath)

if isEs5Service && isEs6Service && snapshotEs5ServicePath == snapshotEs6ServicePath {
Expand Down Expand Up @@ -1653,7 +1623,20 @@ func getSnapshotLocationsOfServices(sshUtil SSHUtil) (*osSnapshot, error) {
return &oss, nil
}

func getSnapshotPath(complianceServicePath string, erchefServicePath string, eventFeedServicePath string, ingestServicePath string) (string, bool) {
var allowRestore bool
var snapshotServicePath string
if complianceServicePath == erchefServicePath && erchefServicePath == eventFeedServicePath && erchefServicePath == ingestServicePath {
allowRestore = true
snapshotServicePath = complianceServicePath
}
return snapshotServicePath, allowRestore
}

func getSnapshotPathDetails(snapshotPath string) string {
parts := strings.Split(snapshotPath, "/automate-elasticsearch-data")
return parts[0]
if len(parts) > 0 {
return parts[0]
}
return ""
}
49 changes: 26 additions & 23 deletions components/automate-cli/cmd/chef-automate/pullAndGenerateConfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -1656,31 +1656,34 @@ func getGcsBackupConfig(a2ConfigMap map[string]*dc.AutomateConfig, fileUtils fil
func (p *PullConfigsImpl) getBackupPathFromAutomateConfig(a2ConfigMap map[string]*dc.AutomateConfig, backupLocation string) (string, error) {
for _, ele := range a2ConfigMap {
path := ""
switch backupLocation {
case "fs":
if ele.Global.V1.External.Opensearch.Backup.Fs != nil &&
ele.Global.V1.External.Opensearch.Backup.Fs.Path != nil {
path = ele.Global.V1.External.Opensearch.Backup.Fs.Path.GetValue()
logrus.Debugf("backup path configured in automate nodes: %s and backup location: %s", path, backupLocation)
return path, nil
}
case "s3":
if ele.Global.V1.External.Opensearch.Backup.S3 != nil &&
ele.Global.V1.External.Opensearch.Backup.S3.Bucket != nil &&
ele.Global.V1.External.Opensearch.Backup.S3.BasePath != nil {
path = ele.Global.V1.External.Opensearch.Backup.S3.BasePath.GetValue()
logrus.Debugf("backup path configured in automate nodes: %s and backup location: %s", path, backupLocation)
return path, nil
}
case "gcs":
if ele.Global.V1.External.Opensearch.Backup.Gcs != nil &&
ele.Global.V1.External.Opensearch.Backup.Gcs.Bucket != nil &&
ele.Global.V1.External.Opensearch.Backup.Gcs.BasePath != nil {
path = ele.Global.V1.External.Opensearch.Backup.Gcs.BasePath.GetValue()
logrus.Debugf("backup path configured in automate nodes: %s and backup location: %s", path, backupLocation)
return path, nil
if ele.Global.V1.External.Opensearch != nil && ele.Global.V1.External.Opensearch.Backup != nil {
switch backupLocation {
case "fs":
if ele.Global.V1.External.Opensearch.Backup.Fs != nil &&
ele.Global.V1.External.Opensearch.Backup.Fs.Path != nil {
path = ele.Global.V1.External.Opensearch.Backup.Fs.Path.GetValue()
logrus.Debugf("backup path configured in automate nodes: %s and backup location: %s", path, backupLocation)
return path, nil
}
case "s3":
if ele.Global.V1.External.Opensearch.Backup.S3 != nil &&
ele.Global.V1.External.Opensearch.Backup.S3.Bucket != nil &&
ele.Global.V1.External.Opensearch.Backup.S3.BasePath != nil {
path = ele.Global.V1.External.Opensearch.Backup.S3.BasePath.GetValue()
logrus.Debugf("backup path configured in automate nodes: %s and backup location: %s", path, backupLocation)
return path, nil
}
case "gcs":
if ele.Global.V1.External.Opensearch.Backup.Gcs != nil &&
ele.Global.V1.External.Opensearch.Backup.Gcs.Bucket != nil &&
ele.Global.V1.External.Opensearch.Backup.Gcs.BasePath != nil {
path = ele.Global.V1.External.Opensearch.Backup.Gcs.BasePath.GetValue()
logrus.Debugf("backup path configured in automate nodes: %s and backup location: %s", path, backupLocation)
return path, nil
}
}
}
return "", errors.New("automate config Global.V1.External.Opensearch configurations are missing")
}
return "", errors.New("backup path from automate node could not be determined")
}
Expand Down

0 comments on commit 6c05d6f

Please sign in to comment.