Skip to content

Commit 7bca612

Browse files
committed
Add GitHub Actions workflow for building and releasing Go project
1 parent b479394 commit 7bca612

File tree

7 files changed

+1552
-21
lines changed

7 files changed

+1552
-21
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: Build and Release Kdiff
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
release:
11+
types: [published]
12+
13+
permissions:
14+
contents: write
15+
16+
jobs:
17+
build-and-compress:
18+
runs-on: ubuntu-latest
19+
20+
steps:
21+
- name: Checkout code
22+
uses: actions/checkout@v4
23+
24+
- name: Set up Go environment
25+
uses: actions/setup-go@v5
26+
with:
27+
go-version: '1.24.3'
28+
29+
- name: Run 'compress' target from Makefile
30+
run: make compress
31+
32+
- name: Upload kdiff.tgz for release (as artifact)
33+
uses: actions/upload-artifact@v4
34+
with:
35+
name: kdiff-linux-amd64
36+
path: kdiff.tgz
37+
38+
create-github-release:
39+
needs: build-and-compress
40+
runs-on: ubuntu-latest
41+
42+
if: github.event_name == 'release' && github.event.action == 'published'
43+
44+
steps:
45+
- name: Download kdiff.tgz artifact
46+
uses: actions/download-artifact@v4
47+
with:
48+
name: kdiff-linux-amd64
49+
path: .
50+
51+
- name: Create GitHub Release and Upload Asset
52+
uses: softprops/action-gh-release@v1
53+
with:
54+
files: kdiff.tgz
55+
env:
56+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

LICENSE

Lines changed: 674 additions & 21 deletions
Large diffs are not rendered by default.

Makefile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CORES := $(shell nproc)
2+
3+
build:
4+
CGO_ENABLED=0 GOMAXPROCS=$(CORES) go build -p $(CORES) -ldflags="-s -w" -o kdiff
5+
6+
compress: build
7+
tar -cvzf kdiff.tgz ./kdiff
8+
9+
.PHONY: build compress

