Skip to content

Commit f0a6701

Browse files
committed
feat: initial
0 parents  commit f0a6701

File tree

14 files changed

+1863
-0
lines changed

14 files changed

+1863
-0
lines changed

.github/release-drafter.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name-template: 'v$RESOLVED_VERSION'
2+
tag-template: 'v$RESOLVED_VERSION'
3+
4+
categories:
5+
- title: '🚀 Features'
6+
labels:
7+
- 'feature'
8+
- 'enhancement'
9+
- title: '🐛 Bug Fixes'
10+
labels:
11+
- 'fix'
12+
- 'bugfix'
13+
- 'bug'
14+
- title: '🧰 Maintenance'
15+
labels:
16+
- 'chore'
17+
- 'dependencies'
18+
- title: '📚 Documentation'
19+
labels:
20+
- 'documentation'
21+
- 'docs'
22+
23+
change-template: '- $TITLE @$AUTHOR (#$NUMBER)'
24+
change-title-escapes: '\<*_&'
25+
26+
version-resolver:
27+
major:
28+
labels:
29+
- 'major'
30+
minor:
31+
labels:
32+
- 'minor'
33+
patch:
34+
labels:
35+
- 'patch'
36+
default: patch
37+
38+
template: |
39+
## Changes
40+
41+
$CHANGES
42+
43+
## Contributors
44+
45+
$CONTRIBUTORS

.github/workflows/ci.yml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
strategy:
13+
matrix:
14+
go-version: [1.23, 1.24]
15+
16+
steps:
17+
- uses: actions/checkout@v4
18+
19+
- name: Set up Go
20+
uses: actions/setup-go@v5
21+
with:
22+
go-version: ${{ matrix.go-version }}
23+
24+
- name: Cache Go modules
25+
uses: actions/cache@v4
26+
with:
27+
path: |
28+
~/.cache/go-build
29+
~/go/pkg/mod
30+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
31+
restore-keys: |
32+
${{ runner.os }}-go-
33+
34+
- name: Download dependencies
35+
run: go mod download
36+
37+
- name: Verify dependencies
38+
run: go mod verify
39+
40+
- name: Run go vet
41+
run: go vet ./...
42+
43+
- name: Build
44+
run: go build -v ./...
45+
46+
build:
47+
runs-on: ubuntu-latest
48+
needs: test
49+
strategy:
50+
matrix:
51+
goos: [linux, windows, darwin]
52+
goarch: [amd64, arm64]
53+
54+
steps:
55+
- uses: actions/checkout@v4
56+
57+
- name: Set up Go
58+
uses: actions/setup-go@v5
59+
with:
60+
go-version: 1.24
61+
62+
- name: Build binary
63+
env:
64+
GOOS: ${{ matrix.goos }}
65+
GOARCH: ${{ matrix.goarch }}
66+
run: |
67+
mkdir -p build
68+
go build -o build/finalizer-cleaner-${{ matrix.goos }}-${{ matrix.goarch }}${{ matrix.goos == 'windows' && '.exe' || '' }} .
69+
70+
- name: Upload artifacts
71+
uses: actions/upload-artifact@v4
72+
with:
73+
name: finalizer-cleaner-${{ matrix.goos }}-${{ matrix.goarch }}
74+
path: build/
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Release Drafter
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
types: [opened, reopened, synchronize]
8+
9+
permissions:
10+
contents: read
11+
12+
jobs:
13+
update_release_draft:
14+
permissions:
15+
contents: write
16+
pull-requests: write
17+
runs-on: ubuntu-latest
18+
steps:
19+
- uses: release-drafter/release-drafter@v6
20+
env:
21+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Binaries for programs and plugins
2+
*.exe
3+
*.exe~
4+
*.dll
5+
*.so
6+
*.dylib
7+
8+
# Test binary, built with `go test -c`
9+
*.test
10+
11+
# Output of the go coverage tool, specifically when used with LiteIDE
12+
*.out
13+
14+
# Dependency directories (remove the comment below to include it)
15+
# vendor/
16+
17+
# Go workspace file
18+
go.work
19+
go.work.sum
20+
21+
# Binary
22+
finalizer-cleaner
23+
24+
# IDE files
25+
.idea/
26+
.vscode/
27+
*.swp
28+
*.swo
29+
*~
30+
31+
# OS files
32+
.DS_Store
33+
Thumbs.db
34+
35+
# Local environment files
36+
.env
37+
.env.local

