utils

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: May 18, 2026 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EventReasonDetectedUnhealthy  = "DetectedUnhealthy"
	EventReasonRemediationCreated = "RemediationCreated"
	EventReasonRemediationSkipped = "RemediationSkipped"
	EventReasonRemediationRemoved = "RemediationRemoved"
	EventReasonInvalidNodeLabel   = "InvalidNodeLabel"
	EventReasonDisabled           = "Disabled"
	EventReasonEnabled            = "Enabled"
)
View Source
const (
	MachineNodeNameIndex = "machineNodeNameIndex"
)

Variables

View Source
var (
	// DefaultRemediationDuration is used for node lease calculations for remediations without configured timeout
	DefaultRemediationDuration = 10 * time.Minute
)
View Source
var MachineAnnotationNotFoundError = errors.New("machine annotation not found")

MachineAnnotationNotFoundError indicates that in GetMachineNsName the machine annotation wasn't found on the given node

Functions

func GetAllRemediationTemplates

func GetAllRemediationTemplates(healthCheck client.Object) []*v1.ObjectReference

GetAllRemediationTemplates returns a slice of all ObjectReferences used as RemedediationTemplate in the given NodeHealthCheck

func GetDeploymentNamespace

func GetDeploymentNamespace() (string, error)

GetDeploymentNamespace returns the Namespace this operator is deployed on.

func GetLogWithNHC

func GetLogWithNHC(log logr.Logger, nhc *v1alpha1.NodeHealthCheck) logr.Logger

GetLogWithNHC return a logger with NHC namespace and name

func GetMachineNamespaceName

func GetMachineNamespaceName(node *v1.Node) (namespace, name string, err error)

GetMachineNamespaceName returns machine namespace and name of the given Node. Returns MachineAnnotationNotFoundError in case the needed annotation doesn't exist on the given node

func GetNodeNameFromCR

func GetNodeNameFromCR(cr unstructured.Unstructured) string

GetNodeNameFromCR returns the node name from the given CR. If the CR has a nodeName annotation, it will return its value, otherwise it will return the CR name.

func GetOwningDeployment

func GetOwningDeployment(ctx context.Context, cl client.Client, namespace, podName string) (*appsv1.Deployment, error)

GetOwningDeployment walks the ownership chain from the current pod to find its controlling Deployment. It follows the chain: Pod → ReplicaSet → Deployment. Returns a specific error for the step in the ownership chain that cannot be resolved.

func GetPodName

func GetPodName() (string, error)

GetPodName returns the name of the pod this operator is running in.

func GetRemediationDuration

func GetRemediationDuration(nhc *v1alpha1.NodeHealthCheck, remediationCR *unstructured.Unstructured) (currentRemediationDuration, previousRemediationsDuration time.Duration)

GetRemediationDuration returns the expected remediation duration for the given CR, and all previous used templates

func GetTemplateNameFromCR

func GetTemplateNameFromCR(cr unstructured.Unstructured) string

GetTemplateNameFromCR returns the template name from the given CR, if set.

func IsConditionFalseWithReason

func IsConditionFalseWithReason(conditions []metav1.Condition, conditionType string, reason string) bool

IsConditionFalseWithReason return true when the conditions contain a condition of given type and reason with status false, this isn't the logical opposite of IsConditionTrueWithReason because the condition is expected to be set with a false status.

func IsConditionSet

func IsConditionSet(conditions []metav1.Condition, conditionType string) bool

IsConditionSet return true when the conditions contain a condition of given type

func IsConditionTrue

func IsConditionTrue(conditions []metav1.Condition, conditionType string) bool

IsConditionTrue returns true when the conditions contain a condition of given type with status true, regardless of reason

func IsConditionTrueWithReason

func IsConditionTrueWithReason(conditions []metav1.Condition, conditionType string, reason string) bool

IsConditionTrueWithReason return true when the conditions contain a condition of given type and reason with status true

func IsHealthyMHC

func IsHealthyMHC(unhealthyConditions []v1beta1.UnhealthyCondition, nodeConditions []corev1.NodeCondition, now time.Time) (bool, *time.Duration)

func IsHealthyNHC

func IsHealthyNHC(unhealthyConditions []remediationv1alpha1.UnhealthyCondition, nodeConditions []corev1.NodeCondition, now time.Time) (bool, *time.Duration)

func MHCByFeatureGateEventMapperFunc

func MHCByFeatureGateEventMapperFunc(c client.Client, logger logr.Logger, featureGates featuregates.Accessor) handler.MapFunc

MHCByFeatureGateEventMapperFunc return the FeatureGateEvent-to-NHC mapper function

func MHCByMachineMapperFunc

func MHCByMachineMapperFunc(c client.Client, logger logr.Logger, featureGates featuregates.Accessor) handler.MapFunc

MHCByMachineMapperFunc return the Machine-to-MHC mapper function

func MHCByNodeMapperFunc

func MHCByNodeMapperFunc(c client.Client, logger logr.Logger, featureGates featuregates.Accessor) handler.MapFunc

MHCByNodeMapperFunc return the Node-to-MHC mapper function

func MHCByRemediationTemplateCRMapperFunc

func MHCByRemediationTemplateCRMapperFunc(c client.Client, logger logr.Logger) handler.MapFunc

MHCByRemediationTemplateCRMapperFunc return the RemediationTemplateCR-to-MHC mapper function

func MinRequeueDuration

func MinRequeueDuration(old, new *time.Duration) *time.Duration

MinRequeueDuration returns the minimal valid requeue duration

func NHCByMHCEventMapperFunc

func NHCByMHCEventMapperFunc(c client.Client, logger logr.Logger) handler.MapFunc

NHCByMHCEventMapperFunc return the MHC-event-to-NHC mapper function

func NHCByNodeMapperFunc

func NHCByNodeMapperFunc(c client.Client, logger logr.Logger) handler.MapFunc

NHCByNodeMapperFunc return the Node-to-NHC mapper function

func NHCByRemediationTemplateCRMapperFunc

func NHCByRemediationTemplateCRMapperFunc(c client.Client, logger logr.Logger) handler.MapFunc

NHCByRemediationTemplateCRMapperFunc return the RemediationTemplateCR-to-NHC mapper function

func RemediationCRMapperFunc

func RemediationCRMapperFunc(logger logr.Logger, watchType WatchType) handler.MapFunc

RemediationCRMapperFunc return the RemediationCR-to-NHC/MHC mapper function

func SetMachineCondition

func SetMachineCondition(mhc *v1beta1.MachineHealthCheck, condition *v1beta1.Condition)

Types

type WatchType

type WatchType string

WatchType is used to differentiate watch CR logic between NHC and MHC.

const (
	NHC WatchType = "NHC"
	MHC WatchType = "MHC"
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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