{"id":28722303,"url":"https://github.com/theonlyway/recycler","last_synced_at":"2026-06-08T02:04:58.663Z","repository":{"id":299187551,"uuid":"988043947","full_name":"theonlyway/recycler","owner":"theonlyway","description":"A Kubernetes controller that monitors pods CPU utilisation inside a deployment, replicaset, or statefulset and terminates the pod if it exceeds a specified threshold","archived":false,"fork":false,"pushed_at":"2026-06-01T02:38:47.000Z","size":627,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-06-01T03:12:31.786Z","etag":null,"topics":["controller","controller-runtime","crd","go","kubernetes","operator-sdk","reconciler"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/theonlyway.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-05-22T01:15:21.000Z","updated_at":"2026-06-01T02:38:50.000Z","dependencies_parsed_at":null,"dependency_job_id":"07dd37cc-6744-4cb0-a6bd-8805da7369ce","html_url":"https://github.com/theonlyway/recycler","commit_stats":null,"previous_names":["theonlyway/recycler"],"tags_count":90,"template":false,"template_full_name":null,"purl":"pkg:github/theonlyway/recycler","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theonlyway%2Frecycler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theonlyway%2Frecycler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theonlyway%2Frecycler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theonlyway%2Frecycler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/theonlyway","download_url":"https://codeload.github.com/theonlyway/recycler/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theonlyway%2Frecycler/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34044920,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-08T02:00:07.615Z","response_time":111,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["controller","controller-runtime","crd","go","kubernetes","operator-sdk","reconciler"],"created_at":"2025-06-15T08:08:19.888Z","updated_at":"2026-06-08T02:04:58.657Z","avatar_url":"https://github.com/theonlyway.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build and Push Recycler Operator image](https://github.com/theonlyway/recycler/actions/workflows/build.yml/badge.svg)](https://github.com/theonlyway/recycler/actions/workflows/build.yml)\n# recycler\n\nA Kubernetes controller that monitors pods CPU utilisation inside a deployment, replicaset, or statefulset and terminates the pod if it exceeds a specified threshold.\n\n## Description\nIdeally something like this shouldn't even exist if people wrote their software properly. But sometimes bugs exist for longer than they should and you get sick of a HPA scaling needlessly, a pod not failing health checks even though it's at 100% CPU, and one day you are on leave and you've hit the limit you set on the HPA. All this results in some graph being more red then it should be which causes someone to panic. Until someone fixes their bug in the code, this controller was created to monitor pods and terminate them if they exceed a defined threshold.\n\n### Prerequisites\n- go version v1.26.3+\n- docker version 17.03+.\n- kubectl version v1.36.0+.\n- Access to a Kubernetes v1.36.0+ cluster.\n\n## Automatic installation\n### Helm\n**Install the operator from `ghcr`:**\n```sh\nhelm install recycler oci://ghcr.io/theonlyway/charts/recycler --namespace \u003cnamespace\u003e --create-namespace\n```\n\n**Download a copy of the chart files locally from `ghcr`:**\n```sh\nhelm pull oci://ghcr.io/theonlyway/charts/recycler --version \u003cversion\u003e\n```\n\n**Install a specific version of the operator from `ghcr`:**\n```sh\nhelm install recycler oci://ghcr.io/theonlyway/charts/recycler --namespace \u003cnamespace\u003e --create-namespace --version \u003cversion\u003e\n```\n\n**Upgrade the operator from `ghcr`:**\n```sh\nhelm upgrade recycler oci://ghcr.io/theonlyway/charts/recycler --namespace \u003cnamespace\u003e\n```\n\n**Upgrade to a specific version of the operator from `ghcr`:**\n```sh\nhelm upgrade recycler oci://ghcr.io/theonlyway/charts/recycler --namespace \u003cnamespace\u003e --version \u003cversion\u003e\n```\n\n**Uninstall the operator:**\n```sh\nhelm uninstall recycler --namespace \u003cnamespace\u003e\n```\n\n### Kustomize\n**Clone the repository:**\n```sh\ngit clone https://github.com/theonlyway/recycler.git\ncd recycler\n```\n\n**Install the CRDs into the cluster:**\n```sh\nmake install\n```\n\n**Deploy the Manager to the cluster with the image specified by `IMG`:**\n```sh\nmake deploy IMG=ghcr.io/theonlyway/recycler:latest\n```\n\n**Uninstall the CRDs from the cluster:**\n```sh\nmake uninstall\n```\n\n**UnDeploy the controller from the cluster:**\n```sh\nmake undeploy\n```\n\n**Generate a consolidated YAML with CRDs and deployment:**\n```sh\nmake build-installer IMG=ghcr.io/theonlyway/recycler:latest\n```\n\nThe generated YAML file will be located in the `dist/install.yaml` file. You can apply it to your cluster using:\n```sh\nkubectl apply -f dist/install.yaml\n```\n\n## Custom Resource Definition\nThese are the configurable values for the Recycler custom resource. View the openAPI schema [here](config/crd/bases/recycler.theonlywaye.com_recyclers.yaml).\n```yaml\napiVersion: recycler.theonlywaye.com/v1alpha1\nkind: Recycler\nmetadata:\n  name: name-of-recycler # Should be unique but can be anything you want\n  namespace: namespace-of-recycler # Should be the same as the namespace of the deployment, replicaset, or statefulset\nspec:\n  scaleTargetRef:\n    apiVersion: apps/v1\n    kind: Deployment\n    name: name-of-deployment # Should be the same as the name of the deployment, replicaset, or statefulset\n  pollingIntervalSeconds: 30 # This is how long between polling for metrics from the metrics api\n  podMetricsHistory: 5 # This is how many historical metrics to keep which is used to calculate the average CPU averageCpuUtilizationPercent\n  averageCpuUtilizationPercent: 80 # This is the threshold for when to terminate the pod\n  recycleDelaySeconds: 3600 # This is how long to wait before terminating the pod once it's breached the average CPU utilization threshold\n  gracePeriodSeconds: 60 # Configuraable time to wait when terminating the pod before it's forcefully terminated\n  metricStorageLocation: memory # Where to store the metrics data. Either in memory or as an annotation on the pod. There are implications to both\n```\n\n## Prometheus Metrics\n\nThe controller exposes the following custom metrics on the `/metrics` endpoint (HTTPS, port `8443`). If you are using the Prometheus Operator, set the Helm value `prometheus.serviceMonitor.enabled=true` to deploy a `ServiceMonitor` and enable scraping.\n\nThe `ServiceMonitor` must carry the labels that your Prometheus instance selects on. Check your Prometheus CR's `serviceMonitorSelector` to determine the required labels:\n```sh\nkubectl get prometheus -A -o jsonpath='{range .items[*]}{.metadata.namespace}/{.metadata.name}: {.spec.serviceMonitorSelector}{\"\\n\"}{end}'\n```\n\nThen pass the required labels via `prometheus.serviceMonitor.additionalLabels`. For example, if the output is `{\"matchLabels\":{\"release\":\"kube-prometheus-stack\"}}`:\n```sh\nhelm install recycler oci://ghcr.io/theonlyway/charts/recycler \\\n  --namespace recycler-system --create-namespace \\\n  --set prometheus.serviceMonitor.enabled=true \\\n  --set prometheus.serviceMonitor.additionalLabels.release=kube-prometheus-stack\n```\n\n| Metric | Type | Labels | Description |\n|--------|------|--------|-------------|\n| `recycler_pod_recycles_total` | Counter | `recycler_namespace`, `recycler` | Total number of pods deleted by the controller. Increments each time a pod is terminated after breaching the CPU threshold. |\n| `recycler_cpu_threshold_breaches_total` | Counter | `recycler_namespace`, `recycler` | Total number of CPU threshold breach events detected. Increments when a pod first crosses the threshold and the breach annotation is written. |\n| `recycler_cpu_breach_duration_seconds` | Histogram | `recycler_namespace`, `recycler` | Time in seconds between when the breach annotation was written and when the pod was actually deleted (i.e. how long the pod spent above threshold before recycling). Buckets: `30, 60, 120, 180, 300, 600, 900, 1800`. |\n| `recycler_pod_last_recycle_timestamp_seconds` | Gauge | `recycler_namespace`, `recycler`, `recycler_pod` | Unix timestamp of the most recent recycle event for a specific pod. Useful for building an audit history of which pods were terminated and when. |\n| `recycler_pod_cpu_utilization_percent` | Gauge | `recycler_namespace`, `recycler_pod` | Current rolling-average CPU utilisation percentage for each monitored pod, calculated over the `podMetricsHistory` window. |\n\n### Example queries\n\n**Rate of pod recycles per namespace:**\n```promql\nrate(recycler_pod_recycles_total[5m])\n```\n\n**Pods currently above threshold (utilisation gauge):**\n```promql\nrecycler_pod_cpu_utilization_percent \u003e \u003cthreshold\u003e\n```\n\n**95th percentile breach-to-recycle duration:**\n```promql\nhistogram_quantile(0.95, rate(recycler_cpu_breach_duration_seconds_bucket[1h]))\n```\n\n**Total breaches detected by recycler CR:**\n```promql\nrecycler_cpu_threshold_breaches_total\n```\n\n## Building and deploying manually\n### To Deploy on the cluster\n**Build and push your image to the location specified by `IMG`:**\n\n```sh\nmake docker-build docker-push IMG=ghcr.io/theonlyway/recycler:tag\n```\n\n**NOTE:** This image ought to be published in the personal registry you specified.\nAnd it is required to have access to pull the image from the working environment.\nMake sure you have the proper permission to the registry if the above commands don’t work.\n\n**Install the CRDs into the cluster:**\n\n```sh\nmake install\n```\n\n**Deploy the Manager to the cluster with the image specified by `IMG`:**\n\n```sh\nmake deploy IMG=ghcr.io/theonlyway/recycler:tag\n```\n\n\u003e **NOTE**: If you encounter RBAC errors, you may need to grant yourself cluster-admin\nprivileges or be logged in as admin.\n\n**Create instances of your solution**\nYou can apply the samples (examples) from the config/sample:\n\n```sh\nkubectl apply -k config/samples/\n```\n\n\u003e**NOTE**: Ensure that the samples has default values to test it out.\n\n### To Uninstall\n**Delete the instances (CRs) from the cluster:**\n\n```sh\nkubectl delete -k config/samples/\n```\n\n**Delete the APIs(CRDs) from the cluster:**\n\n```sh\nmake uninstall\n```\n\n**UnDeploy the controller from the cluster:**\n\n```sh\nmake undeploy\n```\n\n## Project Distribution\n\nFollowing are the steps to build the installer and distribute this project to users.\n\n1. Build the installer for the image built and published in the registry:\n\n```sh\nmake build-installer IMG=\u003csome-registry\u003e/recycler:tag\n```\n\nNOTE: The makefile target mentioned above generates an 'install.yaml'\nfile in the dist directory. This file contains all the resources built\nwith Kustomize, which are necessary to install this project without\nits dependencies.\n\n2. Using the installer\n\nUsers can just run kubectl apply -f \u003cURL for YAML BUNDLE\u003e to install the project, i.e.:\n\n```sh\nkubectl apply -f https://raw.githubusercontent.com/\u003corg\u003e/recycler/\u003ctag or branch\u003e/dist/install.yaml\n```\n\n## Security \u0026 Verification\n\nEach release includes cryptographically signed build provenance attestations and SBOMs (Software Bill of Materials) in both SPDX and CycloneDX formats. These are attached to each GitHub release and pushed to the container registries.\n\n### Verify Attestations\n\nRequires the [GitHub CLI](https://cli.github.com/).\n\n**Verify build provenance (GHCR):**\n```sh\ngh attestation verify oci://ghcr.io/theonlyway/recycler:\u003cversion\u003e \\\n  --repo theonlyway/recycler\n```\n\n**Verify SBOM attestation (GHCR):**\n```sh\ngh attestation verify oci://ghcr.io/theonlyway/recycler:\u003cversion\u003e \\\n  --repo theonlyway/recycler \\\n  --predicate-type https://spdx.dev/Document/v2.3\n```\n\n**View full attestation details:**\n```sh\ngh attestation verify oci://ghcr.io/theonlyway/recycler:\u003cversion\u003e \\\n  --repo theonlyway/recycler \\\n  --format json | jq\n```\n\n### SBOM Files\n\nFour SBOM files are attached to each release:\n\n| File | Format | Image |\n|------|--------|-------|\n| `sbom-ghcr.spdx.json` | SPDX 2.3 | GHCR |\n| `sbom-ghcr.cyclonedx.json` | CycloneDX | GHCR |\n| `sbom-dockerhub.spdx.json` | SPDX 2.3 | Docker Hub |\n| `sbom-dockerhub.cyclonedx.json` | CycloneDX | Docker Hub |\n\nUse **SPDX** for attestation verification and compliance. Use **CycloneDX** with security scanning tools like [Grype](https://github.com/anchore/grype), [Trivy](https://github.com/aquasecurity/trivy), or [Dependency-Track](https://dependencytrack.org/).\n\n## Contributing\n// TODO(user): Add detailed information on how you would like others to contribute to this project\n\n**NOTE:** Run `make help` for more information on all potential `make` targets\n\nMore information can be found via the [Kubebuilder Documentation](https://book.kubebuilder.io/introduction.html)\n\n## License\n\nCopyright 2025.\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n    http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftheonlyway%2Frecycler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftheonlyway%2Frecycler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftheonlyway%2Frecycler/lists"}