How devtron-labs/winter-soldier works
Project type and purpose
• This is a Kubernetes Operator written in Go, called “Winter Soldier.”
• Purpose: define a Custom Resource Definition (CRD) named Hibernator, then run a controller and webhook that periodically either scales workloads to zero (“sleep”) or deletes them based on time-and-field selectors.
File structure
• api/v1alpha1: Go types for the Hibernator CRD, codegen helpers.
• controllers/: reconciliation logic that watches Hibernator resources and enacts actions.
• config/: kustomize overlays for CRD manifests, RBAC, manager Deployment, admission webhook, Prometheus monitor.
• main.go: bootstraps controller-runtime manager, registers controllers and webhooks.
• pkg/: helper utilities for talking to Kubernetes, evaluating selectors (gjson, expr), mocking.
• Dockerfile, Makefile, PROJECT: build, containerize, and package the operator.
• hack/: license boilerplate.
• vendor/: third-party dependencies.
README for additional insights
• Describes two actions (“sleep” vs “delete”), selection mechanisms (label, namespace, kind, arbitrary fields via gjson/expr), time ranges, and custom flags.
• Mentions Prometheus monitoring.
• Manager: sets up caches, webhooks, metrics.
• HibernatorController: implements Reconcile(Hibernator) → calls ResourceAction, History, Helper.
• pkg/KubeUtil & pkg/KubectlUtil: wrap client operations, mocking.
• time_util.go: helper for AddTime, ParseTime, Now.
• api/v1alpha1/time_util.go: CRD-level defaults, conversions.