Aller au contenu

Backup Spec (cue)#

Generating cue spec#

The following definition has been generated from velero code with cue:

cd $(mktemp -d)
go mod init cue-velero
go get github.com/vmware-tanzu/velero@v1.9.2
go get k8s.io/api/...
cue get go github.com/vmware-tanzu/velero/pkg/apis/velero/v1

# This will generate a directory ./cue.mod/gen/github.com/vmware-tanzu/velero/pkg/apis/velero/v1/
# containing cue definitions infered from go code.
# Get the content of ./cue.mod/gen/github.com/vmware-tanzu/velero/pkg/apis/velero/v1/backup_go_gen.cue

Spec#

// Code generated by cue get go. DO NOT EDIT.

//cue:generate cue get go github.com/vmware-tanzu/velero/pkg/apis/velero/v1

package v1

import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

#Metadata: {
    labels?: {[string]: string} @go(Labels,map[string]string)
}

// BackupSpec defines the specification for a Velero backup.
#BackupSpec: {
    // +optional
    metadata?: #Metadata @go(Metadata)

    // IncludedNamespaces is a slice of namespace names to include objects
    // from. If empty, all namespaces are included.
    // +optional
    // +nullable
    includedNamespaces?: [...string] @go(IncludedNamespaces,[]string)

    // ExcludedNamespaces contains a list of namespaces that are not
    // included in the backup.
    // +optional
    // +nullable
    excludedNamespaces?: [...string] @go(ExcludedNamespaces,[]string)

    // IncludedResources is a slice of resource names to include
    // in the backup. If empty, all resources are included.
    // +optional
    // +nullable
    includedResources?: [...string] @go(IncludedResources,[]string)

    // ExcludedResources is a slice of resource names that are not
    // included in the backup.
    // +optional
    // +nullable
    excludedResources?: [...string] @go(ExcludedResources,[]string)

    // LabelSelector is a metav1.LabelSelector to filter with
    // when adding individual objects to the backup. If empty
    // or nil, all objects are included. Optional.
    // +optional
    // +nullable
    labelSelector?: null | metav1.#LabelSelector @go(LabelSelector,*metav1.LabelSelector)

    // 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. LabelSelector as well as
    // OrLabelSelectors cannot co-exist in backup request, only one of them
    // can be used.
    // +optional
    // +nullable
    orLabelSelectors?: [...null | metav1.#LabelSelector] @go(OrLabelSelectors,[]*metav1.LabelSelector)

    // SnapshotVolumes specifies whether to take cloud snapshots
    // of any PV's referenced in the set of objects included
    // in the Backup.
    // +optional
    // +nullable
    snapshotVolumes?: null | bool @go(SnapshotVolumes,*bool)

    // TTL is a time.Duration-parseable string describing how long
    // the Backup should be retained for.
    // +optional
    ttl?: metav1.#Duration @go(TTL)

    // IncludeClusterResources specifies whether cluster-scoped resources
    // should be included for consideration in the backup.
    // +optional
    // +nullable
    includeClusterResources?: null | bool @go(IncludeClusterResources,*bool)

    // Hooks represent custom behaviors that should be executed at different phases of the backup.
    // +optional
    hooks?: #BackupHooks @go(Hooks)

    // StorageLocation is a string containing the name of a BackupStorageLocation where the backup should be stored.
    // +optional
    storageLocation?: string @go(StorageLocation)

    // VolumeSnapshotLocations is a list containing names of VolumeSnapshotLocations associated with this backup.
    // +optional
    volumeSnapshotLocations?: [...string] @go(VolumeSnapshotLocations,[]string)

    // DefaultVolumesToRestic specifies whether restic should be used to take a
    // backup of all pod volumes by default.
    // +optional
    // + nullable
    defaultVolumesToRestic?: null | bool @go(DefaultVolumesToRestic,*bool)

    // OrderedResources specifies the backup order of resources of specific Kind.
    // The map key is the Kind name and value is a list of resource names separated by commas.
    // Each resource name has format "namespace/resourcename".  For cluster resources, simply use "resourcename".
    // +optional
    // +nullable
    orderedResources?: {[string]: string} @go(OrderedResources,map[string]string)

    // CSISnapshotTimeout specifies the time used to wait for CSI VolumeSnapshot status turns to
    // ReadyToUse during creation, before returning error as timeout.
    // The default value is 10 minute.
    // +optional
    csiSnapshotTimeout?: metav1.#Duration @go(CSISnapshotTimeout)
}

// BackupHooks contains custom behaviors that should be executed at different phases of the backup.
#BackupHooks: {
    // Resources are hooks that should be executed when backing up individual instances of a resource.
    // +optional
    // +nullable
    resources?: [...#BackupResourceHookSpec] @go(Resources,[]BackupResourceHookSpec)
}

