func (r *ReconcileBackup) createDatabaseSecret(bkp *v1alpha1.Backup, db *v1alpha1.Database) error {
	dbSecretName := utils.DbSecretPrefix + bkp.Name
	if _, err := service.FetchSecret(bkp.Namespace, dbSecretName, r.client); err != nil {
		secretData, err := r.buildDBSecretData(bkp, db)
		if err != nil {
			return err
		}
		dbSecret := resource.NewBackupSecret(bkp, utils.DbSecretPrefix, secretData, nil, r.scheme)
		if err := r.client.Create(context.TODO(), dbSecret); err != nil {
			return err
		}
	}
	return nil
}
createDatabaseSecret checks if the secret with the database is created, if not create one
package backup
import (
	"context"
	"fmt"
	"github.com/dev4devs-com/postgresql-operator/pkg/apis/postgresql/v1alpha1"
	"github.com/dev4devs-com/postgresql-operator/pkg/resource"
	"github.com/dev4devs-com/postgresql-operator/pkg/service"
	"github.com/dev4devs-com/postgresql-operator/pkg/utils"
)
func (r *ReconcileBackup) getDatabasePod(bkp *v1alpha1.Backup, db *v1alpha1.Database) error {
	dbPod, err := service.FetchDatabasePod(bkp, db, r.client)
	if err != nil || dbPod == nil {
		r.dbPod = nil
		err := fmt.Errorf("Unable to find the Database Pod")
		return err
	}
	r.dbPod = dbPod
	return nil
}
func (r *ReconcileBackup) getDatabaseService(bkp *v1alpha1.Backup, db *v1alpha1.Database) error {
	dbService, err := service.FetchDatabaseService(bkp, db, r.client)
	if err != nil || dbService == nil {
		r.dbService = nil
		err := fmt.Errorf("Unable to find the Database Service")
		return err
	}
	r.dbService = dbService
	return nil
}
func (r *ReconcileBackup) createCronJob(bkp *v1alpha1.Backup) error {
	if _, err := service.FetchCronJob(bkp.Name, bkp.Namespace, r.client); err != nil {
		if err := r.client.Create(context.TODO(), resource.NewBackupCronJob(bkp, r.scheme)); err != nil {
			return err
		}
	}
	return nil
}
func (r *ReconcileBackup) createEncryptionKey(bkp *v1alpha1.Backup) error {
	if utils.IsEncryptionKeyOptionConfig(bkp) {
		if _, err := service.FetchSecret(utils.GetEncSecretNamespace(bkp), utils.GetEncSecretName(bkp), r.client); err != nil {
			if utils.IsEncKeySetupByName(bkp) {
				return err
			} else {
				secretData, secretStringData := createEncDataMaps(bkp)
				encSecret := resource.NewBackupSecret(bkp, utils.EncSecretPrefix, secretData, secretStringData, r.scheme)
				if err := r.client.Create(context.TODO(), encSecret); err != nil {
					return err
				}
			}
		}
	}
	return nil
}
func (r *ReconcileBackup) createAwsSecret(bkp *v1alpha1.Backup) error {
	if _, err := service.FetchSecret(utils.GetAwsSecretNamespace(bkp), utils.GetAWSSecretName(bkp), r.client); err != nil {
		if !utils.IsAwsKeySetupByName(bkp) {
			secretData := createAwsDataByteMap(bkp)
			awsSecret := resource.NewBackupSecret(bkp, utils.AwsSecretPrefix, secretData, nil, r.scheme)
			if err := r.client.Create(context.TODO(), awsSecret); err != nil {
				return err
			}
		}
	}
	return nil
}