README.md

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
# Finalizer Cleaner
2+
3+
A Kubernetes tool to safely remove finalizers from resources based on specified criteria. Features both CLI flags and an interactive TUI mode for easy finalizer management.
4+
5+
## Features
6+
7+
- **Interactive TUI Mode**: User-friendly interface for selecting namespaces, resource types, and finalizers
8+
- **Batch Operations**: Remove finalizers from multiple resources at once
9+
- **Dry Run Mode**: Preview changes before applying them
10+
- **Flexible Filtering**: Filter by namespaces, resource kinds, and specific finalizer names
11+
- **Comprehensive Logging**: Detailed logging with different log levels
12+
- **Safe Operations**: Only removes specified finalizers, preserving others
13+
14+
## Installation
15+
16+
### From Source
17+
18+
```bash
19+
go install github.com/risen228/finalizer-cleaner@latest
20+
```
21+
22+
### Build Locally
23+
24+
```bash
25+
git clone https://github.com/risen228/finalizer-cleaner.git
26+
cd finalizer-cleaner
27+
go build .
28+
```
29+
30+
## Usage
31+
32+
### Interactive Mode
33+
34+
Run without arguments or with limited arguments to enter interactive TUI mode:
35+
36+
```bash
37+
finalizer-cleaner
38+
```
39+
40+
The interactive mode will guide you through:
41+
1. Selecting namespaces (or all namespaces)
42+
2. Selecting resource types (or all types)
43+
3. Selecting which finalizers to remove
44+
45+
### CLI Mode
46+
47+
Specify all parameters via command-line flags:
48+
49+
```bash
50+
./finalizer-cleaner \
51+
--namespaces "default,kube-system" \
52+
--kinds "apps/v1/Deployment,v1/Pod" \
53+
--finalizers "kubernetes.io/pvc-protection,example.com/finalizer"
54+
```
55+
56+
### Flags
57+
58+
- `--namespaces`: Comma-separated list of namespaces (empty = all namespaces)
59+
- `--kinds`: Comma-separated list of Group/Version/Kind triplets (empty = all kinds)
60+
- `--finalizers`: Comma-separated list of finalizers to remove (empty = all finalizers)
61+
- `--dry-run`: Print what would be changed without making actual modifications
62+
- `--interactive`: Force interactive mode even when other flags are provided
63+
- `--verbose`: Enable verbose logging for detailed operation information
64+
- `--timeout`: HTTP timeout for Kubernetes API calls (default: 30s)
65+
66+
### Examples
67+
68+
#### Remove specific finalizer from all deployments in default namespace
69+
70+
```bash
71+
./finalizer-cleaner \
72+
--namespaces default \
73+
--kinds apps/v1/Deployment \
74+
--finalizers "example.com/my-finalizer"
75+
```
76+
77+
#### Dry run to see what would be removed
78+
79+
```bash
80+
./finalizer-cleaner \
81+
--namespaces default \
82+
--dry-run
83+
```
84+
85+
#### Verbose logging for detailed operation information
86+
87+
```bash
88+
./finalizer-cleaner \
89+
--namespaces default \
90+
--kinds apps/v1/Deployment \
91+
--verbose
92+
```
93+
94+
#### Remove all finalizers from failed pods (dangerous!)
95+
96+
```bash
97+
./finalizer-cleaner \
98+
--namespaces default \
99+
--kinds v1/Pod \
100+
--finalizers ""
101+
```
102+
103+
## Safety Considerations
104+
105+
1. **Always use dry-run first**: Before performing actual removal, use `--dry-run` to preview changes
106+
2. **Be specific with finalizers**: Only remove finalizers you understand. Removing system finalizers can cause data loss
107+
3. **Understand the impact**: Finalizers exist to ensure proper cleanup. Removing them bypasses this cleanup
108+
4. **Backup important resources**: Consider backing up critical resources before removing finalizers
109+
110+
## Common Use Cases
111+
112+
### Stuck Namespace Deletion
113+
114+
When a namespace is stuck in "Terminating" state:
115+
116+
```bash
117+
./finalizer-cleaner \
118+
--namespaces stuck-namespace \
119+
--finalizers "kubernetes"
120+
```
121+
122+
### PVC Protection Removal
123+
124+
To force-delete protected PVCs:
125+
126+
```bash
127+
./finalizer-cleaner \
128+
--kinds v1/PersistentVolumeClaim \
129+
--finalizers "kubernetes.io/pvc-protection"
130+
```
131+
132+
### Custom Operator Cleanup
133+
134+
Remove custom operator finalizers:
135+
136+
```bash
137+
./finalizer-cleaner \
138+
--kinds "example.com/v1/CustomResource" \
139+
--finalizers "example.com/operator-finalizer"
140+
```
141+
142+
## Architecture
143+
144+
The tool is structured into several modules:
145+
146+
- `main.go`: Entry point and orchestration
147+
- `config.go`: Configuration parsing and validation
148+
- `tui.go`: Interactive terminal UI components
149+
- `kubernetes.go`: Kubernetes client and operations
150+
- `logger.go`: Structured logging utilities
151+
- `utils.go`: Helper functions
152+
153+
## Requirements
154+
155+
- Go 1.21 or later
156+
- Access to a Kubernetes cluster (via `~/.kube/config` or `KUBECONFIG` environment variable)
157+
- Appropriate RBAC permissions to list and patch target resources
158+
159+
## Known Issues
160+
161+
### Dependency Conflicts
162+
This project currently uses `replace` directives in `go.mod` to resolve protobuf registration conflicts between `gnostic` and `gnostic-models` libraries. See `DEPENDENCY_NOTES.md` for details and future migration plans.
163+
164+
## License
165+
166+
MIT License
167+
168+
## Contributing
169+
170+
Contributions are welcome! Please feel free to submit a Pull Request.

0 commit comments

Comments
 (0)