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

Merged
merged 15 commits into from
Nov 29, 2024
15 changes: 15 additions & 0 deletions apis/dataprotection/v1alpha1/actionset_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ type ActionSetSpec struct {
// +kubebuilder:validation:Required
BackupType BackupType `json:"backupType"`

// Specifies the schema of parameters in backups and restores before their usage.
//
// +optional
ParametersSchema *SelectiveParametersSchema `json:"parametersSchema,omitempty"`

// Specifies a list of environment variables to be set in the container.
//
// +kubebuilder:pruning:PreserveUnknownFields
Expand Down Expand Up @@ -117,6 +122,11 @@ type BackupActionSpec struct {
//
// +optional
PreDeleteBackup *BaseJobActionSpec `json:"preDelete,omitempty"`

// Specifies the parameters used by the backup action
//
// +optional
WithParameters []string `json:"withParameters,omitempty"`
}

// BackupDataActionSpec defines how to back up data.
Expand Down Expand Up @@ -162,6 +172,11 @@ type RestoreActionSpec struct {
// +optional
// +kubebuilder:default=true
BaseBackupRequired *bool `json:"baseBackupRequired,omitempty"`

// Specifies the parameters used by the restore action
//
// +optional
WithParameters []string `json:"withParameters,omitempty"`
}

// ActionSpec defines an action that should be executed. Only one of the fields may be set.
Expand Down
11 changes: 11 additions & 0 deletions apis/dataprotection/v1alpha1/backup_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
)

