github.com/1aal/kubeblocks@v0.0.0-20231107070852-e1c03e598921/pkg/dataprotection/errors/errors.go (about)

     1  /*
     2  Copyright (C) 2022-2023 ApeCloud Co., Ltd
     3  
     4  This file is part of KubeBlocks project
     5  
     6  This program is free software: you can redistribute it and/or modify
     7  it under the terms of the GNU Affero General Public License as published by
     8  the Free Software Foundation, either version 3 of the License, or
     9  (at your option) any later version.
    10  
    11  This program is distributed in the hope that it will be useful
    12  but WITHOUT ANY WARRANTY; without even the implied warranty of
    13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    14  GNU Affero General Public License for more details.
    15  
    16  You should have received a copy of the GNU Affero General Public License
    17  along with this program.  If not, see <http://www.gnu.org/licenses/>.
    18  */
    19  
    20  package errors
    21  
    22  import (
    23  	intctrlutil "github.com/1aal/kubeblocks/pkg/controllerutil"
    24  )
    25  
    26  // ErrorType for backup
    27  const (
    28  	// ErrorTypeBackupNotSupported this backup type not supported
    29  	ErrorTypeBackupNotSupported intctrlutil.ErrorType = "BackupNotSupported"
    30  	// ErrorTypeBackupPVTemplateNotFound this pv template not found
    31  	ErrorTypeBackupPVTemplateNotFound intctrlutil.ErrorType = "BackupPVTemplateNotFound"
    32  	// ErrorTypeBackupNotCompleted report backup not completed.
    33  	ErrorTypeBackupNotCompleted intctrlutil.ErrorType = "BackupNotCompleted"
    34  	// ErrorTypeBackupPVCNameIsEmpty pvc name for backup is empty
    35  	ErrorTypeBackupPVCNameIsEmpty intctrlutil.ErrorType = "BackupPVCNameIsEmpty"
    36  	// ErrorTypeBackupRepoIsNotReady the backup repository is not ready
    37  	ErrorTypeBackupRepoIsNotReady intctrlutil.ErrorType = "BackupRepoIsNotReady"
    38  	// ErrorTypeToolConfigSecretNameIsEmpty the name of  repository is not ready
    39  	ErrorTypeToolConfigSecretNameIsEmpty intctrlutil.ErrorType = "ToolConfigSecretNameIsEmpty"
    40  	// ErrorTypeBackupJobFailed backup job failed
    41  	ErrorTypeBackupJobFailed intctrlutil.ErrorType = "BackupJobFailed"
    42  	// ErrorTypeStorageNotMatch storage not match
    43  	ErrorTypeStorageNotMatch intctrlutil.ErrorType = "ErrorTypeStorageNotMatch"
    44  	// ErrorTypeReconfigureFailed reconfigure failed
    45  	ErrorTypeReconfigureFailed intctrlutil.ErrorType = "ErrorTypeReconfigureFailed"
    46  	// ErrorTypeInvalidLogfileBackupName invalid logfile backup name
    47  	ErrorTypeInvalidLogfileBackupName intctrlutil.ErrorType = "InvalidLogfileBackupName"
    48  	// ErrorTypeBackupScheduleDisabled backup schedule disabled
    49  	ErrorTypeBackupScheduleDisabled intctrlutil.ErrorType = "BackupScheduleDisabled"
    50  	// ErrorTypeLogfileScheduleDisabled logfile schedule disabled
    51  	ErrorTypeLogfileScheduleDisabled intctrlutil.ErrorType = "LogfileScheduleDisabled"
    52  	// ErrorTypeWaitForExternalHandler wait for external handler to handle the Backup or Restore
    53  	ErrorTypeWaitForExternalHandler intctrlutil.ErrorType = "WaitForExternalHandler"
    54  )
    55  
    56  // NewBackupNotSupported returns a new Error with ErrorTypeBackupNotSupported.
    57  func NewBackupNotSupported(backupType, backupPolicyName string) *intctrlutil.Error {
    58  	return intctrlutil.NewErrorf(ErrorTypeBackupNotSupported, `backup type "%s" not supported by backup policy "%s"`, backupType, backupPolicyName)
    59  }
    60  
    61  // NewBackupPVTemplateNotFound returns a new Error with ErrorTypeBackupPVTemplateNotFound.
    62  func NewBackupPVTemplateNotFound(cmName, cmNamespace string) *intctrlutil.Error {
    63  	return intctrlutil.NewErrorf(ErrorTypeBackupPVTemplateNotFound, `"the persistentVolume template is empty in the configMap %s/%s", pvConfig.Namespace, pvConfig.Name`, cmNamespace, cmName)
    64  }
    65  
    66  // NewBackupRepoIsNotReady returns a new Error with ErrorTypeBackupRepoIsNotReady.
    67  func NewBackupRepoIsNotReady(backupRepo string) *intctrlutil.Error {
    68  	return intctrlutil.NewErrorf(ErrorTypeBackupRepoIsNotReady, `the backup repository %s is not ready`, backupRepo)
    69  }
    70  
    71  // NewToolConfigSecretNameIsEmpty returns a new Error with ErrorTypeToolConfigSecretNameIsEmpty.
    72  func NewToolConfigSecretNameIsEmpty(backupRepo string) *intctrlutil.Error {
    73  	return intctrlutil.NewErrorf(ErrorTypeToolConfigSecretNameIsEmpty, `the secret name of tool config from %s is empty`, backupRepo)
    74  }
    75  
    76  // NewBackupPVCNameIsEmpty returns a new Error with ErrorTypeBackupPVCNameIsEmpty.
    77  func NewBackupPVCNameIsEmpty(backupRepo, backupPolicyName string) *intctrlutil.Error {
    78  	return intctrlutil.NewErrorf(ErrorTypeBackupPVCNameIsEmpty, `the persistentVolumeClaim name of %s is empty in BackupPolicy "%s"`, backupRepo, backupPolicyName)
    79  }
    80  
    81  // NewBackupJobFailed returns a new Error with ErrorTypeBackupJobFailed.
    82  func NewBackupJobFailed(jobName string) *intctrlutil.Error {
    83  	return intctrlutil.NewErrorf(ErrorTypeBackupJobFailed, `backup job "%s" failed`, jobName)
    84  }
    85  
    86  // NewInvalidLogfileBackupName returns a new Error with ErrorTypeInvalidLogfileBackupName.
    87  func NewInvalidLogfileBackupName(backupPolicyName string) *intctrlutil.Error {
    88  	return intctrlutil.NewErrorf(ErrorTypeInvalidLogfileBackupName, `backup name is incorrect for logfile, you can create the logfile backup by enabling the schedule in BackupPolicy "%s"`, backupPolicyName)
    89  }
    90  
    91  // NewBackupScheduleDisabled returns a new Error with ErrorTypeBackupScheduleDisabled.
    92  func NewBackupScheduleDisabled(backupType, backupPolicyName string) *intctrlutil.Error {
    93  	return intctrlutil.NewErrorf(ErrorTypeBackupScheduleDisabled, `%s schedule is disabled, you can enable spec.schedule.%s in BackupPolicy "%s"`, backupType, backupType, backupPolicyName)
    94  }
    95  
    96  // NewBackupLogfileScheduleDisabled returns a new Error with ErrorTypeLogfileScheduleDisabled.
    97  func NewBackupLogfileScheduleDisabled(backupToolName string) *intctrlutil.Error {
    98  	return intctrlutil.NewErrorf(ErrorTypeLogfileScheduleDisabled, `BackupTool "%s" of the backup relies on logfile. Please enable the logfile scheduling firstly`, backupToolName)
    99  }