Aller au contenu

Restore 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/restore_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"
    "k8s.io/api/core/v1"
)

// RestoreSpec defines the specification for a Velero restore.
#RestoreSpec: {
    // BackupName is the unique name of the Velero backup to restore
    // from.
    backupName: string @go(BackupName)

    // ScheduleName is the unique name of the Velero schedule to restore
    // from. If specified, and BackupName is empty, Velero will restore
    // from the most recent successful backup created from this schedule.
    // +optional
    scheduleName?: string @go(ScheduleName)

    // 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 restore.
    // +optional
    // +nullable
    excludedNamespaces?: [...string] @go(ExcludedNamespaces,[]string)

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

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

    // NamespaceMapping is a map of source namespace names
    // to target namespace names to restore into. Any source
    // namespaces not included in the map will be restored into
    // namespaces of the same name.
    // +optional
    namespaceMapping?: {[string]: string} @go(NamespaceMapping,map[string]string)

    // LabelSelector is a metav1.LabelSelector to filter with
    // when restoring individual objects from 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 restoring individual objects from the backup. If multiple provided
    // they will be joined by the OR operator. LabelSelector as well as
    // OrLabelSelectors cannot co-exist in restore request, only one of them
    // can be used
    // +optional
    // +nullable
    orLabelSelectors?: [...null | metav1.#LabelSelector] @go(OrLabelSelectors,[]*metav1.LabelSelector)

    // RestorePVs specifies whether to restore all included
    // PVs from snapshot (via the cloudprovider).
    // +optional
    // +nullable
    restorePVs?: null | bool @go(RestorePVs,*bool)

    // RestoreStatus specifies which resources we should restore the status
    // field. If nil, no objects are included. Optional.
    // +optional
    // +nullable
    restoreStatus?: null | #RestoreStatusSpec @go(RestoreStatus,*RestoreStatusSpec)

    // PreserveNodePorts specifies whether to restore old nodePorts from backup.
    // +optional
    // +nullable
    preserveNodePorts?: null | bool @go(PreserveNodePorts,*bool)

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

    // Hooks represent custom behaviors that should be executed during or post restore.
    // +optional
    hooks?: #RestoreHooks @go(Hooks)

    // ExistingResourcePolicy specifies the restore behaviour for the kubernetes resource to be restored
    // +optional
    // +nullable
    existingResourcePolicy?: #PolicyType @go(ExistingResourcePolicy)
}

// RestoreHooks contains custom behaviors that should be executed during or post restore.
#RestoreHooks: {
    resources?: [...#RestoreResourceHookSpec] @go(Resources,[]RestoreResourceHookSpec)
}

#RestoreStatusSpec: {
    // IncludedResources specifies the resources to which will restore the status.
    // If empty, it applies to all resources.
    // +optional
    // +nullable
    includedResources?: [...string] @go(IncludedResources,[]string)

    // ExcludedResources specifies the resources to which will not restore the status.
    // +optional
    // +nullable
    excludedResources?: [...string] @go(ExcludedResources,[]string)
}

// RestoreResourceHookSpec defines one or more RestoreResrouceHooks that should be executed based on
// the rules defined for namespaces, resources, and label selector.
#RestoreResourceHookSpec: {
    // 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)

    // PostHooks is a list of RestoreResourceHooks to execute during and after restoring a resource.
    // +optional
    postHooks?: [...#RestoreResourceHook] @go(PostHooks,[]RestoreResourceHook)
}

// RestoreResourceHook defines a restore hook for a resource.
#RestoreResourceHook: {
    // Exec defines an exec restore hook.
    exec?: null | #ExecRestoreHook @go(Exec,*ExecRestoreHook)

    // Init defines an init restore hook.
    init?: null | #InitRestoreHook @go(Init,*InitRestoreHook)
}

