{"id":13396202,"url":"https://github.com/B23admin/kubectl-config-cleanup","last_synced_at":"2025-03-13T22:31:49.454Z","repository":{"id":49548726,"uuid":"176971763","full_name":"B23admin/kubectl-config-cleanup","owner":"B23admin","description":"A kubectl plugin for automatically cleaning up your kubeconfig","archived":false,"fork":false,"pushed_at":"2023-04-27T03:16:10.000Z","size":3281,"stargazers_count":49,"open_issues_count":2,"forks_count":4,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-05-21T12:42:47.560Z","etag":null,"topics":["kubeconfig","kubectl-plugins","kubernetes"],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/B23admin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2019-03-21T15:19:06.000Z","updated_at":"2024-05-13T08:16:53.000Z","dependencies_parsed_at":"2024-01-13T22:23:46.209Z","dependency_job_id":"6f2f98e3-b114-4c06-9054-010d80f9a985","html_url":"https://github.com/B23admin/kubectl-config-cleanup","commit_stats":{"total_commits":31,"total_committers":2,"mean_commits":15.5,"dds":0.06451612903225812,"last_synced_commit":"6a5182b76cf5b2d68ca3d3f5c2cd0d7e404e7ba0"},"previous_names":["b23llc/kubectl-cleanup","b23llc/kubectl-config-cleanup"],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/B23admin%2Fkubectl-config-cleanup","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/B23admin%2Fkubectl-config-cleanup/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/B23admin%2Fkubectl-config-cleanup/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/B23admin%2Fkubectl-config-cleanup/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/B23admin","download_url":"https://codeload.github.com/B23admin/kubectl-config-cleanup/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243493942,"owners_count":20299747,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["kubeconfig","kubectl-plugins","kubernetes"],"created_at":"2024-07-30T18:00:42.324Z","updated_at":"2025-03-13T22:31:49.449Z","avatar_url":"https://github.com/B23admin.png","language":"Go","funding_links":[],"categories":["Kubernetes"],"sub_categories":["K8s Tools"],"readme":"# kubectl config-cleanup plugin #\n\n`kubectl config-cleanup` is a plugin for automatically cleaning up your kubeconfig.\nEvery cloud provider has their own utilities for adding kubernetes cluster credentials\nto your kubeconfig but they don't offer the ability to clean it up once the cluster is deleted.\nFor those of us who launch and delete multiple clusters per day, it would be useful to have\nan automated way to clean up old kubeconfig entries. This plugin will attempt to\nconnect to each cluster defined in a context, if the connection succeeds then the user,\ncluster, and context entry are maintained in the result. Otherwise, the entries are removed.\n\n```bash\n# prints the cleaned kubeconfig to stdout, similar to running: kubectl config view\nkubectl config-cleanup\n\n# cleanup and save the result\nkubectl config-cleanup --raw \u003e ./kubeconfig-clean.yaml\n\n# cleanup and print the configs that were removed\nkubectl config-cleanup --print-removed --raw \u003e ./kubeconfig-removed.yaml\n\n# print only the context names that were removed\nkubectl config-cleanup --print-removed -o=jsonpath='{ range.contexts[*] }{ .name }{\"\\n\"}'\n```\n\n\u003e DO NOT attempt to overwrite the source kubeconfig, it will result in an empty config.\nSee Known Issues below for details\n\n## Install ##\n\nInstall with krew: `kubectl krew install config-cleanup`\n\nor download the [latest release binary](https://github.com/B23admin/kubectl-config-cleanup/releases/latest)\nfor your platform and add it to your `$PATH`\n\n## Roadmap ##\n\n- Shell autocomplete\n- Add `users` and `clusters` functionality for config-cleanup.ignore\n- implement multi-flag for `--ignore-user`, `--ignore-cluster`, `--ignore-context`\n\n## config-cleanup.ignore ##\n\nAdd a `~/.kube/config-cleanup.ignore` to specify contexts which should be ignored during cleanup.\nThe associated context, user, and cluster will be maintained in the output. This is useful for long\nrunning clusters where the api server is behind a firewall.\n\nexample:\n\n```yaml\n---\napiVersion: v1\nkind: ConfigMap\ndata:\n  contexts: |\n    prod-cluster\n    staging-cluster\n    docker-for-desktop\n```\n\n## Plugin Development ##\n\n\u003e This project uses the [just](https://github.com/casey/just) command runner\n\n### Build from source ###\n\n```bash\njust build\n```\n\n### Release ###\n\n```bash\n# dryrun\njust dist\n\n# release by pushing a tag\njust release $TAG\n```\n\n## Known issues ##\n\n- Error log message when cleaning up GKE clusters that have already been terminated\nhttps://github.com/kubernetes/kubernetes/issues/73791\n\n- Attempting to overwrite the source kubeconfig will wipe the config completely.\n  - `config-cleanup` does not support [merging kubeconfig files](https://kubernetes.io/docs/concepts/configuration/organize-cluster-access-kubeconfig/#the-kubeconfig-environment-variable)\n  - This behavior is consistent with the behavior of `kubectl config view --raw \u003e ~/.kube/config`\n\ni.e. Dont do this: `kubectl config-cleanup --kubeconfig=~/.kube/config --raw \u003e ~/.kube/config`\n\nA simple shell script `kubectl-config_swap` in your path can easily solve for this:\n\n```bash\n#!/usr/bin/env bash\nset -euo pipefail\n\n# if $KUBECONFIG is not set, use default\nKUBECONFIG=${KUBECONFIG:-\"$HOME/.kube/config\"}\nprintf \"Using kubeconfig: %s\\n\" \"${KUBECONFIG}\" \u003e\u00262\n\ntouch \"${KUBECONFIG}.swap\" \u0026\u0026\n    mv \"${KUBECONFIG}\" \"${KUBECONFIG}.swap.tmp\" \u0026\u0026\n    mv \"${KUBECONFIG}.swap\" \"${KUBECONFIG}\" \u0026\u0026\n    mv \"${KUBECONFIG}.swap.tmp\" \"${KUBECONFIG}.swap\" \u0026\u0026\n    printf \"Success.\\n\" \u003e\u00262\n```\n\nThe workflow would appear as:\n\n```bash\nkubectl config-cleanup --raw \u003e ~/.kube/config.swap\nkubectl config-swap\n```\n\nRunning `config-swap` twice would revert the changes.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FB23admin%2Fkubectl-config-cleanup","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FB23admin%2Fkubectl-config-cleanup","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FB23admin%2Fkubectl-config-cleanup/lists"}