Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HealthCheck: support examing resources of different groups together #263

Merged
merged 1 commit into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 13 additions & 23 deletions api/v1alpha1/healthcheck_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,32 +30,22 @@ const (

// HealthCheckSpec defines the desired state of HealthCheck
type HealthCheckSpec struct {
// Group of the resource deployed in the Cluster.
Group string `json:"group"`

// Version of the resource deployed in the Cluster.
Version string `json:"version"`

// Kind of the resource deployed in the Cluster.
// ResourceSelectors identifies what resources to select to evaluate health
ResourceSelectors []ResourceSelector `json:"resourceSelectors"`

// The EvaluateHealth field specifies a Lua function responsible for evaluating the
// health of the resources selected by resourceSelectors.
// This function can assess the health of each resource independently or consider inter-resource relationships.
// The function must be named *evaluate* and can access all objects identified by resourceSelectors using
// the *resources* variable. It should return an array of structured instances, each containing the following fields:
// - resource: The resource being evaluated
// - healthStatus: The health status of the resource, which can be one of "Healthy", "Progressing", "Degraded", or "Suspended"
// - message: An optional message providing additional information about the health status
// +kubebuilder:validation:MinLength=1
Kind string `json:"kind"`

// LabelFilters allows to filter resources based on current labels.
// +optional
LabelFilters []LabelFilter `json:"labelFilters,omitempty"`

// Namespace of the resource deployed in the Cluster.
// Empty for resources scoped at cluster level.
// +optional
Namespace string `json:"namespace,omitempty"`

// Script is a text containing a lua script.
// Must return a struct with field "status"
// set to one of the possible value of HealthStatus.
Script string `json:"script,omitempty"`
EvaluateHealth string `json:"evaluateHealth"`

// CollectResources indicates whether matching resources need
// to be collected and added to EventReport.
// to be collected and added to HealthReport.
// +kubebuilder:default:=false
// +optional
CollectResources bool `json:"collectResources,omitempty"`
Expand Down
10 changes: 6 additions & 4 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

99 changes: 63 additions & 36 deletions config/crd/bases/lib.projectsveltos.io_healthchecks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,54 +37,81 @@ spec:
collectResources:
default: false
description: CollectResources indicates whether matching resources
need to be collected and added to EventReport.
need to be collected and added to HealthReport.
type: boolean
group:
description: Group of the resource deployed in the Cluster.
type: string
kind:
description: Kind of the resource deployed in the Cluster.
evaluateHealth:
description: 'The EvaluateHealth field specifies a Lua function responsible
for evaluating the health of the resources selected by resourceSelectors.
This function can assess the health of each resource independently
or consider inter-resource relationships. The function must be named
*evaluate* and can access all objects identified by resourceSelectors
using the *resources* variable. It should return an array of structured
instances, each containing the following fields: - resource: The
resource being evaluated - healthStatus: The health status of the
resource, which can be one of "Healthy", "Progressing", "Degraded",
or "Suspended" - message: An optional message providing additional
information about the health status'
minLength: 1
type: string
labelFilters:
description: LabelFilters allows to filter resources based on current
labels.
resourceSelectors:
description: ResourceSelectors identifies what resources to select
to evaluate health
items:
description: ResourceSelector defines what resources are a match
properties:
key:
description: Key is the label key
evaluate:
description: Evaluate contains a function "evaluate" in lua
language. The function will be passed one of the object selected
based on above criteria. Must return struct with field "matching"
representing whether object is a match and an optional "message"
field.
type: string
group:
description: Group of the resource deployed in the Cluster.
type: string
kind:
description: Kind of the resource deployed in the Cluster.
minLength: 1
type: string
operation:
description: Operation is the comparison operation
enum:
- Equal
- Different
labelFilters:
description: LabelFilters allows to filter resources based on
current labels.
items:
properties:
key:
description: Key is the label key
type: string
operation:
description: Operation is the comparison operation
enum:
- Equal
- Different
type: string
value:
description: Value is the label value
type: string
required:
- key
- operation
- value
type: object
type: array
namespace:
description: Namespace of the resource deployed in the Cluster.
Empty for resources scoped at cluster level.
type: string
value:
description: Value is the label value
version:
description: Version of the resource deployed in the Cluster.
type: string
required:
- key
- operation
- value
- group
- kind
- version
type: object
type: array
namespace:
description: Namespace of the resource deployed in the Cluster. Empty
for resources scoped at cluster level.
type: string
script:
description: Script is a text containing a lua script. Must return
a struct with field "status" set to one of the possible value of
HealthStatus.
type: string
version:
description: Version of the resource deployed in the Cluster.
type: string
required:
- group
- kind
- version
- evaluateHealth
- resourceSelectors
type: object
type: object
served: true
Expand Down
99 changes: 63 additions & 36 deletions lib/crd/healthchecks.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,54 +56,81 @@ spec:
collectResources:
default: false
description: CollectResources indicates whether matching resources
need to be collected and added to EventReport.
need to be collected and added to HealthReport.
type: boolean
group:
description: Group of the resource deployed in the Cluster.
type: string
kind:
description: Kind of the resource deployed in the Cluster.
evaluateHealth:
description: 'The EvaluateHealth field specifies a Lua function responsible
for evaluating the health of the resources selected by resourceSelectors.
This function can assess the health of each resource independently
or consider inter-resource relationships. The function must be named
*evaluate* and can access all objects identified by resourceSelectors
using the *resources* variable. It should return an array of structured
instances, each containing the following fields: - resource: The
resource being evaluated - healthStatus: The health status of the
resource, which can be one of "Healthy", "Progressing", "Degraded",
or "Suspended" - message: An optional message providing additional
information about the health status'
minLength: 1
type: string
labelFilters:
description: LabelFilters allows to filter resources based on current
labels.
resourceSelectors:
description: ResourceSelectors identifies what resources to select
to evaluate health
items:
description: ResourceSelector defines what resources are a match
properties:
key:
description: Key is the label key
evaluate:
description: Evaluate contains a function "evaluate" in lua
language. The function will be passed one of the object selected
based on above criteria. Must return struct with field "matching"
representing whether object is a match and an optional "message"
field.
type: string
group:
description: Group of the resource deployed in the Cluster.
type: string
kind:
description: Kind of the resource deployed in the Cluster.
minLength: 1
type: string
operation:
description: Operation is the comparison operation
enum:
- Equal
- Different
labelFilters:
description: LabelFilters allows to filter resources based on
current labels.
items:
properties:
key:
description: Key is the label key
type: string
operation:
description: Operation is the comparison operation
enum:
- Equal
- Different
type: string
value:
description: Value is the label value
type: string
required:
- key
- operation
- value
type: object
type: array
namespace:
description: Namespace of the resource deployed in the Cluster.
Empty for resources scoped at cluster level.
type: string
value:
description: Value is the label value
version:
description: Version of the resource deployed in the Cluster.
type: string
required:
- key
- operation
- value
- group
- kind
- version
type: object
type: array
namespace:
description: Namespace of the resource deployed in the Cluster. Empty
for resources scoped at cluster level.
type: string
script:
description: Script is a text containing a lua script. Must return
a struct with field "status" set to one of the possible value of
HealthStatus.
type: string
version:
description: Version of the resource deployed in the Cluster.
type: string
required:
- group
- kind
- version
- evaluateHealth
- resourceSelectors
type: object
type: object
served: true
Expand Down