// ExecRestoreHook is a hook that uses pod exec API to execute a command inside a container in a pod
#ExecRestoreHook: {
    // 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 from within a container after a pod has been restored.
    // +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)

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

    // WaitTimeout defines the maximum amount of time Velero should wait for the container to be Ready
    // before attempting to run the command.
    // +optional
    waitTimeout?: metav1.#Duration @go(WaitTimeout)
}

// InitRestoreHook is a hook that adds an init container to a PodSpec to run commands before the
// workload pod is able to start.
#InitRestoreHook: {
    // InitContainers is list of init containers to be added to a pod during its restore.
    // +optional
    initContainers: [...v1.#Container] @go(InitContainers,[]v1.Container)

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

// RestorePhase is a string representation of the lifecycle phase
// of a Velero restore
// +kubebuilder:validation:Enum=New;FailedValidation;InProgress;Completed;PartiallyFailed;Failed
#RestorePhase: string // #enumRestorePhase

#enumRestorePhase:
    #RestorePhaseNew |
    #RestorePhaseFailedValidation |
    #RestorePhaseInProgress |
    #RestorePhaseCompleted |
    #RestorePhasePartiallyFailed |
    #RestorePhaseFailed

// RestorePhaseNew means the restore has been created but not
// yet processed by the RestoreController
#RestorePhaseNew: #RestorePhase & "New"

// RestorePhaseFailedValidation means the restore has failed
// the controller's validations and therefore will not run.
#RestorePhaseFailedValidation: #RestorePhase & "FailedValidation"

// RestorePhaseInProgress means the restore is currently executing.
#RestorePhaseInProgress: #RestorePhase & "InProgress"

// RestorePhaseCompleted means the restore has run successfully
// without errors.
#RestorePhaseCompleted: #RestorePhase & "Completed"

// RestorePhasePartiallyFailed means the restore has run to completion
// but encountered 1+ errors restoring individual items.
#RestorePhasePartiallyFailed: #RestorePhase & "PartiallyFailed"

// RestorePhaseFailed means the restore was unable to execute.
// The failing error is recorded in status.FailureReason.
#RestorePhaseFailed: #RestorePhase & "Failed"

// PolicyTypeNone means velero will not overwrite the resource
// in cluster with the one in backup whether changed/unchanged.
#PolicyTypeNone: #PolicyType & "none"

// PolicyTypeUpdate means velero will try to attempt a patch on
// the changed resources.
#PolicyTypeUpdate: #PolicyType & "update"

// RestoreStatus captures the current status of a Velero restore
#RestoreStatus: {
    // Phase is the current state of the Restore
    // +optional
    phase?: #RestorePhase @go(Phase)

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

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

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

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

    // StartTimestamp records the time the restore operation was started.
    // The server's time is used for StartTimestamps
    // +optional
    // +nullable
    startTimestamp?: null | metav1.#Time @go(StartTimestamp,*metav1.Time)

    // CompletionTimestamp records the time the restore operation was completed.
    // Completion time is recorded even on failed restore.
    // The server's time is used for StartTimestamps
    // +optional
    // +nullable
    completionTimestamp?: null | metav1.#Time @go(CompletionTimestamp,*metav1.Time)

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

// RestoreProgress stores information about the restore's execution progress
#RestoreProgress: {
    // TotalItems is the total number of items to be restored. This number may change
    // throughout the execution of the restore due to plugins that return additional related
    // items to restore
    // +optional
    totalItems?: int @go(TotalItems)

    // ItemsRestored is the number of items that have actually been restored so far
    // +optional
    itemsRestored?: int @go(ItemsRestored)
}

// Restore is a Velero resource that represents the application of
// resources from a Velero backup to a target Kubernetes cluster.
#Restore: {
    metav1.#TypeMeta

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

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

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

// RestoreList is a list of Restores.
#RestoreList: {
    metav1.#TypeMeta

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

// PolicyType helps specify the ExistingResourcePolicy
#PolicyType: string // #enumPolicyType

#enumPolicyType:
    #PolicyTypeNone |
    #PolicyTypeUpdate