hooks

package
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 14, 2024 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Overview

Package hooks implement hook execution in backup and restore scenario

Package hooks implement pre and post hook execution

Package hooks implement pre and post hook execution

Index

Constants

View Source
const (
	PreHookPhase  = "pre"
	PostHookPhase = "post"
	PodResource   = utils.Pod
)

Variables

View Source
var (
	Pods = schema.GroupResource{Group: "", Resource: "pods"}
)

Functions

func CheckContainerExists

func CheckContainerExists(item map[string]interface{}, container string) error

func CommonExecuteHook

func CommonExecuteHook(
	logger log.FieldLogger,
	client kubernetes.Interface,
	podCommandExecutor PodCommandExecutor,
	hookSpec CommonHookSpec,
	namespace string,
	name string,
	phase string,
) error

ExecuteHook executes the hooks in a container

func FilterHookNamespaces

func FilterHookNamespaces(allNamespaces sets.String, IncludeNamespaces, ExcludeNamespaces []string) sets.String

func GetAllPodsForNamespace

func GetAllPodsForNamespace(logger log.FieldLogger, client kubernetes.Interface, namespace string,
	selector *metav1.LabelSelector,
	includeResources, excludeResources []kahuapi.ResourceSpec) (sets.String, error)

func GetPodsFromDaemonset

func GetPodsFromDaemonset(logger log.FieldLogger, client kubernetes.Interface, namespace string,
	includeResources, excludeResources []kahuapi.ResourceSpec) ([]*v1.PodList, error)

func GetPodsFromDeployment

func GetPodsFromDeployment(logger log.FieldLogger, client kubernetes.Interface, namespace string,
	includeResources, excludeResources []kahuapi.ResourceSpec) ([]*v1.PodList, error)

func GetPodsFromReplicaset

func GetPodsFromReplicaset(logger log.FieldLogger, client kubernetes.Interface, namespace string,
	includeResources, excludeResources []kahuapi.ResourceSpec) ([]*v1.PodList, error)

func GetPodsFromStatefulset

func GetPodsFromStatefulset(logger log.FieldLogger, client kubernetes.Interface, namespace string,
	includeResources, excludeResources []kahuapi.ResourceSpec) ([]*v1.PodList, error)

func GroupRestoreExecHooks

func GroupRestoreExecHooks(

	resourceHooks []kahuapi.RestoreResourceHookSpec,
	client kubernetes.Interface,
	pod *v1.Pod,
	log logrus.FieldLogger,
) (map[string][]PodExecRestoreHook, error)

GroupRestoreExecHooks returns a list of hooks to be executed in a pod grouped by container name. If an exec hook is defined in annotation that is used, else applicable exec hooks from the restore resource are accumulated.

Types

type CommonHookSpec

type CommonHookSpec struct {
	Name              string
	IncludeNamespaces []string
	ExcludeNamespaces []string
	IncludeResources  []kahuapi.ResourceSpec
	ExcludeResources  []kahuapi.ResourceSpec
	LabelSelector     *metav1.LabelSelector
	ContinueFlag      bool
	Hooks             []kahuapi.ResourceHook
}

type DefaultListWatchFactory

type DefaultListWatchFactory struct {
	PodsGetter cache.Getter
}

func (*DefaultListWatchFactory) NewListWatch

func (d *DefaultListWatchFactory) NewListWatch(namespace string, selector fields.Selector) cache.ListerWatcher

type DefaultWaitExecHookHandler

type DefaultWaitExecHookHandler struct {
	ListWatchFactory   ListWatchFactory
	PodCommandExecutor PodCommandExecutor
}

func (*DefaultWaitExecHookHandler) HandleHooks

func (e *DefaultWaitExecHookHandler) HandleHooks(
	ctx context.Context,
	log logrus.FieldLogger,
	pod *v1.Pod,
	byContainer map[string][]PodExecRestoreHook,
) []error

type Hooks

type Hooks interface {
	ExecuteHook(logger log.FieldLogger, hookSpec *kahuapi.BackupSpec, phase string) error
}

func NewHooks

func NewHooks(kubeClient kubernetes.Interface, restConfig *restclient.Config,
	podCommandExecutor PodCommandExecutor) (Hooks, error)

NewHooks creates hooks exection handler

type InitHooks

type InitHooks interface {
	HandleInitHook(hookSpec *kahuapi.HookSpec, phase string) error
}

type InitHooksHandler

type InitHooksHandler struct {
}

func (*InitHooksHandler) HandleInitHook

func (i *InitHooksHandler) HandleInitHook(
	logger log.FieldLogger,
	client kubernetes.Interface,
	groupResource schema.GroupResource,
	obj runtime.Unstructured,
	hookSpec *kahuapi.RestoreHookSpec,
) (*unstructured.Unstructured, error)

HandleInitHook runs the restore hooks for an item. If the item is a pod, then hooks are chosen to be run as follows: If the pod has the appropriate annotations specifying the hook action, then hooks from the annotation are run Otherwise, the supplied ResourceRestoreHooks are applied.

type ListWatchFactory

type ListWatchFactory interface {
	NewListWatch(namespace string, selector fields.Selector) cache.ListerWatcher
}

type PodCommandExecutor

type PodCommandExecutor interface {
	// ExecutePodCommand executes a command in a container in a pod. If the command takes longer than
	// the specified timeout, an error is returned.
	ExecutePodCommand(log logrus.FieldLogger, item map[string]interface{}, namespace, name, hookName string, hook *kahuapi.ExecHook) error
}

PodCommandExecutor is capable of executing a command in a container in a pod.

func NewPodCommandExecutor

func NewPodCommandExecutor(restClientConfig *rest.Config, restClient poster) PodCommandExecutor

NewPodCommandExecutor creates a new PodCommandExecutor.

type PodExecRestoreHook

type PodExecRestoreHook struct {
	HookName   string
	HookSource string
	Hook       kahuapi.RestoreExecHook
	// contains filtered or unexported fields
}

type RListWatchFactory

type RListWatchFactory interface {
	NewListWatch(resource, namespace string, selector fields.Selector) cache.ListerWatcher
}

type ResourceListWatchFactory

type ResourceListWatchFactory struct {
	ResourceGetter cache.Getter
}

func (*ResourceListWatchFactory) NewListWatch

func (r *ResourceListWatchFactory) NewListWatch(resource, namespace string, selector fields.Selector) cache.ListerWatcher

type ResourceWaitHandler

type ResourceWaitHandler struct {
	ResourceListWatchFactory ResourceListWatchFactory
}

func (*ResourceWaitHandler) WaitResource

func (r *ResourceWaitHandler) WaitResource(
	ctx context.Context,
	log logrus.FieldLogger,
	robj *unstructured.Unstructured,
	selectorName string,
	selectorNamespace string,
	resourceType string,
) error

type WaitExecHookHandler

type WaitExecHookHandler interface {
	HandleHooks(
		ctx context.Context,
		log logrus.FieldLogger,
		pod *v1.Pod,
		byContainer map[string][]PodExecRestoreHook,
	) []error
}

type WaitHandler

type WaitHandler interface {
	WaitResource(
		ctx context.Context,
		log logrus.FieldLogger,
		robj *unstructured.Unstructured,
		selectorName string,
		selectorNamespace string,
		resourceType string,
	) error
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL