ADR0018 - Custom Health Checks
Problem Statement
Service readiness is directly taken from FluxCDs Helm Controller readiness condition.
Currently we use default recommended parameters for the release manifests. While the Helm controller has readiness defaults for built in Kubernetes resources it does not known them for custom resources. Currently a service shows ready even if for example the credentials could not be synced. The controller does have an extension mechanism using CEL.
This ADR evaluates how we can add custom readiness checks to the framework.
High level goals
-
A service can implement custom readiness checks
-
Readiness checks for framework resources can be easily added without copying them
Proposals
Add custom checks to Helm metadata, statically add framework checks
We configure the HelmRelease.spec.healthCheckExprs semi-dynamically.
Chart provided health checks come from the charts annotations.
The annotations contain json serialized healthCheckExprs that are applied to the HelmRelease.
Metadata can’t be merged from a library chart.
Framework resource checks are implemented statically by the the HelmRelease management controller and not managed by the library chart.
This adds another code path that is harder to manage in the revision model. It is however the most straightforward implementation.
The user experience is suboptimal. They need to serialize JSON into a string. Invalid JSON is not immediately clear.
apiVersion: v2
name: testchart
description: A Helm chart for Kubernetes
annotations:
healthchecks.helmetica.io/test: | (1)
[{
"apiVersion": "bitnami.com/v1alpha1",
"kind": "SealedSecret",
"failed": "status.conditions.filter(e, e.type == 'Synced').all(e, e.status == 'False')",
"current": "status.conditions.filter(e, e.type == 'Synced').all(e, e.status == 'True')"
}]
| 1 | Prefixed matched (healthchecks.helmetica.io/), multiple annotations can be added with independent health checks. |
Render and parse Helm output to configure release
We configure the HelmRelease.spec.healthCheckExprs dynamically.
The HelmRelease is parametrized from Helm rendering output.
Before applying the HelmRelease the chart is pre-rendered and rendered manifests are parsed.
The manifests are later dropped by adding a postrender filter.
The manifests are not real CRDs, they don’t exist in the cluster.
apiVersion: internal.chrysopoeia.helmetica.io/v1alpha1
kind: HealthCheck
spec:
healthChecks:
- apiVersion: bitnami.com/v1alpha1
kind: SealedSecret
failed: status.conditions.filter(e, e.type == 'Synced').all(e, e.status == 'False')
current: status.conditions.filter(e, e.type == 'Synced').all(e, e.status == 'True')
If rendering the helm chart fails we could add a never true health check and let the Helm controller render the manifest to get nice FluxCD error messages.
Custom readiness controller
We configure the HelmRelease.spec.healthCheckExprs statically.
All logic is configured in a custom CRD with a custom controller. The controller has one overarching readiness status that is queried by the Flux health check.
This would add one more controller and possibly lead to race conditions between Flux and the custom controller. It makes it harder to debug as there are more sources of state.
It does make it easy to include default health checks to the library chart: It’s just another manifest rendered by the chart.
apiVersion: ...helmetica.io/v1alpha1
kind: HealthCheck
spec:
healthChecks:
- apiVersion: bitnami.com/v1alpha1
kind: SealedSecret
failed: status.conditions.filter(e, e.type == 'Synced').all(e, e.status == 'False')
current: status.conditions.filter(e, e.type == 'Synced').all(e, e.status == 'True')
status:
overall: Ready
healthChecks:
- apiVersion: bitnami.com/v1alpha1
kind: SealedSecret
status: Ready
Decision
We implement "Render and parse Helm output to configure release."
This the best possible UX.
Consequences
Configuration shows up in diffs and is managed by the same revision logic as everything else. There is additional external configuration. Updated rules get pulled in on library chart updates and can thus be kept in sync with other changes to the chart manifests.
The controller applying HelmReleases gets more complicated and possibly uses more memory. Chart rendering errors most likely trigger earlier and need to be communicated to the claim correctly.