Skip to content

Add pvc and cert-expiry Kubernetes probes - #36

Merged
joy-software merged 1 commit into
mainfrom
feature/pvc-cert-probes
Jun 7, 2026
Merged

Add pvc and cert-expiry Kubernetes probes#36
joy-software merged 1 commit into
mainfrom
feature/pvc-cert-probes

Conversation

@joy-software

Copy link
Copy Markdown
Contributor

What

Two new probes on the existing probe seam, plus an optional certs extra.

pvc

  • Params: name: str.
  • kubectl get pvc <name> -o json; healthy iff status.phase == "Bound".
  • Detail names the phase and the bound capacity when present.
  • object_ref -> ["pvc", name].
  • Bind health only. True PVC usage (how full the mounted filesystem is) needs kubelet volume stats that kubectl does not expose, so usage thresholds stay future work.

cert-expiry

  • Params: secret: str, days: int = 14, key: str = "tls.crt".
  • kubectl get secret <secret> -o json, base64-decode data[key], parse the X.509 notAfter with cryptography.
  • Unhealthy when the cert expires within days or is already expired; detail reports days remaining.
  • cryptography is imported lazily inside check() so the dep stays optional. Without it, the probe returns a pointer to the certs extra instead of crashing.
  • object_ref -> ["secret", secret].

Wiring

  • Both registered in PROBES and __all__.
  • Bad params raise at construction so the policy validator rejects them at load.
  • Added optional extra certs = ["cryptography>=42"] and refreshed uv.lock.

Tests

  • tests/test_pvc_probe.py: Bound/Pending/missing-phase/kubectl-failure, object_ref, build-from-spec.
  • tests/test_cert_expiry_probe.py: mints short- and long-lived self-signed certs in-process, asserts unhealthy/healthy, covers expired, missing key, custom key, unparseable cert, negative-days rejection, object_ref, build-from-spec. Guarded with pytest.importorskip("cryptography").

All gates pass locally: ruff check, ruff format --check, mypy, pytest (244 passed).

Two new probes under the existing probe seam:

- pvc: healthy iff the PersistentVolumeClaim is Bound. Detail names the
  phase and the bound capacity when present. This is bind health only;
  true PVC usage needs kubelet volume stats that kubectl does not expose,
  so usage thresholds stay future work.
- cert-expiry: reads a TLS Secret, base64-decodes data[key] (default
  tls.crt), parses the X.509 notAfter with cryptography, and reports
  unhealthy when the cert expires within `days` (default 14) or is already
  expired. cryptography is imported lazily so the dep stays optional;
  without it the probe points at the new `certs` extra.

Both register in PROBES and __all__, expose object_ref for `get -o yaml`,
and validate bad params at construction so the policy loader rejects them.
Adds the optional `certs = ["cryptography>=42"]` extra and refreshes the
lock. Tests mint short- and long-lived self-signed certs in-process and
drive the probes through a scripted provider.
@joy-software
joy-software merged commit fcd1786 into main Jun 7, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant