Skip to content

Commit

Permalink
HealthCheck: support examing resources of different groups together
Browse files Browse the repository at this point in the history
Resources of different GVKs can be selected ResourceSelectors
All selected resources will be passed to the method defined in EvaluateHealth
  • Loading branch information
mgianluc committed Jan 16, 2024
1 parent 5397f87 commit 9baac9d
Show file tree
Hide file tree
Showing 4 changed files with 145 additions and 99 deletions.
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

Check failure on line 66 in lib/crd/healthchecks.go

View workflow job for this annotation

GitHub Actions / build-static-test

missing ',' in argument list

Check failure on line 66 in lib/crd/healthchecks.go

View workflow job for this annotation

GitHub Actions / build-static-test

missing ',' in argument list

Check failure on line 66 in lib/crd/healthchecks.go

View workflow job for this annotation

GitHub Actions / build-static-test

missing ',' in argument list

Check failure on line 66 in lib/crd/healthchecks.go

View workflow job for this annotation

GitHub Actions / build-static-test

missing ',' in argument list

Check failure on line 66 in lib/crd/healthchecks.go

View workflow job for this annotation

GitHub Actions / build-static-test

missing ',' in argument list

Check failure on line 66 in lib/crd/healthchecks.go

View workflow job for this annotation

GitHub Actions / build-static-test

missing ',' before newline in argument list

Check failure on line 66 in lib/crd/healthchecks.go

View workflow job for this annotation

GitHub Actions / build-static-test

missing ',' in argument list

Check failure on line 66 in lib/crd/healthchecks.go

View workflow job for this annotation

GitHub Actions / build-static-test

missing ',' in argument list

Check failure on line 66 in lib/crd/healthchecks.go

View workflow job for this annotation

GitHub Actions / build-ut

missing ',' in argument list

Check failure on line 66 in lib/crd/healthchecks.go

View workflow job for this annotation

GitHub Actions / build-ut

missing ',' in argument list

Check failure on line 66 in lib/crd/healthchecks.go

View workflow job for this annotation

GitHub Actions / build-ut

missing ',' in argument list

Check failure on line 66 in lib/crd/healthchecks.go

View workflow job for this annotation

GitHub Actions / build-ut

missing ',' in argument list

Check failure on line 66 in lib/crd/healthchecks.go

View workflow job for this annotation

GitHub Actions / build-ut

missing ',' in argument list

Check failure on line 66 in lib/crd/healthchecks.go

View workflow job for this annotation

GitHub Actions / build-ut

missing ',' before newline in argument list

Check failure on line 66 in lib/crd/healthchecks.go

View workflow job for this annotation

GitHub Actions / build-ut

missing ',' in argument list

Check failure on line 66 in lib/crd/healthchecks.go

View workflow job for this annotation

GitHub Actions / build-ut

missing ',' in argument list
using the `resources`` variable. It should return an array of structured

Check failure on line 67 in lib/crd/healthchecks.go

View workflow job for this annotation

GitHub Actions / build-static-test

missing ',' in argument list

Check failure on line 67 in lib/crd/healthchecks.go

View workflow job for this annotation

GitHub Actions / build-static-test

missing ',' in argument list

Check failure on line 67 in lib/crd/healthchecks.go

View workflow job for this annotation

GitHub Actions / build-ut

missing ',' in argument list

Check failure on line 67 in lib/crd/healthchecks.go

View workflow job for this annotation

GitHub Actions / build-ut

missing ',' in argument list
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

0 comments on commit 9baac9d

Please sign in to comment.