README.md

Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
# 🚀 kdiff
2+
3+
<div align="center">
4+
5+
![Go](https://img.shields.io/badge/go-%2300ADD8.svg?style=for-the-badge&logo=go&logoColor=white)
6+
![Kubernetes](https://img.shields.io/badge/kubernetes-%23326ce5.svg?style=for-the-badge&logo=kubernetes&logoColor=white)
7+
![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg?style=for-the-badge)
8+
9+
**A pretty command-line tool to monitor Kubernetes pod resource usage vs requests**
10+
11+
Compare actual CPU and memory usage against requested resources with color-coded output for easy identification of over/under-utilized pods.
12+
13+
</div>
14+
15+
## ✨ Features
16+
17+
- 🎨 **Color-coded output** - Instantly identify resource utilization patterns
18+
- 📊 **Detailed comparison** - See requested vs actual CPU and memory usage
19+
- 🌐 **Multi-namespace support** - Check single namespace or all at once
20+
- 🎯 **Flexible filtering** - Show only CPU, memory, or both
21+
-**Performance focused** - Fast scanning with progress indicators
22+
- 🔧 **Customizable thresholds** - Adjust color coding to your needs
23+
- 📈 **Usage percentage** - Clear percentage differences for easy analysis
24+
25+
## 🎨 Color Legend
26+
27+
- <span style="color: cyan">**Cyan**</span> - Very under-utilized (< -90% by default)
28+
- <span style="color: green">**Green**</span> - Under-utilized (-90% to -20% by default)
29+
- <span style="color: yellow">**Yellow**</span> - Well-utilized (-20% to 0% by default)
30+
- <span style="color: red">**Red**</span> - Over-utilized (> 0% by default)
31+
- <span style="color: magenta">**Magenta**</span> - No resource requests set
32+
33+
## 🚀 Installation
34+
35+
### Option 1: Download Pre-built Binary
36+
37+
```bash
38+
# Download the latest release for your platform
39+
curl -L https://github.com/Senk02/kdiff/releases/latest/download/kdiff-linux-amd64 -o kdiff
40+
chmod +x kdiff
41+
sudo mv kdiff /usr/local/bin/
42+
```
43+
44+
### Option 2: Build from Source
45+
46+
```bash
47+
# Clone the repository
48+
git clone https://github.com/Senk02/kdiff.git
49+
cd kdiff
50+
51+
# Build the binary
52+
make build
53+
54+
sudo chmod +x kdiff
55+
56+
# Optional: Install to PATH
57+
sudo mv kdiff /usr/local/bin/
58+
```
59+
60+
## 📋 Prerequisites
61+
62+
- Kubernetes cluster with `metrics-server` installed and running
63+
- Valid `kubeconfig` file (usually at `~/.kube/config`)
64+
- Go 1.19+ (if building from source)
65+
66+
## 🔧 Usage
67+
68+
### Basic Usage
69+
70+
```bash
71+
# Check current namespace
72+
kdiff
73+
74+
# Check specific namespace
75+
kdiff -n kube-system
76+
77+
# Check all namespaces
78+
kdiff -a
79+
```
80+
81+
### Advanced Options
82+
83+
```bash
84+
# Show only CPU usage across all namespaces
85+
kdiff -a -o cpu
86+
87+
# Show only memory usage in specific namespace
88+
kdiff -n production -o memory
89+
90+
# Show only pods exceeding their requests
91+
kdiff -d
92+
93+
# Ignore pods without resource requests set
94+
kdiff -i
95+
96+
# Combine filters: only over-utilized pods with requests set
97+
kdiff -d -i
98+
99+
# Use specific kubeconfig context
100+
kdiff --context my-cluster-context
101+
```
102+
103+
### Custom Color Thresholds
104+
105+
```bash
106+
# Customize when colors appear (values are percentages)
107+
kdiff --color-red 10 --color-yellow -10 --color-cyan -75
108+
109+
# This means:
110+
# Red: > 10% over requests
111+
# Yellow: -10% to 10% of requests
112+
# Green: -75% to -10% under requests
113+
# Cyan: < -75% under requests
114+
```
115+
116+
## 📊 Example Output
117+
118+
```
119+
Processing 3 running pods...
120+
Progress: 3/3 pods - Complete!
121+
122+
+------------------+------------------+-------------+--------------+----------------+-------------+---------------+
123+
| POD | REQUESTED MEMORY | USED MEMORY | MEMORY DIFF | REQUESTED CPU | USED CPU | CPU DIFF (%) |
124+
+------------------+------------------+-------------+--------------+----------------+-------------+---------------+
125+
| nginx-deployment | 128.0Mi | 45.2Mi | -64.69% | 100m | 23m | -77.00% |
126+
| api-server | 512.0Mi | 634.1Mi | 23.85% | 200m | 156m | -22.00% |
127+
| database | 1.0Gi | 890.3Mi | -13.18% | 500m | 520m | 4.00% |
128+
+------------------+------------------+-------------+--------------+----------------+-------------+---------------+
129+
```
130+
131+
## 🛠️ Command Line Options
132+
133+
| Flag | Description |
134+
|------|-------------|
135+
| `-n <namespace>` | Specify namespace to check (defaults to current context) |
136+
| `-a` | Check all namespaces |
137+
| `-o <filter>` | Filter output to 'cpu' or 'memory' |
138+
| `-d` | Only show pods with usage over requests |
139+
| `-i, --ignore-unset` | Ignore pods without resource requests set |
140+
| `--context <context>` | Use specific kubeconfig context |
141+
| `-h` | Show help message |
142+
| `--color-red <float>` | Threshold for red color (default: 0.0) |
143+
| `--color-yellow <float>` | Threshold for yellow color (default: -20.0) |
144+
| `--color-cyan <float>` | Threshold for cyan color (default: -90.0) |
145+
146+
## 🤝 Contributing
147+
148+
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
149+
150+
1. Fork the repository
151+
2. Create your feature branch (`git checkout -b feature/AmazingFeature`)
152+
3. Commit your changes (`git commit -m 'Add some AmazingFeature'`)
153+
4. Push to the branch (`git push origin feature/AmazingFeature`)
154+
5. Open a Pull Request
155+
156+
## 📝 License
157+
158+
This project is licensed under the GNU GPL V3 License - see the [LICENSE](LICENSE) file for details.
159+
160+
## ☕ Support
161+
162+
If you find this tool helpful, consider supporting the development:
163+
164+
<div align="center">
165+
166+
[![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/senk0)
167+
168+
</div>
169+
170+
## 🐛 Troubleshooting
171+
172+
### Common Issues
173+
174+
**"Error connecting to metrics API"**
175+
- Ensure `metrics-server` is installed: `kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml`
176+
- Check if metrics-server pods are running: `kubectl get pods -n kube-system | grep metrics-server`
177+
178+
**"No running pods found"**
179+
- Verify you're connected to the right cluster: `kubectl cluster-info`
180+
- Check if pods exist in the namespace: `kubectl get pods -n <namespace>`
181+
182+
**"Error creating kubeconfig"**
183+
- Ensure your kubeconfig file exists and is valid: `kubectl config view`
184+
- Try specifying a different context: `kdiff --context <context-name>`
185+
186+
---
187+
188+
<div align="center">
189+
190+
**Made with ❤️ for the Kubernetes community**
191+
192+
[Report Bug](https://github.com/Senk02/kdiff/issues) · [Request Feature](https://github.com/Senk02/kdiff/issues)
193+
194+
</div>

go.mod

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
module github.com/Senk02/kdiff
2+
3+
go 1.24.3
4+
5+
require (
6+
github.com/fatih/color v1.18.0
7+
github.com/olekukonko/tablewriter v1.0.7
8+
k8s.io/api v0.33.1
9+
k8s.io/apimachinery v0.33.1
10+
k8s.io/client-go v0.33.1
11+
k8s.io/metrics v0.33.1
12+
)
13+
14+
require (
15+
github.com/davecgh/go-spew v1.1.1 // indirect
16+
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
17+
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
18+
github.com/go-logr/logr v1.4.2 // indirect
19+
github.com/go-openapi/jsonpointer v0.21.0 // indirect
20+
github.com/go-openapi/jsonreference v0.20.2 // indirect
21+
github.com/go-openapi/swag v0.23.0 // indirect
22+
github.com/gogo/protobuf v1.3.2 // indirect
23+
github.com/google/gnostic-models v0.6.9 // indirect
24+
github.com/google/go-cmp v0.7.0 // indirect
25+
github.com/google/uuid v1.6.0 // indirect
26+
github.com/josharian/intern v1.0.0 // indirect
27+
github.com/json-iterator/go v1.1.12 // indirect
28+
github.com/mailru/easyjson v0.7.7 // indirect
29+
github.com/mattn/go-colorable v0.1.13 // indirect
30+
github.com/mattn/go-isatty v0.0.20 // indirect
31+
github.com/mattn/go-runewidth v0.0.16 // indirect
32+
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
33+
github.com/modern-go/reflect2 v1.0.2 // indirect
34+
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
35+
github.com/olekukonko/errors v0.0.0-20250405072817-4e6d85265da6 // indirect
36+
github.com/olekukonko/ll v0.0.8 // indirect
37+
github.com/pkg/errors v0.9.1 // indirect
38+
github.com/rivo/uniseg v0.2.0 // indirect
39+
github.com/spf13/pflag v1.0.5 // indirect
40+
github.com/x448/float16 v0.8.4 // indirect
41+
golang.org/x/net v0.38.0 // indirect
42+
golang.org/x/oauth2 v0.27.0 // indirect
43+
golang.org/x/sys v0.31.0 // indirect
44+
golang.org/x/term v0.30.0 // indirect
45+
golang.org/x/text v0.23.0 // indirect
46+
golang.org/x/time v0.9.0 // indirect
47+
google.golang.org/protobuf v1.36.5 // indirect
48+
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
49+
gopkg.in/inf.v0 v0.9.1 // indirect
50+
gopkg.in/yaml.v3 v3.0.1 // indirect
51+
k8s.io/klog/v2 v2.130.1 // indirect
52+
k8s.io/kube-openapi v0.0.0-20250318190949-c8a335a9a2ff // indirect
53+
k8s.io/utils v0.0.0-20241104100929-3ea5e8cea738 // indirect
54+
sigs.k8s.io/json v0.0.0-20241010143419-9aa6b5e7a4b3 // indirect
55+
sigs.k8s.io/randfill v1.0.0 // indirect
56+
sigs.k8s.io/structured-merge-diff/v4 v4.6.0 // indirect
57+
sigs.k8s.io/yaml v1.4.0 // indirect
58+
)

0 commit comments

Comments
 (0)