mirror of
https://github.com/vmware-tanzu/velero.git
synced 2026-08-15 11:46:06 +00:00
Add types to implement restore hooks (#2761)
* Add types to implement restore hooks Signed-off-by: Ashish Amarnath <ashisham@vmware.com>
This commit is contained in:
@@ -0,0 +1 @@
|
||||
Add types to implement restore hooks
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
@@ -16,7 +16,10 @@ limitations under the License.
|
||||
|
||||
package v1
|
||||
|
||||
import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
import (
|
||||
v1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
)
|
||||
|
||||
// RestoreSpec defines the specification for a Velero restore.
|
||||
type RestoreSpec struct {
|
||||
@@ -80,6 +83,100 @@ type RestoreSpec struct {
|
||||
// +optional
|
||||
// +nullable
|
||||
IncludeClusterResources *bool `json:"includeClusterResources,omitempty"`
|
||||
|
||||
// Hooks represent custom behaviors that should be executed during or post restore.
|
||||
// +optional
|
||||
Hooks RestoreHooks `json:"hooks,omitempty"`
|
||||
}
|
||||
|
||||
// RestoreHooks contains custom behaviors that should be executed during or post restore.
|
||||
type RestoreHooks struct {
|
||||
Resources []RestoreResourceHookSpec `json:"resources,omitempty"`
|
||||
}
|
||||
|
||||
// RestoreResourceHookSpec defines one or more RestoreResrouceHooks that should be executed based on
|
||||
// the rules defined for namespaces, resources, and label selector.
|
||||
type RestoreResourceHookSpec struct {
|
||||
// Name is the name of this hook.
|
||||
Name string `json:"name"`
|
||||
|
||||
// IncludedNamespaces specifies the namespaces to which this hook spec applies. If empty, it applies
|
||||
// to all namespaces.
|
||||
// +optional
|
||||
// +nullable
|
||||
IncludedNamespaces []string `json:"includedNamespaces,omitempty"`
|
||||
|
||||
// ExcludedNamespaces specifies the namespaces to which this hook spec does not apply.
|
||||
// +optional
|
||||
// +nullable
|
||||
ExcludedNamespaces []string `json:"excludedNamespaces,omitempty"`
|
||||
|
||||
// IncludedResources specifies the resources to which this hook spec applies. If empty, it applies
|
||||
// to all resources.
|
||||
// +optional
|
||||
// +nullable
|
||||
IncludedResources []string `json:"includedResources,omitempty"`
|
||||
|
||||
// ExcludedResources specifies the resources to which this hook spec does not apply.
|
||||
// +optional
|
||||
// +nullable
|
||||
ExcludedResources []string `json:"excludedResources,omitempty"`
|
||||
|
||||
// LabelSelector, if specified, filters the resources to which this hook spec applies.
|
||||
// +optional
|
||||
// +nullable
|
||||
LabelSelector *metav1.LabelSelector `json:"labelSelector,omitempty"`
|
||||
|
||||
// PostHooks is a list of RestoreResourceHooks to execute during and after restoring a resource.
|
||||
// +optional
|
||||
PostHooks []RestoreResourceHook `json:"postHooks,omitempty"`
|
||||
}
|
||||
|
||||
// RestoreResourceHook defines a restore hook for a resource.
|
||||
type RestoreResourceHook struct {
|
||||
// Exec defines an exec restore hook.
|
||||
Exec *ExecRestoreHook `json:"exec"`
|
||||
|
||||
// Init defines an init restore hook.
|
||||
Init *InitRestoreHook `json:"init"`
|
||||
}
|
||||
|
||||
// ExecRestoreHook is a hook that uses pod exec API to execute a command inside a container in a pod
|
||||
type ExecRestoreHook struct {
|
||||
// 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 `json:"container,omitempty"`
|
||||
|
||||
// Command is the command and arguments to execute from within a container after a pod has been restored.
|
||||
// +kubebuilder:validation:MinItems=1
|
||||
Command []string `json:"command"`
|
||||
|
||||
// OnError specifies how Velero should behave if it encounters an error executing this hook.
|
||||
// +optional
|
||||
OnError HookErrorMode `json:"onError,omitempty"`
|
||||
|
||||
// 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 `json:"execTimeout,omitempty"`
|
||||
|
||||
// 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 `json:"waitTimeout,omitempty"`
|
||||
}
|
||||
|
||||
// InitRestoreHook is a hook that adds an init container to a PodSpec to run commands before the
|
||||
// workload pod is able to start.
|
||||
type InitRestoreHook struct {
|
||||
// InitContainers is list of init containers to be added to a pod during its restore.
|
||||
// +optional
|
||||
InitContainers []v1.Container `json:"initContainers"`
|
||||
|
||||
// Timeout defines the maximum amount of time Velero should wait for the initContainers to complete.
|
||||
// +optional
|
||||
Timeout metav1.Duration `json:"timeout,omitempty"`
|
||||
}
|
||||
|
||||
// RestorePhase is a string representation of the lifecycle phase
|
||||
|
||||
@@ -21,6 +21,7 @@ limitations under the License.
|
||||
package v1
|
||||
|
||||
import (
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
runtime "k8s.io/apimachinery/pkg/runtime"
|
||||
)
|
||||
@@ -655,6 +656,53 @@ func (in *ExecHook) DeepCopy() *ExecHook {
|
||||
return out
|
||||
}
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *ExecRestoreHook) DeepCopyInto(out *ExecRestoreHook) {
|
||||
*out = *in
|
||||
if in.Command != nil {
|
||||
in, out := &in.Command, &out.Command
|
||||
*out = make([]string, len(*in))
|
||||
copy(*out, *in)
|
||||
}
|
||||
out.ExecTimeout = in.ExecTimeout
|
||||
out.WaitTimeout = in.WaitTimeout
|
||||
return
|
||||
}
|
||||
|
||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ExecRestoreHook.
|
||||
func (in *ExecRestoreHook) DeepCopy() *ExecRestoreHook {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := new(ExecRestoreHook)
|
||||
in.DeepCopyInto(out)
|
||||
return out
|
||||
}
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *InitRestoreHook) DeepCopyInto(out *InitRestoreHook) {
|
||||
*out = *in
|
||||
if in.InitContainers != nil {
|
||||
in, out := &in.InitContainers, &out.InitContainers
|
||||
*out = make([]corev1.Container, len(*in))
|
||||
for i := range *in {
|
||||
(*in)[i].DeepCopyInto(&(*out)[i])
|
||||
}
|
||||
}
|
||||
out.Timeout = in.Timeout
|
||||
return
|
||||
}
|
||||
|
||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new InitRestoreHook.
|
||||
func (in *InitRestoreHook) DeepCopy() *InitRestoreHook {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := new(InitRestoreHook)
|
||||
in.DeepCopyInto(out)
|
||||
return out
|
||||
}
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *ObjectStorageLocation) DeepCopyInto(out *ObjectStorageLocation) {
|
||||
*out = *in
|
||||
@@ -1047,6 +1095,29 @@ func (in *Restore) DeepCopyObject() runtime.Object {
|
||||
return nil
|
||||
}
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *RestoreHooks) DeepCopyInto(out *RestoreHooks) {
|
||||
*out = *in
|
||||
if in.Resources != nil {
|
||||
in, out := &in.Resources, &out.Resources
|
||||
*out = make([]RestoreResourceHookSpec, len(*in))
|
||||
for i := range *in {
|
||||
(*in)[i].DeepCopyInto(&(*out)[i])
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RestoreHooks.
|
||||
func (in *RestoreHooks) DeepCopy() *RestoreHooks {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := new(RestoreHooks)
|
||||
in.DeepCopyInto(out)
|
||||
return out
|
||||
}
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *RestoreList) DeepCopyInto(out *RestoreList) {
|
||||
*out = *in
|
||||
@@ -1080,6 +1151,80 @@ func (in *RestoreList) DeepCopyObject() runtime.Object {
|
||||
return nil
|
||||
}
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *RestoreResourceHook) DeepCopyInto(out *RestoreResourceHook) {
|
||||
*out = *in
|
||||
if in.Exec != nil {
|
||||
in, out := &in.Exec, &out.Exec
|
||||
*out = new(ExecRestoreHook)
|
||||
(*in).DeepCopyInto(*out)
|
||||
}
|
||||
if in.Init != nil {
|
||||
in, out := &in.Init, &out.Init
|
||||
*out = new(InitRestoreHook)
|
||||
(*in).DeepCopyInto(*out)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RestoreResourceHook.
|
||||
func (in *RestoreResourceHook) DeepCopy() *RestoreResourceHook {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := new(RestoreResourceHook)
|
||||
in.DeepCopyInto(out)
|
||||
return out
|
||||
}
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *RestoreResourceHookSpec) DeepCopyInto(out *RestoreResourceHookSpec) {
|
||||
*out = *in
|
||||
if in.IncludedNamespaces != nil {
|
||||
in, out := &in.IncludedNamespaces, &out.IncludedNamespaces
|
||||
*out = make([]string, len(*in))
|
||||
copy(*out, *in)
|
||||
}
|
||||
if in.ExcludedNamespaces != nil {
|
||||
in, out := &in.ExcludedNamespaces, &out.ExcludedNamespaces
|
||||
*out = make([]string, len(*in))
|
||||
copy(*out, *in)
|
||||
}
|
||||
if in.IncludedResources != nil {
|
||||
in, out := &in.IncludedResources, &out.IncludedResources
|
||||
*out = make([]string, len(*in))
|
||||
copy(*out, *in)
|
||||
}
|
||||
if in.ExcludedResources != nil {
|
||||
in, out := &in.ExcludedResources, &out.ExcludedResources
|
||||
*out = make([]string, len(*in))
|
||||
copy(*out, *in)
|
||||
}
|
||||
if in.LabelSelector != nil {
|
||||
in, out := &in.LabelSelector, &out.LabelSelector
|
||||
*out = new(metav1.LabelSelector)
|
||||
(*in).DeepCopyInto(*out)
|
||||
}
|
||||
if in.PostHooks != nil {
|
||||
in, out := &in.PostHooks, &out.PostHooks
|
||||
*out = make([]RestoreResourceHook, len(*in))
|
||||
for i := range *in {
|
||||
(*in)[i].DeepCopyInto(&(*out)[i])
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RestoreResourceHookSpec.
|
||||
func (in *RestoreResourceHookSpec) DeepCopy() *RestoreResourceHookSpec {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := new(RestoreResourceHookSpec)
|
||||
in.DeepCopyInto(out)
|
||||
return out
|
||||
}
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *RestoreSpec) DeepCopyInto(out *RestoreSpec) {
|
||||
*out = *in
|
||||
@@ -1125,6 +1270,7 @@ func (in *RestoreSpec) DeepCopyInto(out *RestoreSpec) {
|
||||
*out = new(bool)
|
||||
**out = **in
|
||||
}
|
||||
in.Hooks.DeepCopyInto(&out.Hooks)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user