Skip to content

Commit

Permalink
Update apis
Browse files Browse the repository at this point in the history
Signed-off-by: Md. Ishtiaq Islam <[email protected]>
  • Loading branch information
ishtiaqhimel committed Jul 12, 2024
1 parent c189406 commit ced003d
Show file tree
Hide file tree
Showing 18 changed files with 39,120 additions and 10,396 deletions.
1 change: 1 addition & 0 deletions apis/constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const (
PrefixRetentionPolicy = "retentionpolicy"
PrefixPopulate = "populate"
PrefixPrime = "prime"
PrefixVerify = "verify"
)

const (
Expand Down
4 changes: 4 additions & 0 deletions apis/core/v1alpha1/backupbatch_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ type BackupBatchSpec struct {
// Session defines a list of session configurations that specifies when and how to take backup.
Sessions []BatchSession `json:"sessions,omitempty"`

// VerificationStrategies specifies a list of backup verification configurations
// +optional
VerificationStrategies []VerificationStrategy `json:"verificationStrategies,omitempty"`

// Paused indicates that the BackupBatch has been paused from taking backup. Default value is 'false'.
// If you set `paused` field to `true`, KubeStash will suspend the respective backup triggering CronJob and
// skip processing any further events for this BackupBatch.
Expand Down
112 changes: 99 additions & 13 deletions apis/core/v1alpha1/backupconfiguration_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (

batchv1 "k8s.io/api/batch/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
kmapi "kmodules.xyz/client-go/api/v1"
ofst "kmodules.xyz/offshoot-api/api/v1"
)
Expand Down Expand Up @@ -298,16 +297,9 @@ type VerificationStrategy struct {
// Name indicates the name of this strategy.
Name string `json:"name,omitempty"`

// Namespace specifies where the verification resources should be created.
Namespace string `json:"namespace,omitempty"`

// Verifier refers to the BackupVerification CR that defines how to verify this particular data.
Verifier *kmapi.ObjectReference `json:"verifier,omitempty"`

// Params specifies the parameters that will be used by the verifier.
// +kubebuilder:pruning:PreserveUnknownFields
// RestoreOption specifies the restore target, addonInfo and manifestOption for backup verification
// +optional
Params *runtime.RawExtension `json:"params,omitempty"`
RestoreOption *RestoreOption `json:"restoreOption,omitempty"`

// VerifySchedule specifies the schedule of backup verification in Cron format, see https://en.wikipedia.org/wiki/Cron.
VerifySchedule string `json:"verifySchedule,omitempty"`
Expand All @@ -316,13 +308,30 @@ type VerificationStrategy struct {
// +optional
KeepAlive *metav1.Time `json:"keepAlive,omitempty"`

// Tasks specifies a list of restore tasks and their configuration parameters for backup verification.
Tasks []TaskReference `json:"tasks,omitempty"`

// OnFailure specifies what to do if the verification fail.
// +optional
// OnFailure FailurePolicy `json:"onFailure,omitempty"`

// Type indicate the types of verifier that will verify the backup.
// Valid values are:
// - "RestoreOnly": KubeStash will create a RestoreSession with the tasks provided in BackupConfiguration's verificationStrategies section.
// - "File": KubeStash will restore the data and then create a job to check if the files exist or not. This type is recommended for workload backup verification.
// - "Query": KubeStash operator will restore data and then create a job to run the queries. This type is recommended for database backup verification.
// - "Script": KubeStash operator will restore data and then create a job to run the script. This type is recommended for database backup verification.
Type VerificationType `json:"type,omitempty"`

// File specifies the file paths information whose existence will be checked for backup verification.
// +optional
File *FileVerifierSpec `json:"file,omitempty"`

// Query specifies the queries to be run to verify backup.
// +optional
Query *QueryVerifierSpec `json:"query,omitempty"`

// Script specifies the script to be run to verify backup.
// +optional
Script *ScriptVerifierSpec `json:"script,omitempty"`

// RetryConfig specifies the behavior of the retry mechanism in case of a verification failure.
// +optional
RetryConfig *RetryConfig `json:"retryConfig,omitempty"`
Expand All @@ -339,6 +348,83 @@ type VerificationStrategy struct {
RuntimeSettings ofst.RuntimeSettings `json:"runtimeSettings,omitempty"`
}

type RestoreOption struct {
// Target indicates the target application where the data will be restored
// +optional
Target *kmapi.TypedObjectReference `json:"target,omitempty"`

// ManifestOptions provide options to select particular manifest object to restore
// +optional
ManifestOptions *ManifestRestoreOptions `json:"manifestOptions,omitempty"`

// AddonInfo specifies addon configuration that will be used to restore this target.
AddonInfo *AddonInfo `json:"addonInfo,omitempty"`
}

// VerificationType specifies the type of verifier that will verify the backup
// +kubebuilder:validation:Enum=RestoreOnly;File;Query;Script
type VerificationType string

const (
RestoreOnlyVerificationType VerificationType = "RestoreOnly"
FileVerificationType VerificationType = "File"
QueryVerificationType VerificationType = "Query"
ScriptVerificationType VerificationType = "Script"
)

// FileVerifierSpec defines the file paths information whose existence will be checked from verifier job.
type FileVerifierSpec struct {
// Paths specifies the list of paths whose existence will be checked.
// These paths must be absolute paths.
Paths []string `json:"paths,omitempty"`
}

// QueryVerifierSpec defines the queries to be run from verifier job.
type QueryVerifierSpec struct {
MySQL []MySQLQueryOpt `json:"mysql,omitempty"`
Postgres []PostgresQueryOpt `json:"postgres,omitempty"`
MongoDB []MongoDBQueryOpt `json:"mongodb,omitempty"`
Elasticsearch []ElasticsearchQueryOpt `json:"elasticsearch,omitempty"`
Redis []RedisQueryOpt `json:"redis,omitempty"`
}

type MySQLQueryOpt struct {
Database string `json:"database,omitempty"`
Table string `json:"table,omitempty"`
RowCount *int32 `json:"rowCount,omitempty"`
}

type PostgresQueryOpt struct {
Database string `json:"database,omitempty"`
Schema string `json:"schema,omitempty"`
Table string `json:"table,omitempty"`
RowCount *int32 `json:"rowCount,omitempty"`
}

type MongoDBQueryOpt struct {
Database string `json:"database,omitempty"`
Collection string `json:"collection,omitempty"`
DocumentCount *int32 `json:"rowCount,omitempty"`
}

type ElasticsearchQueryOpt struct {
Index string `json:"index,omitempty"`
}

type RedisQueryOpt struct {
Database string `json:"database,omitempty"`
DbSize *int32 `json:"dbSize,omitempty"`
}

// ScriptVerifierSpec defines the script location in verifier job and the args to be provided with the script.
type ScriptVerifierSpec struct {
// Location specifies the absolute path of the script file's location.
Location string `json:"location,omitempty"`

// Args specifies the arguments to be provided with the script.
Args []string `json:"args,omitempty"`
}

// BackupHooks specifies the hooks that will be executed before and/or after backup
type BackupHooks struct {
// PreBackup specifies a list of hooks that will be executed before backup
Expand Down
8 changes: 4 additions & 4 deletions apis/core/v1alpha1/backupconfiguration_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -448,12 +448,12 @@ func (b *BackupConfiguration) validateVerificationStrategies() error {
}

for _, vs := range b.Spec.VerificationStrategies {
if vs.Namespace == "" {
return fmt.Errorf("namespace for verification strategy %q cannot be empty", vs.Name)
if vs.RestoreOption == nil {
return fmt.Errorf("restoreOption for verification strategy %q cannot be empty", vs.Name)
}

if vs.Verifier == nil {
return fmt.Errorf("verifier for verification strategy %q cannot be empty", vs.Name)
if vs.RestoreOption.AddonInfo == nil {
return fmt.Errorf("addonInfo in restoreOption for verification strategy %q cannot be empty", vs.Name)
}

if vs.VerifySchedule == "" {
Expand Down
11 changes: 0 additions & 11 deletions apis/core/v1alpha1/backupsession_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ func (b *BackupSession) CalculatePhase() BackupSessionPhase {
b.failedToExecutePreBackupHooks() ||
b.failedToExecutePostBackupHooks() ||
b.failedToApplyRetentionPolicy() ||
b.verificationsFailed() ||
b.sessionHistoryCleanupFailed()) {
return BackupSessionFailed
}
Expand Down Expand Up @@ -110,16 +109,6 @@ func (b *BackupSession) failedToApplyRetentionPolicy() bool {
return false
}

func (b *BackupSession) verificationsFailed() bool {
for _, v := range b.Status.Verifications {
if v.Phase == VerificationFailed {
return true
}
}

return false
}

func (b *BackupSession) calculateBackupSessionPhaseFromSnapshots() BackupSessionPhase {
status := b.Status.Snapshots
if len(status) == 0 {
Expand Down
42 changes: 0 additions & 42 deletions apis/core/v1alpha1/backupverification_helpers.go

This file was deleted.

Loading

0 comments on commit ced003d

Please sign in to comment.