workloadhealth

package
v1.16.109 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2023 License: MPL-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StatusKey              = "consul.io/workload-health"
	StatusConditionHealthy = "healthy"

	NodeAndWorkloadHealthyMessage   = "All workload and associated node health checks are passing"
	WorkloadHealthyMessage          = "All workload health checks are passing"
	NodeAndWorkloadUnhealthyMessage = "One or more workload and node health checks are not passing"
	WorkloadUnhealthyMessage        = "One or more workload health checks are not passing"
)

Variables

View Source
var (
	ConditionWorkloadPassing = &pbresource.Condition{
		Type:    StatusConditionHealthy,
		State:   pbresource.Condition_STATE_TRUE,
		Reason:  pbcatalog.Health_HEALTH_PASSING.String(),
		Message: WorkloadHealthyMessage,
	}

	ConditionWorkloadWarning = &pbresource.Condition{
		Type:    StatusConditionHealthy,
		State:   pbresource.Condition_STATE_FALSE,
		Reason:  pbcatalog.Health_HEALTH_WARNING.String(),
		Message: WorkloadUnhealthyMessage,
	}

	ConditionWorkloadCritical = &pbresource.Condition{
		Type:    StatusConditionHealthy,
		State:   pbresource.Condition_STATE_FALSE,
		Reason:  pbcatalog.Health_HEALTH_CRITICAL.String(),
		Message: WorkloadUnhealthyMessage,
	}

	ConditionWorkloadMaintenance = &pbresource.Condition{
		Type:    StatusConditionHealthy,
		State:   pbresource.Condition_STATE_FALSE,
		Reason:  pbcatalog.Health_HEALTH_MAINTENANCE.String(),
		Message: WorkloadUnhealthyMessage,
	}

	ConditionNodeAndWorkloadPassing = &pbresource.Condition{
		Type:    StatusConditionHealthy,
		State:   pbresource.Condition_STATE_TRUE,
		Reason:  pbcatalog.Health_HEALTH_PASSING.String(),
		Message: NodeAndWorkloadHealthyMessage,
	}

	ConditionNodeAndWorkloadWarning = &pbresource.Condition{
		Type:    StatusConditionHealthy,
		State:   pbresource.Condition_STATE_FALSE,
		Reason:  pbcatalog.Health_HEALTH_WARNING.String(),
		Message: NodeAndWorkloadUnhealthyMessage,
	}

	ConditionNodeAndWorkloadCritical = &pbresource.Condition{
		Type:    StatusConditionHealthy,
		State:   pbresource.Condition_STATE_FALSE,
		Reason:  pbcatalog.Health_HEALTH_CRITICAL.String(),
		Message: NodeAndWorkloadUnhealthyMessage,
	}

	ConditionNodeAndWorkloadMaintenance = &pbresource.Condition{
		Type:    StatusConditionHealthy,
		State:   pbresource.Condition_STATE_FALSE,
		Reason:  pbcatalog.Health_HEALTH_MAINTENANCE.String(),
		Message: NodeAndWorkloadUnhealthyMessage,
	}

	ConditionNodeWarning = &pbresource.Condition{
		Type:    StatusConditionHealthy,
		State:   pbresource.Condition_STATE_FALSE,
		Reason:  pbcatalog.Health_HEALTH_WARNING.String(),
		Message: nodehealth.NodeUnhealthyMessage,
	}

	ConditionNodeCritical = &pbresource.Condition{
		Type:    StatusConditionHealthy,
		State:   pbresource.Condition_STATE_FALSE,
		Reason:  pbcatalog.Health_HEALTH_CRITICAL.String(),
		Message: nodehealth.NodeUnhealthyMessage,
	}

	ConditionNodeMaintenance = &pbresource.Condition{
		Type:    StatusConditionHealthy,
		State:   pbresource.Condition_STATE_FALSE,
		Reason:  pbcatalog.Health_HEALTH_MAINTENANCE.String(),
		Message: nodehealth.NodeUnhealthyMessage,
	}

	// WorkloadConditions is a map of the workloadhealth to the status condition
	// used to represent that health.
	WorkloadConditions = map[pbcatalog.Health]*pbresource.Condition{
		pbcatalog.Health_HEALTH_PASSING:     ConditionWorkloadPassing,
		pbcatalog.Health_HEALTH_WARNING:     ConditionWorkloadWarning,
		pbcatalog.Health_HEALTH_CRITICAL:    ConditionWorkloadCritical,
		pbcatalog.Health_HEALTH_MAINTENANCE: ConditionWorkloadMaintenance,
	}

	// NodeAndWorkloadConditions is a map whose ultimate values are the status conditions
	// used to represent the combined health of a workload and its associated node.
	// The outer map's keys are the workloads health and the inner maps keys are the nodes
	// health
	NodeAndWorkloadConditions = map[pbcatalog.Health]map[pbcatalog.Health]*pbresource.Condition{
		pbcatalog.Health_HEALTH_PASSING: {
			pbcatalog.Health_HEALTH_PASSING:     ConditionNodeAndWorkloadPassing,
			pbcatalog.Health_HEALTH_WARNING:     ConditionNodeWarning,
			pbcatalog.Health_HEALTH_CRITICAL:    ConditionNodeCritical,
			pbcatalog.Health_HEALTH_MAINTENANCE: ConditionNodeMaintenance,
		},
		pbcatalog.Health_HEALTH_WARNING: {
			pbcatalog.Health_HEALTH_PASSING:     ConditionWorkloadWarning,
			pbcatalog.Health_HEALTH_WARNING:     ConditionNodeAndWorkloadWarning,
			pbcatalog.Health_HEALTH_CRITICAL:    ConditionNodeAndWorkloadCritical,
			pbcatalog.Health_HEALTH_MAINTENANCE: ConditionNodeAndWorkloadMaintenance,
		},
		pbcatalog.Health_HEALTH_CRITICAL: {
			pbcatalog.Health_HEALTH_PASSING:     ConditionWorkloadCritical,
			pbcatalog.Health_HEALTH_WARNING:     ConditionNodeAndWorkloadCritical,
			pbcatalog.Health_HEALTH_CRITICAL:    ConditionNodeAndWorkloadCritical,
			pbcatalog.Health_HEALTH_MAINTENANCE: ConditionNodeAndWorkloadMaintenance,
		},
		pbcatalog.Health_HEALTH_MAINTENANCE: {
			pbcatalog.Health_HEALTH_PASSING:     ConditionWorkloadMaintenance,
			pbcatalog.Health_HEALTH_WARNING:     ConditionNodeAndWorkloadMaintenance,
			pbcatalog.Health_HEALTH_CRITICAL:    ConditionNodeAndWorkloadMaintenance,
			pbcatalog.Health_HEALTH_MAINTENANCE: ConditionNodeAndWorkloadMaintenance,
		},
	}
)

Functions

func WorkloadHealthController

func WorkloadHealthController(nodeMap NodeMapper) controller.Controller

Types

type NodeMapper

type NodeMapper interface {
	// MapNodeToWorkloads will take a Node resource and return controller requests
	// for all Workloads associated with the Node.
	MapNodeToWorkloads(ctx context.Context, rt controller.Runtime, res *pbresource.Resource) ([]controller.Request, error)

	// TrackWorkload instructs the NodeMapper to associate the given workload
	// ID with the given node ID.
	TrackWorkload(workloadID *pbresource.ID, nodeID *pbresource.ID)

	// UntrackWorkload instructs the Nodemapper to forget about any
	// association it was tracking for this workload.
	UntrackWorkload(workloadID *pbresource.ID)

	// NodeIDFromWorkload is used to generate the resource ID for the Node referenced
	// within the NodeName field of the Workload.
	NodeIDFromWorkload(workload *pbresource.Resource, workloadData *pbcatalog.Workload) *pbresource.ID
}

The NodeMapper interface is used to provide an implementation around being able to map a watch event for a Node resource and translate it to reconciliation requests for all Workloads assigned to that node.

Jump to

Keyboard shortcuts

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