Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support backup and restore parameters #8472

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

gnolong
Copy link
Contributor

@gnolong gnolong commented Nov 15, 2024

fix #8475
Backup and restore tools like pg_dump, pg_restore, mysqldump, etc., require various configuration parameters when performing database-level, schema-level, or table-level tasks, and these parameter structures differ among database engines. Therefore, we add parametersSchema to the actionSet API to define the schema of necessary configuration parameters, and add parameters to the backup and restore API to pass parameter values to backup or restore workloads through environment variables.

  • actionset API
    The actionset API introduces the parametersSchema structure to define the parameter schema for backup and restore tools. The withParameters method specifies the parameters required for backup or restore operations.

  • on-demand backup
    A read-only parameters structure has been added under backup.spec in the backup API to pass configuration values defined by parametersSchema.

  • scheduled backup
    The schedulePolicy structure needs to include a parameters structure. The cron job created by backupSchedule will regularly execute on-demand backups with the corresponding parameters structure. If multiple parameter configurations are needed, new schedulePolicy entries with different parameters structures can be appended to the schedulePolicy array. Additionally, a name field has been added to schedulePolicy to indicate different configurations.

  • opsRequest API
    The opsRequest.spec.restore and opsRequest.spec.backup sections need to include a parameters structure for generating the corresponding restore and backup.

@github-actions github-actions bot added the size/XXL Denotes a PR that changes 1000+ lines. label Nov 15, 2024
Copy link

codecov bot commented Nov 18, 2024

Codecov Report

Attention: Patch coverage is 36.26943% with 123 lines in your changes missing coverage. Please review.

Project coverage is 60.93%. Comparing base (c3861c2) to head (c00df14).
Report is 6 commits behind head on main.

Files with missing lines Patch % Lines
pkg/dataprotection/backup/scheduler.go 27.77% 24 Missing and 2 partials ⚠️
pkg/dataprotection/utils/utils.go 0.00% 26 Missing ⚠️
pkg/dataprotection/backup/utils.go 0.00% 16 Missing ⚠️
pkg/dataprotection/restore/utils.go 0.00% 15 Missing ⚠️
pkg/dataprotection/utils/backup.go 0.00% 13 Missing ⚠️
controllers/dataprotection/actionset_controller.go 78.12% 4 Missing and 3 partials ⚠️
pkg/dataprotection/utils/envvar.go 0.00% 6 Missing ⚠️
...trollers/apps/transformer_cluster_backup_policy.go 54.54% 4 Missing and 1 partial ⚠️
.../dataprotection/backuppolicytemplate_controller.go 76.47% 2 Missing and 2 partials ⚠️
pkg/controller/plan/restore.go 33.33% 3 Missing and 1 partial ⚠️
... and 1 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8472      +/-   ##
==========================================
- Coverage   61.11%   60.93%   -0.18%     
==========================================
  Files         351      351              
  Lines       41782    41953     +171     
==========================================
+ Hits        25534    25565      +31     
- Misses      13922    14073     +151     
+ Partials     2326     2315      -11     
Flag Coverage Δ
unittests 60.93% <36.26%> (-0.18%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@gnolong gnolong marked this pull request as ready for review November 18, 2024 07:42
@gnolong gnolong requested review from ldming, wangyelei, zjx20 and a team as code owners November 18, 2024 07:42
// +kubebuilder:validation:MaxProperties=30
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="forbidden to update spec.parameters"
// +optional
Parameters map[string]string `json:"parameters,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using name/value pairs such as environment variables, if encrypted information needs to be obtained from a secret in the future, it would be better to expand this approach.

//
// +kubebuilder:validation:Pattern:=`^[a-z0-9]([a-z0-9\.\-]*[a-z0-9])?$`
// +optional
Name string `json:"name,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add this api in backupPolicyTemplate

// Specifies parameters and their corresponding values.
// Parameters match the schema specified in the `actionset.spec.parametersSchema`
//
// +kubebuilder:validation:MaxProperties=30
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MaxProperties=128

@@ -312,6 +312,8 @@ func (r *backupPolicyBuilder) buildBackupSchedule(
CronExpression: s.CronExpression,
Enabled: s.Enabled,
RetentionPeriod: s.RetentionPeriod,
Name: s.Name,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if s.Name is empty, using the backupMethod name.

for _, s := range backupSchedule.Spec.Schedules {
scheduleMethodMap[s.BackupMethod] = struct{}{}
if len(s.Name) > 0 {
scheduleNameMap[s.Name] = true
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To maintain compatibility with previous versions, if the name is empty, use the backup method name.

and replace the scheduleMethodMap

withParameters = actionSet.Spec.Backup.WithParameters

}
if err := dputils.ValidateParameters(actionSet.Spec.ParametersSchema, withParameters, backup.Spec.Parameters); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is better to validate alls conditions in a function. and you can input a actionSet object and a bool to check if ti is backup.

}
if err := dputils.ValidateParameters(actionSet.Spec.ParametersSchema, withParameters, v.Parameters); err != nil {
message += fmt.Sprintf(`fails to validate parameters of backupMethod "%s": %v;`, v.BackupMethod, err)
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

if len(schedules) == 0 {
return nil
}
nameMap := map[string]bool{}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is better to use strucet{} if the value is not used

continue
}
// names cannot be duplicated
if nameMap[sp.Name] {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_, ok := nameMap[sp.Name] ; ok

return fmt.Errorf("fails to validate parameters with actionset %s: %v", backupSet.ActionSet.Name, err)
}
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/user-interaction size/XXL Denotes a PR that changes 1000+ lines.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Features] support backup and restore parameters to implement database and table-level backups
3 participants