$ show k3s-io/helm-controller
This is a Kubernetes controller that manages Helm chart deployments via Custom Resource Definitions (HelmChart and HelmChartConfig). It watches these CRDs and creates Kubernetes Jobs to run Helm install, upgrade, or delete operations, with a two-phase apply pattern that suspends jobs before updating them to avoid race conditions. The controller is built on the rancher/wrangler framework and handles complex features like failure policies, server-side apply, driver selection (secret vs configmap), values from secrets, HelmChartConfig merging, and bootstrapping. It is the core Helm management component of k3s and is designed to be deployed as a Deployment with a ServiceAccount and ClusterRole.
The LLM identified 4 files worth highlighting for reuse:
Provides functions to parse and validate JSON strings representing Kubernetes ResourceRequirements and Tolerations. It converts external types to internal Kubernetes types and runs the same validation logic used by the kubelet, ensuring that user-provided resource specs are valid. This pattern is reusable in any project that needs to accept and validate Kubernetes resource configurations from CLI flags or config files.
Implements a generic scoped on-remove handler that only adds finalizers and sync logic for objects that pass a provided scope function. This prevents the controller from adding finalizers to all resources across the cluster and is a clean pattern for managing lifecycle of only relevant resources. Could be extracted and used by other controllers needing similar scoped finalizer management.
Provides safe conversion functions between apiextv1.JSON and YAML strings, handling nil, empty, and null inputs gracefully. Useful for any project dealing with Kubernetes apiextensions JSON values that need to be displayed or parsed as YAML. Demonstrates clean handling of edge cases without panics.
A logr.LogSink implementation that wraps logrus, providing structured logging with key-value pairs. Includes a custom hook to format request bodies for trace-level debugging. This adapter pattern is reusable across Go projects that need to integrate logr-based code with existing logrus infrastructure.