Skip to content

Commit

Permalink
backup: update with review
Browse files Browse the repository at this point in the history
Signed-off-by: Xieql <[email protected]>
  • Loading branch information
Xieql committed Sep 7, 2023
1 parent b9546b9 commit 041835d
Show file tree
Hide file tree
Showing 10 changed files with 1,969 additions and 1,666 deletions.
739 changes: 328 additions & 411 deletions docs/content/en/references/backups_v1alpha1_types.html

Large diffs are not rendered by default.

839 changes: 427 additions & 412 deletions manifests/charts/fleet-manager/crds/backup.kurator.dev_backups.yaml

Large diffs are not rendered by default.

691 changes: 419 additions & 272 deletions manifests/charts/fleet-manager/crds/backup.kurator.dev_migrates.yaml

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

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

type BackupSpec struct {
// Storage details where the backup data should be stored.
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.
// ┌───────────── 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.
// +optional
Destination *Destination `json:"destination,omitempty"`
// Destination indicates the clusters where backups should be performed.
// +required
Destination Destination `json:"destination"`

// 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"`
Policy *BackupPolicy `json:"policy,omitempty"`
}

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.
// Note: partly copied from https://github.com/vmware-tanzu/velero/blob/v1.11.1/pkg/apis/velero/v1/backup_types.go
// BackupPolicy defines the specification for a backup policy.
type BackupPolicy struct {
// ResourceFilter specifies which resources should be included in the backup.
// It acts as a selective criterion to determine which resources are relevant for backup.
// If not set, the backup process will consider all resources. This filter helps in optimizing the backup process by excluding unnecessary data.
// +optional
ResourceFilter *ResourceFilter `json:"resourceFilter,omitempty"`

// TODO: support volume snapshot

// 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"`

// ItemOperationTimeout specifies the time used to wait for asynchronous BackupItemAction operations.
// The default value is 1 hour.
// +optional
ItemOperationTimeout metav1.Duration `json:"itemOperationTimeout,omitempty"`
}

type BackupStatus struct {
Expand All @@ -129,7 +103,35 @@ 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
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
BackupDetails []*velerov1.BackupStatus `json:"backupDetails,omitempty"`
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.
// +kubebuilder:object:root=true
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type BackupList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []Backup `json:"items"`
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,22 @@ 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.
// Destination defines a target set of clusters, either through a fleet or by specifying them directly.
type Destination struct {
// Fleet is the name of fleet.
// +required
Fleet string `json:"fleet"`
// ClusterSelector specifies the selectors to select the clusters within the fleet.
// If unspecified, all clusters in the fleet will be selected.
// Fleet represents the name of a fleet which determines a set of clusters.
// If Fleet is set, it will be used to determine the target clusters.
// If users wish to specify clusters directly, they can use the Clusters field.
// +optional
ClusterSelector *ClusterSelector `json:"clusterSelector,omitempty"`
Fleet string `json:"fleet,omitempty"`

// Clusters allows users to directly specify a set of destination clusters.
// +optional
Clusters []*corev1.ObjectReference `json:"clusters,omitempty"`
}

type ClusterSelector struct {
Expand All @@ -36,9 +41,9 @@ type ClusterSelector struct {
MatchLabels map[string]string `json:"matchLabels,omitempty"`
}

// Note: partly copied from https://github.com/"github.com/vmware-tanzu/velero/pkg/apis/backup_types.go
// Note: partly copied from https://github.com/vmware-tanzu/velero/blob/v1.11.1/pkg/apis/velero/v1/backup_types.go
type ResourceFilter struct {
// IncludedNamespaces is a slice of namespace names to include objects from.
// IncludedNamespaces is a list of namespace names to include objects from.
// If empty, all namespaces are included.
// +optional
// +nullable
Expand All @@ -49,38 +54,53 @@ type ResourceFilter struct {
// +nullable
ExcludedNamespaces []string `json:"excludedNamespaces,omitempty"`

// IncludedResources is a slice of resource names to include in the backup.
// If empty, all resources are included.
// IncludedResources is a slice of API resource names to include in the backup.
// For example, we can populate this string array with ["deployments", "configmaps","clusterroles","storageclasses"], then we will select all resources of type deployments and configmaps.
// If empty, all API 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", "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", "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 +117,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"`
}
39 changes: 26 additions & 13 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,13 +36,14 @@ 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.
// The user needs to ensure that SourceCluster points to only ONE cluster.
// Because the current migration only supports migrating from one SourceCluster to one or more TargetCluster.
// +required
SourceCluster *Destination `json:"sourceCluster"`

// TargetCluster represents the target clusters for migration.
// +required
TargetCluster *Destination `json:"targetCluster"`

// Policy defines the rules for the migration.
Expand All @@ -53,13 +53,22 @@ type MigrateSpec struct {

type MigratePolicy struct {
// ResourceFilter specifies the resources to be included in the migration.
// If not set, all resources in will be migrated.
// If not set, all resources in source cluster will be migrated.
// +optional
ResourceFilter *ResourceFilter `json:"resourceFilter,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 @@ -73,17 +82,12 @@ type MigratePolicy struct {
// If nil, no objects are included. Optional.
// +optional
// +nullable
MigrateStatus *RestoreStatusSpec `json:"migrateStatus,omitempty"`
MigrateStatus *PreserveStatus `json:"migrateStatus,omitempty"`

// PreserveNodePorts specifies whether to migrate old nodePorts from source cluster to target cluster.
// +optional
// +nullable
PreserveNodePorts *bool `json:"preserveNodePorts,omitempty"`

// ItemOperationTimeout specifies the time used to wait for RestoreItemAction operations.
// The default value is 1 hour.
// +optional
ItemOperationTimeout metav1.Duration `json:"itemOperationTimeout,omitempty"`
}

type MigrateStatus struct {
Expand All @@ -96,8 +100,17 @@ 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.
// +kubebuilder:object:root=true
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type MigrateList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []Migrate `json:"items"`
}
Loading

0 comments on commit 041835d

Please sign in to comment.