// BackupResourceHookSpec defines one or more BackupResourceHooks that should be executed based on
// the rules defined for namespaces, resources, and label selector.
#BackupResourceHookSpec: {
    // Name is the name of this hook.
    name: string @go(Name)

    // IncludedNamespaces specifies the namespaces to which this hook spec applies. If empty, it applies
    // to all namespaces.
    // +optional
    // +nullable
    includedNamespaces?: [...string] @go(IncludedNamespaces,[]string)

    // ExcludedNamespaces specifies the namespaces to which this hook spec does not apply.
    // +optional
    // +nullable
    excludedNamespaces?: [...string] @go(ExcludedNamespaces,[]string)

    // IncludedResources specifies the resources to which this hook spec applies. If empty, it applies
    // to all resources.
    // +optional
    // +nullable
    includedResources?: [...string] @go(IncludedResources,[]string)

    // ExcludedResources specifies the resources to which this hook spec does not apply.
    // +optional
    // +nullable
    excludedResources?: [...string] @go(ExcludedResources,[]string)

    // LabelSelector, if specified, filters the resources to which this hook spec applies.
    // +optional
    // +nullable
    labelSelector?: null | metav1.#LabelSelector @go(LabelSelector,*metav1.LabelSelector)

    // PreHooks is a list of BackupResourceHooks to execute prior to storing the item in the backup.
    // These are executed before any "additional items" from item actions are processed.
    // +optional
    pre?: [...#BackupResourceHook] @go(PreHooks,[]BackupResourceHook)

    // PostHooks is a list of BackupResourceHooks to execute after storing the item in the backup.
    // These are executed after all "additional items" from item actions are processed.
    // +optional
    post?: [...#BackupResourceHook] @go(PostHooks,[]BackupResourceHook)
}

// BackupResourceHook defines a hook for a resource.
#BackupResourceHook: {
    // Exec defines an exec hook.
    exec?: null | #ExecHook @go(Exec,*ExecHook)
}

// ExecHook is a hook that uses the pod exec API to execute a command in a container in a pod.
#ExecHook: {
    // Container is the container in the pod where the command should be executed. If not specified,
    // the pod's first container is used.
    // +optional
    container?: string @go(Container)

    // Command is the command and arguments to execute.
    // +kubebuilder:validation:MinItems=1
    command: [...string] @go(Command,[]string)

    // OnError specifies how Velero should behave if it encounters an error executing this hook.
    // +optional
    onError?: #HookErrorMode @go(OnError)

    // Timeout defines the maximum amount of time Velero should wait for the hook to complete before
    // considering the execution a failure.
    // +optional
    timeout?: metav1.#Duration @go(Timeout)
}

// HookErrorMode defines how Velero should treat an error from a hook.
// +kubebuilder:validation:Enum=Continue;Fail
#HookErrorMode: string // #enumHookErrorMode

#enumHookErrorMode:
    #HookErrorModeContinue |
    #HookErrorModeFail

// HookErrorModeContinue means that an error from a hook is acceptable, and the backup can
// proceed.
#HookErrorModeContinue: #HookErrorMode & "Continue"

// HookErrorModeFail means that an error from a hook is problematic, and the backup should be in
// error.
#HookErrorModeFail: #HookErrorMode & "Fail"

// BackupPhase is a string representation of the lifecycle phase
// of a Velero backup.
// +kubebuilder:validation:Enum=New;FailedValidation;InProgress;Completed;PartiallyFailed;Failed;Deleting
#BackupPhase: string // #enumBackupPhase

#enumBackupPhase:
    #BackupPhaseNew |
    #BackupPhaseFailedValidation |
    #BackupPhaseInProgress |
    #BackupPhaseUploading |
    #BackupPhaseUploadingPartialFailure |
    #BackupPhaseCompleted |
    #BackupPhasePartiallyFailed |
    #BackupPhaseFailed |
    #BackupPhaseDeleting

// BackupPhaseNew means the backup has been created but not
// yet processed by the BackupController.
#BackupPhaseNew: #BackupPhase & "New"

// BackupPhaseFailedValidation means the backup has failed
// the controller's validations and therefore will not run.
#BackupPhaseFailedValidation: #BackupPhase & "FailedValidation"

// BackupPhaseInProgress means the backup is currently executing.
#BackupPhaseInProgress: #BackupPhase & "InProgress"

// BackupPhaseUploading means the backups of Kubernetes resources
// and creation of snapshots was successful and snapshot data
// is currently uploading.  The backup is not usable yet.
#BackupPhaseUploading: #BackupPhase & "Uploading"

// BackupPhaseUploadingPartialFailure means the backup of Kubernetes
// resources and creation of snapshots partially failed (final phase
// will be PartiallyFailed) and snapshot data is currently uploading.
// The backup is not usable yet.
#BackupPhaseUploadingPartialFailure: #BackupPhase & "UploadingPartialFailure"

