hooks

package
v0.1.0-rc1 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2026 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ScaleUp   = "up"
	ScaleDown = "down"
	ScaleSync = "sync"
)

Variables

This section is empty.

Functions

func ConvertClientObjectToMap

func ConvertClientObjectToMap(obj client.Object) (map[string]interface{}, error)

func EvaluateCheckHook

func EvaluateCheckHook(k8sReader client.Reader, hook *kubeobjects.HookSpec, log logr.Logger) (bool, error)

func EvaluateCheckHookExp

func EvaluateCheckHookExp(booleanExpression string, jsonData interface{}) (bool, error)

func EvaluateCheckHookForObjects

func EvaluateCheckHookForObjects(objs []client.Object, hook *kubeobjects.HookSpec, log logr.Logger) (bool, error)

func IsJobOwnedByCronJob

func IsJobOwnedByCronJob(job *batchv1.Job, cronJobName string) bool

IsJobOwnedByCronJob checks if a Job is owned by the specified CronJob.

func IsPodOwnedByDaemonSet

func IsPodOwnedByDaemonSet(pod *corev1.Pod, dsName string) bool

IsPodOwnedByDaemonSet checks if a pod is owned by the specified DaemonSet and is running.

func IsPodOwnedByJob

func IsPodOwnedByJob(pod *corev1.Pod, jobName string) bool

IsPodOwnedByJob checks if a pod is owned by the specified Job and is running.

func IsPodOwnedByRS

func IsPodOwnedByRS(pod *corev1.Pod, rsName string) bool

IsPodOwnedByRS checks if a pod is owned by the specified ReplicaSet and is running.

func IsPodOwnedByStatefulSet

func IsPodOwnedByStatefulSet(pod *corev1.Pod, ssName string) bool

IsPodOwnedByStatefulSet checks if a pod is owned by the specified StatefulSet and is running.

func IsRSOwnedByDeployment

func IsRSOwnedByDeployment(rs *appsv1.ReplicaSet, depName string) bool

IsRSOwnedByDeployment checks if a ReplicaSet is owned by the specified Deployment and has ready replicas.

func IsValidJSONPathExpression

func IsValidJSONPathExpression(expr string) bool

IsValidJSONPathExpression checks if a given expression is a valid JSONPath expression

func QueryJSONPath

func QueryJSONPath(data interface{}, jsonPath string) (reflect.Value, error)

Types

type CheckHook

type CheckHook struct {
	Hook   *kubeobjects.HookSpec
	Reader client.Reader
}

func (CheckHook) Execute

func (c CheckHook) Execute(log logr.Logger) error

type CronJobPodLister

type CronJobPodLister struct {
	ExecHook
}

CronJobPodLister handles pod discovery when SelectResource is "cronjob". It finds CronJobs, then their active child Jobs, then the pods owned by those Jobs.

func (*CronJobPodLister) GetPods

func (l *CronJobPodLister) GetPods(log logr.Logger) ([]ExecPodSpec, error)

GetPods returns pods from CronJobs matching the selector criteria. When SinglePodOnly is true, it returns one active pod per CronJob (from its first active Job). When SinglePodOnly is false, it returns all active pods from all active Jobs of all matched CronJobs.

type DaemonSetPodLister

type DaemonSetPodLister struct {
	ExecHook
}

DaemonSetPodLister handles pod discovery when SelectResource is "daemonset". It finds DaemonSets and returns one running pod from each.

func (*DaemonSetPodLister) GetPods

func (l *DaemonSetPodLister) GetPods(log logr.Logger) ([]ExecPodSpec, error)

GetPods returns pods from DaemonSets matching the selector criteria. When SinglePodOnly is true, it returns one pod per DaemonSet. When SinglePodOnly is false, it returns all pods from all DaemonSets.

type DeploymentPodLister

type DeploymentPodLister struct {
	ExecHook
}

DeploymentPodLister handles pod discovery when SelectResource is "deployment". It finds deployments, then their ReplicaSets, then the pods owned by those ReplicaSets.

func (*DeploymentPodLister) GetPods

func (l *DeploymentPodLister) GetPods(log logr.Logger) ([]ExecPodSpec, error)

GetPods returns pods from deployments matching the selector criteria. When SinglePodOnly is true, it returns one pod per deployment. When SinglePodOnly is false, it returns all pods from all deployments' ReplicaSets.

type DeploymentResource

type DeploymentResource struct {
	*appsv1.Deployment
}

func (DeploymentResource) GetAnnotations

func (d DeploymentResource) GetAnnotations() map[string]string

func (DeploymentResource) GetObjectMeta

func (d DeploymentResource) GetObjectMeta() metav1.Object

func (DeploymentResource) GetReplicasFromSpec

func (d DeploymentResource) GetReplicasFromSpec() *int32

func (DeploymentResource) GetReplicasFromStatus

func (d DeploymentResource) GetReplicasFromStatus() *int32

func (DeploymentResource) SetAnnotations

func (d DeploymentResource) SetAnnotations(annotation map[string]string)

func (DeploymentResource) SetReplicas

func (d DeploymentResource) SetReplicas(replicas *int32)

func (DeploymentResource) Update

type DirectPodLister

