func (dt *HelperDbSecret) newErrorUnableToGetKeyFrom() error {
	return fmt.Errorf("Unable to get the key (%v) in the configMap (%v) in the namespace (%v) to create the secret",
		dt.cfgKey, dt.cfgName, dt.cfgNamespace)
}
newErrorUnableToGetKeyFrom returns an error when is not possible find the key into the configMap and namespace in order
to create the mandatory envvar for the database
package backup
import (
	"fmt"
	"github.com/dev4devs-com/postgresql-operator/pkg/apis/postgresql/v1alpha1"
	"github.com/dev4devs-com/postgresql-operator/pkg/service"
	"github.com/dev4devs-com/postgresql-operator/pkg/utils"
)
type DbSecret struct {
	databaseName string
	user         string
	pwd          string
	host         string
	superuser    string
	dbVersion    string
}
type HelperDbSecret struct {
	envVarName   string
	envVarValue  string
	cfgName      string
	cfgKey       string
	cfgNamespace string
}
func (r *ReconcileBackup) buildDBSecretData(bkp *v1alpha1.Backup, db *v1alpha1.Database) (map[string][]byte, error) {
	dbSecret := r.newDBSecret(bkp)
	for i := 0; i < len(r.dbPod.Spec.Containers[0].Env); i++ {
		helper := r.newHelperDbSecret(i, bkp)
		var err error
		switch helper.envVarName {
		case utils.GetEnvVarKey(db.Spec.ConfigMapDatabaseNameKey, db.Spec.DatabaseNameKeyEnvVar):
			dbSecret.databaseName, err = r.getEnvVarValue(dbSecret.databaseName, dbSecret, helper)
			if err != nil {
				return nil, err
			}
		case utils.GetEnvVarKey(db.Spec.ConfigMapDatabaseUserKey, db.Spec.DatabaseUserKeyEnvVar):
			dbSecret.user, err = r.getEnvVarValue(dbSecret.user, dbSecret, helper)
			if err != nil {
				return nil, err
			}
		case utils.GetEnvVarKey(db.Spec.ConfigMapDatabasePasswordKey, db.Spec.DatabasePasswordKeyEnvVar):
			dbSecret.pwd, err = r.getEnvVarValue(dbSecret.pwd, dbSecret, helper)
			if err != nil {
				return nil, err
			}
		}
	}
	return dbSecret.createMap(), nil
}
func (r *ReconcileBackup) getEnvVarValue(value string, dbSecret *DbSecret, helper *HelperDbSecret) (string, error) {
	value = helper.envVarValue
	if value == "" {
		value = r.getKeyValueFromConfigMap(helper)
		if value == "" {
			return "", helper.newErrorUnableToGetKeyFrom()
		}
	}
	return value, nil
}
func (r *ReconcileBackup) newHelperDbSecret(i int, bkp *v1alpha1.Backup) *HelperDbSecret {
	dt := new(HelperDbSecret)
	dt.envVarName = r.dbPod.Spec.Containers[0].Env[i].Name
	dt.envVarValue = r.dbPod.Spec.Containers[0].Env[i].Value
	dt.cfgNamespace = bkp.Namespace
	if r.dbPod.Spec.Containers[0].Env[i].ValueFrom != nil {
		dt.cfgName = r.dbPod.Spec.Containers[0].Env[i].ValueFrom.ConfigMapKeyRef.Name
		dt.cfgKey = r.dbPod.Spec.Containers[0].Env[i].ValueFrom.ConfigMapKeyRef.Key
	}
	return dt
}
func (r *ReconcileBackup) newDBSecret(bkp *v1alpha1.Backup) *DbSecret {
	db := new(DbSecret)
	db.host = r.dbService.Name + "." + bkp.Namespace + ".svc"
	db.superuser = "false"
	db.dbVersion = bkp.Spec.DatabaseVersion
	return db
}