health

package
v1.0.50 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2024 License: Apache-2.0 Imports: 22 Imported by: 6

Documentation

Index

Constants

View Source
const (
	SecretKind                   = "Secret"
	ServiceKind                  = "Service"
	ServiceAccountKind           = "ServiceAccount"
	EndpointsKind                = "Endpoints"
	DeploymentKind               = "Deployment"
	ReplicaSetKind               = "ReplicaSet"
	StatefulSetKind              = "StatefulSet"
	DaemonSetKind                = "DaemonSet"
	IngressKind                  = "Ingress"
	JobKind                      = "Job"
	CronJobKind                  = "CronJob"
	PersistentVolumeClaimKind    = "PersistentVolumeClaim"
	CustomResourceDefinitionKind = "CustomResourceDefinition"
	PodKind                      = "Pod"
	APIServiceKind               = "APIService"
	NamespaceKind                = "Namespace"
	HorizontalPodAutoscalerKind  = "HorizontalPodAutoscaler"
)
View Source
const NoCondition = "none"
View Source
const PodStartingBufferPeriod = time.Minute * 10

duration after the creation of a replica set within which we never deem the it to be unhealthy.

View Source
const (
	SyncStatusCodeSynced = "Synced"
)

Variables

This section is empty.

Functions

func CompareHealth added in v1.0.46

func CompareHealth(a, b Health) int

func GetHealthCheckFunc

func GetHealthCheckFunc(gvk schema.GroupVersionKind) func(obj *unstructured.Unstructured) (*HealthStatus, error)

GetHealthCheckFunc returns built-in health check function or nil if health check is not supported

func GetLastUpdatedTime added in v1.0.50

func GetLastUpdatedTime(obj *unstructured.Unstructured) *time.Time

func GetStartDeadline added in v1.0.40

func GetStartDeadline(containers ...corev1.Container) time.Duration

func HumanCase added in v1.0.43

func HumanCase(s string) string

func IsContainerStarting added in v1.0.40

func IsContainerStarting(creation time.Time, containers ...corev1.Container) bool

func IsPodAvailable

func IsPodAvailable(pod *corev1.Pod, minReadySeconds int32, now metav1.Time) bool

IsPodAvailable returns true if a pod is available; false otherwise. Precondition for an available pod is that it must be ready. On top of that, there are two cases when a pod can be considered available: 1. minReadySeconds == 0, or 2. LastTransitionTime (is set) + minReadySeconds < current time

func IsPodReady

func IsPodReady(pod *corev1.Pod) bool

IsPodReady returns true if a pod is ready; false otherwise.

func IsValidHealth added in v1.0.41

func IsValidHealth(s string) bool

func SetDefaultCertificateExpiryWarningPeriod added in v1.0.34

func SetDefaultCertificateExpiryWarningPeriod(p time.Duration)

Types

type Condition added in v1.0.3

type Condition struct {
	OnCondition `yaml:",inline" json:",inline"`

	OnFalse   *OnCondition `yaml:"onFalse,omitempty"   json:"onFalse,omitempty"`
	OnUnknown *OnCondition `yaml:"onUnknown,omitempty" json:"onUnknown,omitempty"`

	// Custom settings per reason
	Reasons map[string]OnCondition `yaml:"reasons,omitempty" json:"reasons,omitempty"`
}

func (*Condition) Apply added in v1.0.3

func (mapped *Condition) Apply(health *HealthStatus, c *metav1.Condition)

type ContainerRecord added in v1.0.20

type ContainerRecord struct {
	Spec   corev1.Container
	Status corev1.ContainerStatus
}

type Filter added in v1.0.48

type Filter struct {
	OnCondition `yaml:",inline" json:",inline,omitempty"`

	Match map[string]string `yaml:"match,omitempty" json:"match,omitempty"`
}

type GenericStatus added in v1.0.3

type GenericStatus struct {
	Conditions []metav1.Condition
	Fields     map[string]interface{}
}

func GetGenericStatus added in v1.0.3

func GetGenericStatus(obj *unstructured.Unstructured) GenericStatus

func (GenericStatus) FindCondition added in v1.0.3

func (s GenericStatus) FindCondition(name string) metav1.Condition

func (GenericStatus) Int added in v1.0.3

func (s GenericStatus) Int(name string) (int32, bool)

