-
Notifications
You must be signed in to change notification settings - Fork 182
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
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
// +kubebuilder:validation:MaxProperties=30 | ||
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="forbidden to update spec.parameters" | ||
// +optional | ||
Parameters map[string]string `json:"parameters,omitempty"` |
There was a problem hiding this comment.
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"` |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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 | ||
} |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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) | ||
} | ||
} |
There was a problem hiding this comment.
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{} |
There was a problem hiding this comment.
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] { |
There was a problem hiding this comment.
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) | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
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 addparametersSchema
to theactionSet
API to define the schema of necessary configuration parameters, and addparameters
to thebackup
andrestore
API to pass parameter values to backup or restore workloads through environment variables.actionset API
The
actionset
API introduces theparametersSchema
structure to define the parameter schema for backup and restore tools. ThewithParameters
method specifies the parameters required for backup or restore operations.on-demand backup
A read-only
parameters
structure has been added underbackup.spec
in the backup API to pass configuration values defined byparametersSchema
.scheduled backup
The
schedulePolicy
structure needs to include aparameters
structure. The cron job created bybackupSchedule
will regularly execute on-demand backups with the correspondingparameters
structure. If multiple parameter configurations are needed, newschedulePolicy
entries with differentparameters
structures can be appended to theschedulePolicy
array. Additionally, aname
field has been added toschedulePolicy
to indicate different configurations.opsRequest API
The
opsRequest.spec.restore
andopsRequest.spec.backup
sections need to include aparameters
structure for generating the corresponding restore and backup.