type DirectPodLister struct {
	ExecHook
}

DirectPodLister handles pod discovery when SelectResource is "pod" or empty. It directly queries pods using label or name selectors.

func (*DirectPodLister) GetPods

func (l *DirectPodLister) GetPods(log logr.Logger) ([]ExecPodSpec, error)

GetPods returns pods matching the selector criteria. If SinglePodOnly is true, returns only the first matching pod.

type ExecHook

type ExecHook struct {
	Hook           *kubeobjects.HookSpec
	Reader         client.Reader
	Scheme         *runtime.Scheme
	RecipeElements util.RecipeElements
}

func (ExecHook) Execute

func (e ExecHook) Execute(log logr.Logger) error

Execute uses exec hook definition provided in the recipe which will have identifiers to execute a command on the pod(s) matching the criteria.

type ExecPodSpec

type ExecPodSpec struct {
	PodName   string
	Namespace string
	Command   []string
	Container string
}

type HookContext

type HookContext struct {
	Hook           kubeobjects.HookSpec
	Client         client.Client
	Reader         client.Reader
	Scheme         *runtime.Scheme
	RecipeElements util.RecipeElements
}

type HookExecutor

type HookExecutor interface {
	Execute(log logr.Logger) error
}

Hook interface will help in executing the hooks based on the types. Supported types are "check", "scale" and "exec". The implementor needs return the result which would be boolean and error if any.

func GetHookExecutor

func GetHookExecutor(ctx HookContext) (HookExecutor, error)

Based on the hook type, return the appropriate implementation of the hook.

type JobPodLister

type JobPodLister struct {
	ExecHook
}

JobPodLister handles pod discovery when SelectResource is "job". It finds Jobs and returns pods owned by those Jobs that are currently active (Running).

func (*JobPodLister) GetPods

func (l *JobPodLister) GetPods(log logr.Logger) ([]ExecPodSpec, error)

GetPods returns pods from Jobs matching the selector criteria. When SinglePodOnly is true, it returns one active pod per Job. When SinglePodOnly is false, it returns all active pods from all matched Jobs.

type NameSelectorType

type NameSelectorType string
const (
	ValidNameSelector   NameSelectorType = "valid"
	RegexNameSelector   NameSelectorType = "regex"
	InvalidNameSelector NameSelectorType = "invalid"
)

type PodLister

type PodLister interface {
	GetPods(log logr.Logger) ([]ExecPodSpec, error)
}

PodLister interface abstracts pod discovery based on SelectResource type. Each implementation handles a specific resource type (pod, deployment, statefulset, daemonset, job, cronjob).

func NewPodLister

func NewPodLister(e ExecHook) PodLister

NewPodLister returns the appropriate PodLister implementation based on SelectResource.

type Resource

type Resource interface {
	GetReplicasFromSpec() *int32
	SetReplicas(*int32)
	GetReplicasFromStatus() *int32
	GetAnnotations() map[string]string
	SetAnnotations(map[string]string)
	GetObjectMeta() metav1.Object
	Update(ctx context.Context, client client.Client) error
}

type ScaleHook

type ScaleHook struct {
	Hook   *kubeobjects.HookSpec
	Reader client.Reader
	Client client.Client
}

func (ScaleHook) Execute

func (s ScaleHook) Execute(log logr.Logger) error

func (ScaleHook) ScaleDownResource

func (s ScaleHook) ScaleDownResource(resource Resource, log logr.Logger) error

func (ScaleHook) ScaleUpResource

func (s ScaleHook) ScaleUpResource(resource Resource, log logr.Logger) error

func (ScaleHook) SyncResource

func (s ScaleHook) SyncResource(resource Resource, log logr.Logger) error

SyncResource waits until the resource reflects its target replica count

type StatefulSetPodLister

type StatefulSetPodLister struct {
	ExecHook
}

StatefulSetPodLister handles pod discovery when SelectResource is "statefulset". It finds StatefulSets and returns the first pod (index 0) from each.

func (*StatefulSetPodLister) GetPods

func (l *StatefulSetPodLister) GetPods(log logr.Logger) ([]ExecPodSpec, error)

GetPods returns pods from StatefulSets matching the selector criteria. When SinglePodOnly is true, it returns one pod (index 0) per StatefulSet. When SinglePodOnly is false, it returns all pods from all StatefulSets.

type StatefulSetResource

type StatefulSetResource struct {
	*appsv1.StatefulSet
}

func (StatefulSetResource) GetAnnotations

func (s StatefulSetResource) GetAnnotations() map[string]string

func (StatefulSetResource) GetObjectMeta

func (s StatefulSetResource) GetObjectMeta() metav1.Object

func (StatefulSetResource) GetReplicasFromSpec

func (s StatefulSetResource) GetReplicasFromSpec() *int32

func (StatefulSetResource) GetReplicasFromStatus

func (s StatefulSetResource) GetReplicasFromStatus() *int32

func (StatefulSetResource) SetAnnotations

func (s StatefulSetResource) SetAnnotations(annotation map[string]string)

func (StatefulSetResource) SetReplicas

func (s StatefulSetResource) SetReplicas(replicas *int32)

func (StatefulSetResource) Update

Jump to

Keyboard shortcuts

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