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 30, 2023
1 parent f8c1010 commit 47f0d67
Show file tree
Hide file tree
Showing 9 changed files with 1,693 additions and 1,437 deletions.
584 changes: 271 additions & 313 deletions docs/content/en/references/backups_v1alpha1_types.html

Large diffs are not rendered by default.

833 changes: 434 additions & 399 deletions manifests/charts/fleet-manager/crds/backup.kurator.dev_backups.yaml

Large diffs are not rendered by default.

622 changes: 391 additions & 231 deletions manifests/charts/fleet-manager/crds/backup.kurator.dev_migrates.yaml

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

91 changes: 45 additions & 46 deletions pkg/apis/backups/v1alpha1/backup_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,59 +39,31 @@ type Backup struct {
}

type BackupSpec struct {
// Storage details where the backup data should be stored.
Storage BackupStorage `json:"storage"`
// TODO: consider add Storage setting for backup

// 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.
// ┌───────────── minute (0 - 59)
// │ ┌───────────── hour (0 - 23)
// │ │ ┌───────────── day of the month (1 - 31)
// │ │ │ ┌───────────── month (1 - 12)
// │ │ │ │ ┌───────────── day of the week (0 - 6) (Sunday to Saturday;
// │ │ │ │ │ 7 is also Sunday on some systems)
// │ │ │ │ │
// │ │ │ │ │
// * * * * *
// For example, "30 * * * *" represents execution at the 30th minute of every hour, 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"`
}

type BackupStorage struct {
// Location specifies the location where the backup data will be stored.
Location BackupStorageLocation `json:"location"`

// Credentials to access the backup storage location.
Credentials string `json:"credentials"`
}

type BackupStorageLocation struct {
// Bucket specifies the storage bucket name.
Bucket string `json:"bucket"`
// Provider specifies the storage provider type (e.g., aws).
Provider string `json:"provider"`
// S3Url provides the endpoint URL for S3-compatible storage.
S3Url string `json:"s3Url"`
// Region specifies the region of the storage.
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"`
Policy *BackupPolicy `json:"policy,omitempty"`
}

// Note: partly copied from https://github.com/vmware-tanzu/velero/pkg/apis/backup_types.go
Expand All @@ -103,13 +75,22 @@ 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"`

// OrderedResources specifies the backup order of resources of specific Kind.
// The map key is the resource name and value is a list of object names separated by commas.
// Each resource name has format "namespace/objectname". For cluster resources, simply use "objectname".
// For example, if you have a specific order for pods, such as "pod1, pod2, pod3" with all belonging to the "ns1" namespace,
// and a specific order for persistentvolumes, such as "pv4, pv8", you can use the orderedResources field in YAML format as shown below:
// ```yaml
// orderedResources:
// pods: "ns1/pod1, ns1/pod2, ns1/pod3"
// persistentvolumes: "pv4, pv8"
// ```
// +optional
// +nullable
OrderedResources map[string]string `json:"orderedResources,omitempty"`
Expand All @@ -129,9 +110,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 +142,3 @@ type BackupList struct {
metav1.ListMeta `json:"metadata,omitempty"`
Items []Backup `json:"items"`
}

9 changes: 2 additions & 7 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 All @@ -37,9 +36,6 @@ type Migrate struct {
}

type MigrateSpec struct {
// Storage details where the data should be stored.
Storage BackupStorage `json:"storage"`

// SourceCluster represents the source cluster for migration.
SourceCluster *Destination `json:"sourceCluster"`

Expand Down Expand Up @@ -96,10 +92,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 +106,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"`
}

38 changes: 30 additions & 8 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 All @@ -50,37 +62,52 @@ type ResourceFilter struct {
ExcludedNamespaces []string `json:"excludedNamespaces,omitempty"`

// IncludedResources is a slice of resource names to include in the backup.
// For example, we can populate this string array with "deployments" and "configmaps", then we will select all resources of type deployments and configmaps,
// If empty, all resources are included.
// Cannot work with IncludedClusterScopedResources, ExcludedClusterScopedResources, IncludedNamespaceScopedResources and ExcludedNamespaceScopedResources.
// +optional
// +nullable
IncludedResources []string `json:"includedResources,omitempty"`

// ExcludedResources is a slice of resource names that are not included in the backup.
// Cannot work with IncludedClusterScopedResources, ExcludedClusterScopedResources, IncludedNamespaceScopedResources and ExcludedNamespaceScopedResources.
// +optional
// +nullable
ExcludedResources []string `json:"excludedResources,omitempty"`

// IncludeClusterResources specifies whether cluster-scoped resources should be included for consideration in the backup.
// Cannot work with IncludedClusterScopedResources, ExcludedClusterScopedResources, IncludedNamespaceScopedResources and ExcludedNamespaceScopedResources.
// +optional
// +nullable
IncludeClusterResources *bool `json:"includeClusterResources,omitempty"`

// IncludedClusterScopedResources is a slice of cluster-scoped resource type names to include in the backup.
// For example, we can populate this string array with "storageclasses" and "clusterroles", then we will select all resources of type storageclasses and clusterroles,
// If set to "*", all cluster-scoped resource types are included.
// The default value is empty, which means only related cluster-scoped resources are included.
// Cannot work with IncludedResources, ExcludedResources and IncludeClusterResources.
// +optional
// +nullable
IncludedClusterScopedResources []string `json:"includedClusterScopedResources,omitempty"`

// ExcludedClusterScopedResources is a slice of cluster-scoped resource type names to exclude from the backup.
// If set to "*", all cluster-scoped resource types are excluded. The default value is empty.
// Cannot work with IncludedResources, ExcludedResources and IncludeClusterResources.
// +optional
// +nullable
ExcludedClusterScopedResources []string `json:"excludedClusterScopedResources,omitempty"`

// IncludedNamespaceScopedResources is a slice of namespace-scoped resource type names to include in the backup.
// For example, we can populate this string array with "deployments" and "configmaps", then we will select all resources of type deployments and configmaps,
// The default value is "*".
// Cannot work with IncludedResources, ExcludedResources and IncludeClusterResources.
// +optional
// +nullable
IncludedNamespaceScopedResources []string `json:"includedNamespaceScopedResources,omitempty"`

// ExcludedNamespaceScopedResources is a slice of namespace-scoped resource type names to exclude from the backup.
// If set to "*", all namespace-scoped resource types are excluded. The default value is empty.
// Cannot work with IncludedResources, ExcludedResources and IncludeClusterResources.
// +optional
// +nullable
ExcludedNamespaceScopedResources []string `json:"excludedNamespaceScopedResources,omitempty"`
Expand All @@ -97,9 +124,4 @@ type ResourceFilter struct {
// +optional
// +nullable
OrLabelSelectors []*metav1.LabelSelector `json:"orLabelSelectors,omitempty"`

// IncludeClusterResources specifies whether cluster-scoped resources should be included for consideration in the backup.
// +optional
// +nullable
IncludeClusterResources *bool `json:"includeClusterResources,omitempty"`
}

0 comments on commit 47f0d67

Please sign in to comment.