Skip to content

Commit

Permalink
review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
sivakumar subraani committed Nov 22, 2023
1 parent 5f6d415 commit 205593d
Showing 1 changed file with 40 additions and 28 deletions.
68 changes: 40 additions & 28 deletions pkg/controllers/dataexport/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,30 +276,32 @@ func (c *Controller) sync(ctx context.Context, in *kdmpapi.DataExport) (bool, er

kdmpData, err := core.Instance().GetConfigMap(utils.KdmpConfigmapName, utils.KdmpConfigmapNamespace)
if err != nil {
msg := fmt.Sprintf("Failed in reading the configmap [%v/%v]", utils.KdmpConfigmapNamespace, utils.KdmpConfigmapName)
logrus.Errorf(msg)
data := updateDataExportDetail{
status: kdmpapi.DataExportStatusFailed,
reason: msg,
}
return false, c.updateStatus(dataExport, data)
} else {
compressionType = kdmpData.Data[compressionKey]
if len(compressionType) == 0 {
compressionType = utils.DefaultCompresion
logrus.Errorf("failed reading config map %v: %v", utils.KdmpConfigmapName, err)
if err != nil {
msg := fmt.Sprintf("Failed in parsing the excludeFileList configmap parameter from configmap [%v/%v]: %v", utils.KdmpConfigmapNamespace, utils.KdmpConfigmapName, err)
logrus.Errorf(msg)
data := updateDataExportDetail{
status: kdmpapi.DataExportStatusFailed,
reason: msg,
}
return false, c.updateStatus(dataExport, data)
}
podDataPath = kdmpData.Data[backupPath]
if len(kdmpData.Data[excludeFileListKey]) != 0 {
excludeFileList, err = parseExcludeFileListKey(pvcStorageClass, kdmpData.Data[excludeFileListKey])
if err != nil {
msg := fmt.Sprintf("Failed in parsing the excludeFileList configmap parameter from configmap [%v/%v]", utils.KdmpConfigmapNamespace, utils.KdmpConfigmapName)
logrus.Errorf(msg)
data := updateDataExportDetail{
status: kdmpapi.DataExportStatusFailed,
reason: msg,
}
return false, c.updateStatus(dataExport, data)
}
compressionType = kdmpData.Data[compressionKey]
if len(compressionType) == 0 {
compressionType = utils.DefaultCompresion
}
podDataPath = kdmpData.Data[backupPath]
if len(kdmpData.Data[excludeFileListKey]) != 0 {
excludeFileList, err = parseExcludeFileListKey(pvcStorageClass, kdmpData.Data[excludeFileListKey])
if err != nil {
msg := fmt.Sprintf("Failed in parsing the excludeFileList configmap parameter from configmap [%v/%v]", utils.KdmpConfigmapNamespace, utils.KdmpConfigmapName)
logrus.Errorf(msg)
data := updateDataExportDetail{
status: kdmpapi.DataExportStatusFailed,
reason: msg,
}
return false, c.updateStatus(dataExport, data)
}
}
blName := dataExport.Spec.Destination.Name
Expand Down Expand Up @@ -528,17 +530,27 @@ func (c *Controller) sync(ctx context.Context, in *kdmpapi.DataExport) (bool, er
}

// If pvc storageclass and the configured storageclass matches, extract the configured ignore file list and return it.
// For code reference, adding the sample of the configmap parameter.
//
// KDMP_EXCLUDE_FILE_LIST: |
// px-db=dir1,file1,dir2
// mysql=dir1,file1,dir2
//
// After we read, the parameter value comes as follow:
// "px-db=dir1,file1,dir2\nmysql=dir1,file1,dir2\n"
func parseExcludeFileListKey(pvcStorageClass string, excludeFileListValue string) (string, error) {
storageClassList := strings.Split(excludeFileListValue, ",")
// trim the ending "\n" character, if it present
excludeFileListValue = strings.TrimSuffix(string(excludeFileListValue), "\n")
storageClassList := strings.Split(excludeFileListValue, "\n")
var excludeFileList string
for _, storageClass := range storageClassList {
colonSplit := strings.Split(storageClass, ":")
if len(colonSplit) != 2 {
return "", fmt.Errorf("invalid exclude file list in the configmap parameter. It should of format: \"storageClass1:dir1#dir2, storageClass2:dir1#file1\"")
equalSignSplit := strings.Split(storageClass, "=")
if len(equalSignSplit) != 2 {
return "", fmt.Errorf("invalid exclude file list in the configmap parameter")
}
// if the PVC storageclass and configure storageclass are same, extract the configured ignore file list
if pvcStorageClass == colonSplit[0] {
excludeFileList = colonSplit[1]
if pvcStorageClass == equalSignSplit[0] {
excludeFileList = equalSignSplit[1]
}

}
Expand Down

0 comments on commit 205593d

Please sign in to comment.