Skip to content

Commit

Permalink
backup: simplify api about the policy of backup
Browse files Browse the repository at this point in the history
Signed-off-by: Xieql <xieqianglong@huawei.com>
  • Loading branch information
Xieql committed Aug 29, 2023
1 parent f8c1010 commit bf1435f
Show file tree
Hide file tree
Showing 9 changed files with 1,552 additions and 1,124 deletions.
381 changes: 235 additions & 146 deletions docs/content/en/references/backups_v1alpha1_types.html

Large diffs are not rendered by default.

773 changes: 408 additions & 365 deletions manifests/charts/fleet-manager/crds/backup.kurator.dev_backups.yaml

Large diffs are not rendered by default.

553 changes: 365 additions & 188 deletions manifests/charts/fleet-manager/crds/backup.kurator.dev_migrates.yaml

Large diffs are not rendered by default.

704 changes: 393 additions & 311 deletions manifests/charts/fleet-manager/crds/backup.kurator.dev_restores.yaml

Large diffs are not rendered by default.

55 changes: 30 additions & 25 deletions pkg/apis/backups/v1alpha1/backup_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,24 @@ type Backup struct {

type BackupSpec struct {
// Storage details where the backup data should be stored.
// If not set, the backup will use the default Storage that is created during Velero installation.
// +optional
Storage BackupStorage `json:"storage"`

// Schedule defines when to run the Backup using a Cron expression.
// A cron expression is a format used to specify the execution time of recurring tasks, consisting of multiple fields representing different time units.
// For example, "30 * * * *" represents execution at the 30th minute of every hour, "*/15 * * * *" represents execution every 15 minutes, and "10 10,14 * * *" represents execution at 10:10 AM and 2:10 PM every day.
// If not set, the backup will be executed only once.
// +optional
Schedule string `json:"schedule,omitempty"`

// Destination indicates the default clusters where backups should be executed.
// Can be overridden by individual Policies.
// Destination indicates the default clusters where backups should be performed.
// +optional
Destination *Destination `json:"destination,omitempty"`

// Policies are the rules defining how backups should be performed.
// Policy are the rules defining how backups should be performed.
// +optional
Policies []*BackupSyncPolicy `json:"policies,omitempty"`
Policy *BackupPolicy `json:"policy,omitempty"`
}

type BackupStorage struct {
Expand All @@ -76,24 +79,6 @@ type BackupStorageLocation struct {
Region string `json:"region"`
}

type BackupSyncPolicy struct {
// Name of the BackupSyncPolicy.
// If not provided, a default name will be generated.
// This field is recommended for users to set, so that during the restore process, customized restoration can be performed based on this name.
// +optional
Name string `json:"name,omitempty"`

// Destination indicates where the backup should be executed.
// +optional
Destination Destination `json:"destination,omitempty"`

// Policy outlines the specific rules and filters applied during the backup process.
// It determines which resources are selected for backup and any specific conditions or procedures to follow.
// Users can customize this policy to ensure that the backup process aligns with their specific requirements and constraints.
// +optional
Policy BackupPolicy `json:"policy,omitempty"`
}

// Note: partly copied from https://github.com/vmware-tanzu/velero/pkg/apis/backup_types.go
// BackupSpec defines the specification for a backup.
type BackupPolicy struct {
Expand All @@ -103,6 +88,8 @@ type BackupPolicy struct {
// +optional
ResourceFilter *ResourceFilter `json:"resourceFilter,omitempty"`

// TODO: consider SnapshotVolumes for backup

// TTL is a time.Duration-parseable string describing how long the Backup should be retained for.
// +optional
TTL metav1.Duration `json:"ttl,omitempty"`
Expand All @@ -129,9 +116,28 @@ type BackupStatus struct {
// +optional
Phase string `json:"phase,omitempty"`

// BackupDetails provides a detailed status for each backup in each cluster.
// Details provides a detailed status for each backup in each cluster.
// +optional
BackupDetails []*velerov1.BackupStatus `json:"backupDetails,omitempty"`
Details []*BackupDetails `json:"backupDetails,omitempty"`
}

type BackupDetails struct {
// ClusterName is the Name of the cluster where the backup is being performed.
// +optional
ClusterName string `json:"clusterName,omitempty"`

// ClusterKind is the kind of ClusterName recorded in Kurator.
// +optional
ClusterKind string `json:"clusterKind,omitempty"`

// BackupNameInCluster is the name of the backup being performed within this cluster.
// This BackupNameInCluster is unique in Storage.
// +optional
BackupNameInCluster string `json:"backupNameInCluster,omitempty"`

// BackupStatusInCluster is the current status of the backup performed within this cluster.
// +optional
BackupStatusInCluster *velerov1.BackupStatus `json:"backupStatusInCluster,omitempty"`
}

// BackupList contains a list of Backup.
Expand All @@ -142,4 +148,3 @@ type BackupList struct {
metav1.ListMeta `json:"metadata,omitempty"`
Items []Backup `json:"items"`
}

6 changes: 2 additions & 4 deletions pkg/apis/backups/v1alpha1/migrate_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ limitations under the License.
package v1alpha1

import (
velerov1 "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
capiv1 "sigs.k8s.io/cluster-api/api/v1beta1"
)
Expand Down Expand Up @@ -96,10 +95,10 @@ type MigrateStatus struct {
Phase string `json:"phase,omitempty"`

// SourceClusterStatus provides a detailed status for backup in SourceCluster.
SourceClusterStatus *velerov1.BackupStatus `json:"sourceClusterStatus,omitempty"`
SourceClusterStatus *BackupDetails `json:"sourceClusterStatus,omitempty"`

// TargetClusterStatus provides a detailed status for each restore in each TargetCluster.
TargetClusterStatus []*velerov1.RestoreStatus `json:"targetClusterStatus,omitempty"`
TargetClusterStatus []*RestoreDetails `json:"targetClusterStatus,omitempty"`
}

// MigrateList contains a list of Migrate.
Expand All @@ -110,4 +109,3 @@ type MigrateList struct {
metav1.ListMeta `json:"metadata,omitempty"`
Items []Migrate `json:"items"`
}

42 changes: 26 additions & 16 deletions pkg/apis/backups/v1alpha1/restore_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,14 @@ type RestoreSpec struct {
// BackupName specifies the backup on which this restore operation is based.
BackupName string `json:"backupName"`

// Policies defines the customization rules for the restore.
// If null, the backup will be fully restored using default settings.
// Destination indicates the clusters where restore should be performed.
// +optional
Policies []*RestoreSyncPolicy `json:"policies,omitempty"`
}
Destination *Destination `json:"destination,omitempty"`

type RestoreSyncPolicy struct {
// Name is the unique identifier for this restore policy. It should match the name in the backup policy.
// to ensure the restore policy corresponds to the correct backup policy.
// If a name provided by the user doesn't match any backup policy, the restore operation will fail
// and return a clear error message.
Name string `json:"name"`

// Policy indicates the rules and filters for the restore.
// Policy defines the customization rules for the restore.
// If null, the backup will be fully restored using default settings.
// +optional
Policy RestorePolicy `json:"policy,omitempty"`
Policy *RestorePolicy `json:"policy,omitempty"`
}

// Note: partly copied from https://github.com/vmware-tanzu/velero/pkg/apis/restore_types.go
Expand Down Expand Up @@ -112,9 +104,28 @@ type RestoreStatus struct {
// +optional
Phase string `json:"phase,omitempty"`

// RestoreDetails provides a detailed status for each restore in each cluster.
// Details provides a detailed status for each restore in each cluster.
// +optional
Details []*RestoreDetails `json:"restoreDetails,omitempty"`
}

type RestoreDetails struct {
// ClusterName is the Name of the cluster where the restore is being performed.
// +optional
RestoreDetails []*velerov1.RestoreStatus `json:"restoreDetails,omitempty"`
ClusterName string `json:"clusterName,omitempty"`

// ClusterKind is the kind of ClusterName recorded in Kurator.
// +optional
ClusterKind string `json:"clusterKind,omitempty"`

// RestoreNameInCluster is the name of the restore being performed within this cluster.
// This RestoreNameInCluster is unique in Storage.
// +optional
RestoreNameInCluster string `json:"restoreNameInCluster,omitempty"`

// RestoreStatusInCluster is the current status of the restore performed within this cluster.
// +optional
RestoreStatusInCluster *velerov1.RestoreStatus `json:"restoreStatusInCluster,omitempty"`
}

// RestoreList contains a list of Restore.
Expand All @@ -125,4 +136,3 @@ type RestoreList struct {
metav1.ListMeta `json:"metadata,omitempty"`
Items []Restore `json:"items"`
}

18 changes: 15 additions & 3 deletions pkg/apis/backups/v1alpha1/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,29 @@ limitations under the License.

package v1alpha1

import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// Destination defines a fleet or specific clusters.
type Destination struct {
// Fleet is the name of fleet.
// +required
Fleet string `json:"fleet"`
// The field, in combination with ClusterSelector, can determine a set of clusters.
// In addition to this approach, users can also directly specify clusters through the field Clusters.
// +optional
Fleet string `json:"fleet,omitempty"`

// ClusterSelector specifies the selectors to select the clusters within the fleet.
// If unspecified, all clusters in the fleet will be selected.
// The field will only take effect when Fleet is set.
// +optional
ClusterSelector *ClusterSelector `json:"clusterSelector,omitempty"`

// Clusters determine a set of clusters as destination clusters.
// The field will only take effect when Fleet is not set.
// +optional
Clusters []*corev1.ObjectReference `json:"clusters,omitempty"`
}

type ClusterSelector struct {
Expand Down

0 comments on commit bf1435f

Please sign in to comment.