// BackupPhaseCompleted means the backup has run successfully without
// errors.
#BackupPhaseCompleted: #BackupPhase & "Completed"

// BackupPhasePartiallyFailed means the backup has run to completion
// but encountered 1+ errors backing up individual items.
#BackupPhasePartiallyFailed: #BackupPhase & "PartiallyFailed"

// BackupPhaseFailed means the backup ran but encountered an error that
// prevented it from completing successfully.
#BackupPhaseFailed: #BackupPhase & "Failed"

// BackupPhaseDeleting means the backup and all its associated data are being deleted.
#BackupPhaseDeleting: #BackupPhase & "Deleting"

// BackupStatus captures the current status of a Velero backup.
#BackupStatus: {
    // Version is the backup format major version.
    // Deprecated: Please see FormatVersion
    // +optional
    version?: int @go(Version)

    // FormatVersion is the backup format version, including major, minor, and patch version.
    // +optional
    formatVersion?: string @go(FormatVersion)

    // Expiration is when this Backup is eligible for garbage-collection.
    // +optional
    // +nullable
    expiration?: null | metav1.#Time @go(Expiration,*metav1.Time)

    // Phase is the current state of the Backup.
    // +optional
    phase?: #BackupPhase @go(Phase)

    // ValidationErrors is a slice of all validation errors (if
    // applicable).
    // +optional
    // +nullable
    validationErrors?: [...string] @go(ValidationErrors,[]string)

    // StartTimestamp records the time a backup was started.
    // Separate from CreationTimestamp, since that value changes
    // on restores.
    // The server's time is used for StartTimestamps
    // +optional
    // +nullable
    startTimestamp?: null | metav1.#Time @go(StartTimestamp,*metav1.Time)

    // CompletionTimestamp records the time a backup was completed.
    // Completion time is recorded even on failed backups.
    // Completion time is recorded before uploading the backup object.
    // The server's time is used for CompletionTimestamps
    // +optional
    // +nullable
    completionTimestamp?: null | metav1.#Time @go(CompletionTimestamp,*metav1.Time)

    // VolumeSnapshotsAttempted is the total number of attempted
    // volume snapshots for this backup.
    // +optional
    volumeSnapshotsAttempted?: int @go(VolumeSnapshotsAttempted)

    // VolumeSnapshotsCompleted is the total number of successfully
    // completed volume snapshots for this backup.
    // +optional
    volumeSnapshotsCompleted?: int @go(VolumeSnapshotsCompleted)

    // FailureReason is an error that caused the entire backup to fail.
    // +optional
    failureReason?: string @go(FailureReason)

    // Warnings is a count of all warning messages that were generated during
    // execution of the backup. The actual warnings are in the backup's log
    // file in object storage.
    // +optional
    warnings?: int @go(Warnings)

    // Errors is a count of all error messages that were generated during
    // execution of the backup.  The actual errors are in the backup's log
    // file in object storage.
    // +optional
    errors?: int @go(Errors)

    // Progress contains information about the backup's execution progress. Note
    // that this information is best-effort only -- if Velero fails to update it
    // during a backup for any reason, it may be inaccurate/stale.
    // +optional
    // +nullable
    progress?: null | #BackupProgress @go(Progress,*BackupProgress)

    // CSIVolumeSnapshotsAttempted is the total number of attempted
    // CSI VolumeSnapshots for this backup.
    // +optional
    csiVolumeSnapshotsAttempted?: int @go(CSIVolumeSnapshotsAttempted)

    // CSIVolumeSnapshotsCompleted is the total number of successfully
    // completed CSI VolumeSnapshots for this backup.
    // +optional
    csiVolumeSnapshotsCompleted?: int @go(CSIVolumeSnapshotsCompleted)
}

// BackupProgress stores information about the progress of a Backup's execution.
#BackupProgress: {
    // TotalItems is the total number of items to be backed up. This number may change
    // throughout the execution of the backup due to plugins that return additional related
    // items to back up, the velero.io/exclude-from-backup label, and various other
    // filters that happen as items are processed.
    // +optional
    totalItems?: int @go(TotalItems)

    // ItemsBackedUp is the number of items that have actually been written to the
    // backup tarball so far.
    // +optional
    itemsBackedUp?: int @go(ItemsBackedUp)
}

// Backup is a Velero resource that represents the capture of Kubernetes
// cluster state at a point in time (API objects and associated volume state).
#Backup: {
    metav1.#TypeMeta

    // +optional
    metadata?: metav1.#ObjectMeta @go(ObjectMeta)

    // +optional
    spec?: #BackupSpec @go(Spec)

    // +optional
    status?: #BackupStatus @go(Status)
}

// BackupList is a list of Backups.
#BackupList: {
    metav1.#TypeMeta

    // +optional
    metadata?: metav1.#ListMeta @go(ListMeta)
    items: [...#Backup] @go(Items,[]Backup)
}