// BackupSpec defines the desired state of Backup.
// +kubebuilder:validation:XValidation:rule="has(oldSelf.parameters) == has(self.parameters)",message="forbidden to update spec.parameters"
type BackupSpec struct {
// Specifies the backup policy to be applied for this backup.
//
Expand Down Expand Up @@ -74,6 +75,16 @@ type BackupSpec struct {
// +optional
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="forbidden to update spec.parentBackupName"
ParentBackupName string `json:"parentBackupName,omitempty"`

// Specifies a list of name-value pairs representing parameters and their corresponding values.
// Parameters match the schema specified in the `actionset.spec.parametersSchema`
//
// +listType=map
// +listMapKey=name
// +kubebuilder:validation:MaxItems=128
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="forbidden to update spec.parameters"
// +optional
Parameters []ParameterPair `json:"parameters,omitempty"`
}

// BackupStatus defines the observed state of Backup.
Expand Down
17 changes: 17 additions & 0 deletions apis/dataprotection/v1alpha1/backupschedule_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ type SchedulePolicy struct {
// +optional
Enabled *bool `json:"enabled,omitempty"`

// Specifies the name of the schedule. Names cannot be duplicated.
// If the name is empty, it will be considered the same as the value of the backupMethod below.
//
// +optional
Name string `json:"name,omitempty"`
gnolong marked this conversation as resolved.
Show resolved Hide resolved

// Specifies the backup method name that is defined in backupPolicy.
//
// +kubebuilder:validation:Required
Expand Down Expand Up @@ -76,6 +82,17 @@ type SchedulePolicy struct {
// +optional
// +kubebuilder:default="7d"
RetentionPeriod RetentionPeriod `json:"retentionPeriod,omitempty"`

// Specifies a list of name-value pairs representing parameters and their corresponding values.
// Parameters match the schema specified in the `actionset.spec.parametersSchema`
//
// +patchMergeKey=name
// +patchStrategy=merge,retainKeys
// +listType=map
// +listMapKey=name
// +kubebuilder:validation:MaxItems=128
// +optional
Parameters []ParameterPair `json:"parameters,omitempty"`
}

// BackupScheduleStatus defines the observed state of BackupSchedule.
Expand Down
11 changes: 11 additions & 0 deletions apis/dataprotection/v1alpha1/restore_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
)

// RestoreSpec defines the desired state of Restore
// +kubebuilder:validation:XValidation:rule="has(oldSelf.parameters) == has(self.parameters)",message="forbidden to update spec.parameters"
type RestoreSpec struct {
// Specifies the backup to be restored. The restore behavior is based on the backup type:
//
Expand Down Expand Up @@ -84,6 +85,16 @@ type RestoreSpec struct {
// +kubebuilder:validation:Minimum=0
// +kubebuilder:validation:Maximum=10
BackoffLimit *int32 `json:"backoffLimit,omitempty"`

// Specifies a list of name-value pairs representing parameters and their corresponding values.
// Parameters match the schema specified in the `actionset.spec.parametersSchema`
//
// +listType=map
// +listMapKey=name
// +kubebuilder:validation:MaxItems=128
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="forbidden to update spec.parameters"
// +optional
Parameters []ParameterPair `json:"parameters,omitempty"`
}

// BackupRef describes the backup info.
Expand Down
26 changes: 26 additions & 0 deletions apis/dataprotection/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"unicode"

corev1 "k8s.io/api/core/v1"
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
)

// Phase defines the BackupPolicy and ActionSet CR .status.phase
Expand Down Expand Up @@ -261,3 +262,28 @@ type EncryptionConfig struct {
// +kubebuilder:validation:Required
PassPhraseSecretKeyRef *corev1.SecretKeySelector `json:"passPhraseSecretKeyRef"`
}

type SelectiveParametersSchema struct {
gnolong marked this conversation as resolved.
Show resolved Hide resolved
// Defines the schema for parameters using the OpenAPI v3.
// The supported property types include:
// - string
// - number
// - integer
// - array: Note that only items of string type are supported.
// +kubebuilder:validation:Schemaless
// +kubebuilder:validation:Type=object
// +kubebuilder:pruning:PreserveUnknownFields
// +k8s:conversion-gen=false
// +optional
OpenAPIV3Schema *apiextensionsv1.JSONSchemaProps `json:"openAPIV3Schema,omitempty"`
}

type ParameterPair struct {
// Represents the name of the parameter.
// +kubebuilder:validation:Required
Name string `json:"name"`

// Represents the parameter values.
// +kubebuilder:validation:Required
Value string `json:"value"`
}
66 changes: 65 additions & 1 deletion apis/dataprotection/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions apis/operations/v1alpha1/opsrequest_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (

appsv1 "github.com/apecloud/kubeblocks/apis/apps/v1"
appsv1alpha1 "github.com/apecloud/kubeblocks/apis/apps/v1alpha1"
dpv1alpha1 "github.com/apecloud/kubeblocks/apis/dataprotection/v1alpha1"
)

// OpsRequestSpec defines the desired state of OpsRequest
Expand Down Expand Up @@ -205,12 +206,15 @@ type SpecificOpsRequest struct {
ExposeList []Expose `json:"expose,omitempty"`

// Specifies the parameters to back up a Cluster.
//
// +kubebuilder:validation:XValidation:rule="has(oldSelf.parameters) == has(self.parameters)",message="forbidden to update backup.parameters"
// +optional
Backup *Backup `json:"backup,omitempty"`

// Specifies the parameters to restore a Cluster.
// Note that this restore operation will roll back cluster services.
//
// +kubebuilder:validation:XValidation:rule="has(oldSelf.parameters) == has(self.parameters)",message="forbidden to update restore.parameters"
// +optional
Restore *Restore `json:"restore,omitempty"`

Expand Down Expand Up @@ -906,6 +910,16 @@ type Backup struct {
//
// +optional
ParentBackupName string `json:"parentBackupName,omitempty"`

// Specifies a list of name-value pairs representing parameters and their corresponding values.
// Parameters match the schema specified in the `actionset.spec.parametersSchema`
//
// +listType=map
// +listMapKey=name
// +kubebuilder:validation:MaxItems=128
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="forbidden to update parameters"
// +optional
Parameters []dpv1alpha1.ParameterPair `json:"parameters,omitempty"`
}

type Restore struct {
Expand Down Expand Up @@ -947,6 +961,16 @@ type Restore struct {
//
// This setting is useful for coordinating PostReady operations across the Cluster for optimal cluster conditions.
DeferPostReadyUntilClusterRunning bool `json:"deferPostReadyUntilClusterRunning,omitempty"`

// Specifies a list of name-value pairs representing parameters and their corresponding values.
// Parameters match the schema specified in the `actionset.spec.parametersSchema`
//
// +listType=map
// +listMapKey=name
// +kubebuilder:validation:MaxItems=128
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="forbidden to update parameters"
// +optional
Parameters []dpv1alpha1.ParameterPair `json:"parameters,omitempty"`
}

// OpsRequestStatus represents the observed state of an OpsRequest.
Expand Down
13 changes: 12 additions & 1 deletion apis/operations/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading