Skip to content

Commit

Permalink
pb-5019: Added logic to fetch the default encryption type for FBDA, if
Browse files Browse the repository at this point in the history
it is not set in the kdmp-config cm.

	- frst case, if the exclude file list key is empty in the
	  kdmp-config cm, we will try to set the default exclude file list for
	  FBDA, if the storage class is FBDA.
	- second case, if the exclude file list key is not empty in the
	  kdmp-cpnfig cm, if it did not had rule for FBDA storage class, we will
	  try to set the degault execlude file list for the FBD, if the storage
	  class is FBDA.
  • Loading branch information
sivakumar subraani committed Nov 30, 2023
1 parent 68149a5 commit 724ad49
Showing 1 changed file with 70 additions and 24 deletions.
94 changes: 70 additions & 24 deletions pkg/controllers/dataexport/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,14 @@ const (
// will incorporate in their names
pvcNameLenLimitForJob = 48

defaultTimeout = 1 * time.Minute
progressCheckInterval = 5 * time.Second
compressionKey = "KDMP_COMPRESSION"
excludeFileListKey = "KDMP_EXCLUDE_FILE_LIST"
backupPath = "KDMP_BACKUP_PATH"
defaultTimeout = 1 * time.Minute
progressCheckInterval = 5 * time.Second
compressionKey = "KDMP_COMPRESSION"
excludeFileListKey = "KDMP_EXCLUDE_FILE_LIST"
backupPath = "KDMP_BACKUP_PATH"
defaultFBDAIgnorFileList = "/.snapshot/"
backendFBDAStorageClassKey = "backend"
backendFBDAStorageClassVal = "pure_file"
)

type updateDataExportDetail struct {
Expand Down Expand Up @@ -276,29 +279,46 @@ func (c *Controller) sync(ctx context.Context, in *kdmpapi.DataExport) (bool, er

kdmpData, err := core.Instance().GetConfigMap(utils.KdmpConfigmapName, utils.KdmpConfigmapNamespace)
if err != nil {
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)
msg := fmt.Sprintf("Failed in reading 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)
}
compressionType = kdmpData.Data[compressionKey]
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,
if driverName == drivers.KopiaBackup {
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]: %v",
utils.KdmpConfigmapNamespace, utils.KdmpConfigmapName, err)
logrus.Errorf(msg)
data := updateDataExportDetail{
status: kdmpapi.DataExportStatusFailed,
reason: msg,
}
return false, c.updateStatus(dataExport, data)
}
} else {
// Add default ignore rule, if any.
// For FBDA pvc, we will add "/.snapshot/" dir to be ignored by default.
if len(pvcStorageClass) != 0 {
excludeFileList, err = getDefaultIgnoreFileListForFBDA(pvcStorageClass)
if err != nil {
msg := fmt.Sprintf("Failed in getting storageclass[%v] for setting default ignore file option : %v",
pvcStorageClass, err)
logrus.Errorf(msg)
data := updateDataExportDetail{
status: kdmpapi.DataExportStatusFailed,
reason: msg,
}
return false, c.updateStatus(dataExport, data)
}
logrus.Infof("Default exclude file list for sc %v: %v", pvcStorageClass, excludeFileList)
}
return false, c.updateStatus(dataExport, data)
}
}
blName := dataExport.Spec.Destination.Name
Expand Down Expand Up @@ -526,6 +546,21 @@ func (c *Controller) sync(ctx context.Context, in *kdmpapi.DataExport) (bool, er
return false, nil
}

func getDefaultIgnoreFileListForFBDA(pvcStorageClass string) (string, error) {
var sc *storagev1.StorageClass
sc, checkErr := storage.Instance().GetStorageClass(pvcStorageClass)
if checkErr != nil {
return "", checkErr
}
if val, ok := sc.Parameters[backendFBDAStorageClassKey]; ok && val == backendFBDAStorageClassVal {
excludeFileList := defaultFBDAIgnorFileList
logrus.Infof("setting default FBDA ignore file list: %v", excludeFileList)
return excludeFileList, nil
}
return "", nil
}

// parseExcludeFileListKey:
// 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.
//
Expand All @@ -540,17 +575,28 @@ func parseExcludeFileListKey(pvcStorageClass string, excludeFileListValue string
excludeFileListValue = strings.TrimSuffix(string(excludeFileListValue), "\n")
storageClassList := strings.Split(excludeFileListValue, "\n")
var excludeFileList string
var err error
for _, storageClass := range storageClassList {
equalSignSplit := strings.Split(storageClass, "=")
if len(equalSignSplit) != 2 {
if len(equalSignSplit) <= 1 {
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 == equalSignSplit[0] {
excludeFileList = equalSignSplit[1]
break
}

}
// If the cm parameter did not had any matching rule, we will try to get the default file ignore list.
// For now, we have default list only for FABDA. The default file list is "/.snapshot/
if len(excludeFileList) == 0 {
excludeFileList, err = getDefaultIgnoreFileListForFBDA(pvcStorageClass)
if err != nil {
return "", err
}
logrus.Infof("parseExcludeFileListKey: Default exclude file list for sc %v: %v", pvcStorageClass, excludeFileList)
}
logrus.Infof("parseExcludeFileListKey: configured excludeFileList - %v", excludeFileList)
return excludeFileList, nil
}
Expand Down

0 comments on commit 724ad49

Please sign in to comment.