Skip to content

Commit

Permalink
Introduce Backup API
Browse files Browse the repository at this point in the history
* draft
  • Loading branch information
zerospiel committed Dec 4, 2024
1 parent 97393a5 commit 91d6cf6
Show file tree
Hide file tree
Showing 3 changed files with 604 additions and 0 deletions.
131 changes: 131 additions & 0 deletions api/v1alpha1/management_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
package v1alpha1

import (
"time"

corev1 "k8s.io/api/core/v1"
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/yaml"
Expand All @@ -35,6 +38,7 @@ const (
type ManagementSpec struct {
// +kubebuilder:validation:MinLength=1
// +kubebuilder:validation:MaxLength=253

// Release references the Release object.
Release string `json:"release"`
// Core holds the core Management components that are mandatory.
Expand All @@ -43,6 +47,8 @@ type ManagementSpec struct {

// Providers is the list of supported CAPI providers.
Providers []Provider `json:"providers,omitempty"`

Backup Backup `json:"backup,omitempty"`
}

// Core represents a structure describing core Management components.
Expand All @@ -53,6 +59,131 @@ type Core struct {
CAPI Component `json:"capi,omitempty"`
}

// Backup enables a feature to backup HMC objects into a cloud.
type Backup struct {
// NOTE: TODO: to avoid any dependencies it is just a ref for now
// actually it must be the velero.ScheduleSpec to avoid creating an actual
// objects and hence introducing other non-HMC-managed backups.
//
// Custom Schedule (and Backup) options to fetch parameters from.
// The HMC-required options might override or precede the options from the field.
CustomBackup *corev1.ObjectReference/* velero.ScheduleSpec */ `json:"customBackup,omitempty"`

// +kubebuilder:default="0 */6 * * *"

// Schedule is a Cron expression defining when to run the Backup.
// A shortcut instead of filling customBackup field up.
// Default value is to backup every 6 hours.
// If both this field and the customBackup are given, the schedule
// from the latter will be utilized.
Schedule string `json:"schedule"`

InstallationParameters *VeleroInstallationParameters `json:"installationParameters,omitempty"` // TODO: remove optional, for now just to pass the tests

// OrLabelSelectors is list of metav1.LabelSelector to filter with
// when adding individual objects to the backup. If multiple provided
// they will be joined by the OR operator.
// A shortcut instead of filling customBackup field up.
// If both this field and the customBackup are given, the orLabelsSelectors
// from the latter will be utilized.
// The HMC default values will be prefixed by default to any value provided.
OrLabelsSelectors []string `json:"orLabelsSelectors,omitempty"`

// +kubebuilder:default=false

// Flag to indicate whether the backup feature is enabled.
// To make any post-install actions, disable the feature at first,
// install Velero, perform actions and only then enable the feature back.
Enabled bool `json:"enabled"`
}

// VeleroInstallationParameters declares a full list of options to configure Velero installation.
// Changing options will lead to perform installation once again with the updated values.
type VeleroInstallationParameters struct {
// Provider name for backup and volume storage.
Provider string `json:"provider"`
// Name of the object storage bucket where backups should be stored.
Bucket string `json:"bucket"`
// Plugin container images to install into the Velero Deployment.
Plugins []string `json:"plugins"`
// Image to use for the Velero and node agent pods.
Image string `json:"image,omitempty"`
// Prefix under which all Velero data should be stored within the bucket
Prefix string `json:"prefix,omitempty"`

// Resource requrements for node-agent pod. A value of "0" is treated as unbounded.
NodeAgentPodResources *corev1.ResourceRequirements `json:"nodeAgentPodResources,omitempty"`
// Resource requrements for Velero pod. A value of "0" is treated as unbounded.
VeleroPodResources *corev1.ResourceRequirements `json:"veleroPodResources,omitempty"`

// Secret with credentials for backup and volume provider.
Secret *corev1.SecretReference `json:"secret"`
// Secret containing a certificate bundle to use when verifying TLS connections to the object store.
CACertFile *corev1.SecretReference `json:"caCertFile,omitempty"`

// Annotations to add to the Velero and node agent pods
PodAnnotations map[string]string `json:"podAnnotations,omitempty"`
// Labels to add to the Velero and node agent pods
PodLabels map[string]string `json:"podLabels,omitempty"`

// Annotations to add to the Velero ServiceAccount. Add iam.gke.io/gcp-service-account=[GSA_NAME]@[PROJECT_NAME].iam.gserviceaccount.com for workload identity.
// Requires ServiceAccountField to be set.
ServiceAccountAnnotations map[string]string `json:"serviceAccountAnnotations,omitempty"`
// ServiceAccountName to be set to the Velero and node agent pods, it should be created before the installation, and the user also needs to create the rolebinding for it.
ServiceAccountName string `json:"serviceAccountName,omitempty"`

// Configuration to use for the backup storage location.
// Alternatively you could configure BackupStorageLocations and VolumeSnapshotLocations after installation.
// To do so, disable backup, configure and perform installation, and then enable backup.
BackupStorageConfig map[string]string `json:"backupStorageConfig,omitempty"`
// Configuration to use for the volume snapshot location.
VolumeSnapshotConfig map[string]string `json:"volumeSnapshotConfig,omitempty"`
// +kubebuilder:default=true

// "Whether or not to create snapshot location automatically. Set to false if you do not plan to create volume snapshots via a storage provider.
UseVolumeSnapshots bool `json:"useVolumeSnapshots,omitempty"`

// Create Velero node-agent daemonset. Velero node-agent hosts Velero modules that need to run in one or more nodes(i.e. Restic, Kopia).
UseNodeAgent bool `json:"useNodeAgent,omitempty"`
// Use privileged mode for the node agent. Required to backup block devices.
PrivilegedNodeAgent bool `json:"privilegedNodeAgent,omitempty"`

// How often 'maintain' is run for backup repositories by default
DefaultRepoMaintenanceFrequency time.Duration `json:"defaultRepoMaintenanceFrequency,omitempty"`
// +kubebuilder:default=600000000000

// How often the garbage collection runs for expired backups.
// Default value is 1h.
GarbageCollectionFrequency time.Duration `json:"garbageCollectionFrequency,omitempty"`
// +kubebuilder:default=2400000000000

// How long to wait for pod volume operations to complete before timing out.
// Default value is 4h.
PodVolumeOperationTimeout time.Duration `json:"podVolumeOperationTimeout,omitempty"`

// List of Velero feature flags to be set on the Velero deployment and the node-agent daemonset, if node-agent is enabled.
Features []string `json:"features,omitempty"`

// Flag to configure Velero server to use pod volume file system backup by default for all volumes on all backups.
DefaultVolumesToFsBackup bool `json:"defaultVolumesToFsBackup,omitempty"`
// +kubebuilder:default="kopia"
// +kubebuilder:validation:Enum={"restic","kopia"}

// The type of uploader to transfer the data of pod volumes.
UploaderType string `json:"uploaderType,omitempty"`

// Flag to configure Velero server to move data by default for all snapshots supporting data movement.
DefaultSnapshotMoveData bool `json:"defaultSnapshotMoveData,omitempty"`

// Skip the first scheduled backup immediately after creating a schedule.
ScheduleSkipImmediately bool `json:"scheduleSkipImmediately,omitempty"`
}

const (
// TODO: NOTE: the backup oneshot anno is just to improve the UX
BackupOneshotAnno = "hmc.mirantis.com/oneshot-backup-name" // create a single Backup object from the management.backup spec named from the given value
)

// Component represents HMC management component
type Component struct {
// Config allows to provide parameters for management component customization.
Expand Down
111 changes: 111 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

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

Loading

0 comments on commit 91d6cf6

Please sign in to comment.