func (GenericStatus) IsEqualInt added in v1.0.3

func (s GenericStatus) IsEqualInt(a, b string) bool

type Health added in v1.0.3

type Health string
const (
	HealthHealthy   Health = "healthy"
	HealthUnhealthy Health = "unhealthy"
	HealthUnknown   Health = "unknown"
	HealthWarning   Health = "warning"
)

func (Health) CompareTo added in v1.0.46

func (h Health) CompareTo(other Health) int

func (Health) IsWorseThan added in v1.0.46

func (h Health) IsWorseThan(other Health) bool

func (Health) Worst added in v1.0.46

func (h Health) Worst(others ...Health) Health

type HealthOverride

type HealthOverride interface {
	GetResourceHealth(obj *unstructured.Unstructured) (*HealthStatus, error)
}

Implements custom health assessment that overrides built-in assessment

var DefaultOverrides HealthOverride

type HealthStatus

type HealthStatus struct {
	Ready  bool   `json:"ready"`
	Health Health `json:"health"`
	// Status holds the status code of the application or resource
	Status HealthStatusCode `json:"status,omitempty"      protobuf:"bytes,1,opt,name=status"`
	// Message is a human-readable informational message describing the health status
	Message string `json:"message,omitempty"     protobuf:"bytes,2,opt,name=message"`
	// LastUpdated is the time this resource as last updated, detected by inspecting all
	// of the relevant status timestamps
	LastUpdated *time.Time `json:"lastUpdated,omitempty"`
	// contains filtered or unexported fields
}

func GetAWSResourceHealth added in v1.0.7

func GetAWSResourceHealth(_, status string) (health HealthStatus)

func GetArgoWorkflowHealth added in v1.0.2

func GetArgoWorkflowHealth(obj *unstructured.Unstructured) (*HealthStatus, error)

func GetCertificateHealth added in v1.0.14

func GetCertificateHealth(obj *unstructured.Unstructured) (*HealthStatus, error)

func GetCertificateRequestHealth added in v1.0.36

func GetCertificateRequestHealth(obj *unstructured.Unstructured) (*HealthStatus, error)

func GetDefaultHealth added in v1.0.3

func GetDefaultHealth(obj *unstructured.Unstructured) (*HealthStatus, error)

func GetECSTaskHealth added in v1.0.40

func GetECSTaskHealth(obj map[string]any) (health HealthStatus)

func GetHealth added in v1.0.3

func GetHealth(obj *unstructured.Unstructured, statusMap StatusMap) (*HealthStatus, error)

func GetHealthByConfigType added in v1.0.24

func GetHealthByConfigType(configType string, obj map[string]any, states ...string) HealthStatus

func GetHealthFromStatus added in v1.0.3

func GetHealthFromStatus(k GenericStatus, statusMap StatusMap) (*HealthStatus, error)

func GetHealthFromStatusName added in v1.0.40

func GetHealthFromStatusName(status string, reasons ...string) (health HealthStatus)

func GetMongoHealth added in v1.0.22

func GetMongoHealth(obj map[string]any) (health HealthStatus)

func GetResourceHealth

func GetResourceHealth(
	obj *unstructured.Unstructured,
	healthOverride HealthOverride,
) (health *HealthStatus, err error)

GetResourceHealth returns the health of a k8s resource

func (*HealthStatus) AppendMessage added in v1.0.3

func (hs *HealthStatus) AppendMessage(msg string, args ...interface{})

func (HealthStatus) Merge added in v1.0.46

func (hs HealthStatus) Merge(others ...*HealthStatus) HealthStatus

func (*HealthStatus) PrependMessage added in v1.0.24

func (hs *HealthStatus) PrependMessage(msg string, args ...interface{})

func (HealthStatus) String added in v1.0.46

func (hs HealthStatus) String() string

type HealthStatusCode

type HealthStatusCode string

Represents resource health status

