$ show postfinance/kubenurse
Kubenurse is a Kubernetes DaemonSet that monitors network connectivity within a cluster by performing periodic checks on API server access (direct and DNS), service/ingress reachability, and inter-node communication. It exports detailed Prometheus metrics including request duration histograms, error counters, and a neighbourhood incoming checks gauge. The architecture uses a controller-runtime client for Kubernetes API discovery, implements an efficient O(N) neighbourhood filtering algorithm based on SHA256 hashing to avoid quadratic scaling, and leverages Go's httptrace package for granular connection metrics. The application features graceful shutdown, TLS support, readiness probes that respect node schedulability, and extensive configuration via environment variables or Helm values.
The LLM identified 4 files worth highlighting for reuse:
Provides a consistent utility for generating Prometheus metric names with labels. The GenMetricsName function ensures all metrics follow the kubenurse_metric_name{label="value"} format, preventing naming inconsistencies and making metric management predictable across the codebase.
A generic, thread-safe TTL cache implementation using Go generics. Offers automatic expired entry cleanup on access, mutex protection for concurrent safety, and simple API for insert/active count operations. This pattern is reusable for any caching scenario requiring time-based expiration.
Implements an efficient neighbourhood discovery algorithm that prevents O(N^2) scaling in large clusters. Uses SHA256 hashing of node names to create a deterministic ordering, then selects the N closest neighbours via a max-heap. This ensures each node checks a fixed number of peers regardless of cluster size, with minimal metric churn during node changes.
Expertly instruments HTTP client requests using Go's httptrace package to capture detailed connection metrics. Wraps RoundTripper to record histograms for DNS lookup, connection establishment, TLS handshake, and more. Properly handles error accounting to prevent double-counting and provides deep visibility into network failure points.