const (
	// Indicates that health assessment failed and actual health status is unknown
	HealthStatusUnknown HealthStatusCode = "Unknown"
	// Progressing health status means that resource is not healthy but still have a chance to reach healthy state
	HealthStatusProgressing HealthStatusCode = "Progressing"
	// Resource is 100% healthy
	HealthStatusHealthy HealthStatusCode = "Healthy"
	// Assigned to resources that are suspended or paused. The typical example is a
	// [suspended](https://kubernetes.io/docs/tasks/job/automated-tasks-with-cron-jobs/#suspend) CronJob.
	HealthStatusSuspended HealthStatusCode = "Suspended"
	// Degrade status is used if resource status indicates failure or resource could not reach healthy state
	// within some timeout.
	HealthStatusDegraded HealthStatusCode = "Degraded"
	// Indicates that resource is missing in the cluster.
	HealthStatusMissing HealthStatusCode = "Missing"

	HealthStatusEvicted          HealthStatusCode = "Evicted"
	HealthStatusCompleted        HealthStatusCode = "Completed"
	HealthStatusCrashLoopBackoff HealthStatusCode = "CrashLoopBackOff"
	HealthStatusCrashed          HealthStatusCode = "Crashed"
	HealthStatusCreating         HealthStatusCode = "Creating"
	HealthStatusDeleted          HealthStatusCode = "Deleted"
	HealthStatusDeleting         HealthStatusCode = "Deleting"
	HealthStatusTerminating      HealthStatusCode = "Terminating"
	HealthStatusError            HealthStatusCode = "Error"
	HealthStatusRolloutFailed    HealthStatusCode = "Rollout Failed"
	HealthStatusInaccesible      HealthStatusCode = "Inaccessible"
	HealthStatusInfo             HealthStatusCode = "Info"
	HealthStatusPending          HealthStatusCode = "Pending"
	HealthStatusMaintenance      HealthStatusCode = "Maintenance"
	HealthStatusScaling          HealthStatusCode = "Scaling"
	HealthStatusRestart          HealthStatusCode = "Restarting"
	HealthStatusStarting         HealthStatusCode = "Starting"
	HealthStatusFailed           HealthStatusCode = "Failed"
	HealthStatusUnschedulable    HealthStatusCode = "Unschedulable"
	HealthStatusUpgradeFailed    HealthStatusCode = "UpgradeFailed"
	HealthStatusOOMKilled        HealthStatusCode = "OOMKilled"
	HealthStatusScalingUp        HealthStatusCode = "Scaling Up"
	HealthStatusScaledToZero     HealthStatusCode = "Scaled to Zero"
	HealthStatusScalingDown      HealthStatusCode = "Scaling Down"
	HealthStatusRunning          HealthStatusCode = "Running"
	HealthStatusRollingOut       HealthStatusCode = "Rolling Out"
	HealthStatusUnhealthy        HealthStatusCode = "Unhealthy"
	HealthStatusUpdating         HealthStatusCode = "Updating"
	HealthStatusWarning          HealthStatusCode = "Warning"
	HealthStatusStopped          HealthStatusCode = "Stopped"
	HealthStatusStopping         HealthStatusCode = "Stopping"
)

type OnCondition added in v1.0.3

type OnCondition struct {
	// When 2 conditions are true, which one takes precedence from a status/message perspective
	Order int `yaml:"order,omitempty" json:"order,omitempty"`
	// If the condition matches, mark ready
	Ready bool `yaml:"ready"           json:"ready"`

	// If the condition matches, mark not ready
	NotReady bool `json:"notReady" yaml:"notReady,omitempty"`

	// If the condition is true, use the conditions message
	Message bool   `json:"message"          yaml:"message"`
	Health  Health `json:"health,omitempty" yaml:"health,omitempty"`

	Status HealthStatusCode `json:"status,omitempty" yaml:"status,omitempty"`
}

func (*OnCondition) Apply added in v1.0.3

func (mapped *OnCondition) Apply(health *HealthStatus, c *metav1.Condition)

type ReplicaStatus added in v1.0.40

type ReplicaStatus struct {
	Object                                         *unstructured.Unstructured
	Containers                                     []corev1.Container
	Desired, Replicas, Ready, Updated, Unavailable int
}

func (ReplicaStatus) String added in v1.0.40

func (rs ReplicaStatus) String() string

type StatusMap added in v1.0.3

type StatusMap struct {
	Filters             []Filter             `yaml:"filters"             json:"filters"`
	Conditions          map[string]Condition `yaml:"conditions"          json:"conditions"`
	UnhealthyIsNotReady bool                 `yaml:"unhealthyIsNotReady" json:"unhealthyIsNotReady"`
}

Jump to

Keyboard shortcuts

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