Skip to content

Commit f7b2c11

Browse files
committed
Initial commit: kdiff - Kubernetes Resource Differ
A comprehensive tool to compare Kubernetes resources between different namespaces. Features: - Compare K8s resources across namespaces - Multiple diff formats (unified, context, side-by-side) - Colored output with colordiff support - Optional kubectl neat integration - Cross-platform builds (Linux, macOS, Windows) - Homebrew tap integration - Professional CI/CD with GitHub Actions - Advanced installation scripts with options - Comprehensive documentation and examples Tech Stack: - Go 1.21 with Cobra CLI framework - GoReleaser for automated releases - GitHub Actions for CI/CD - Makefile for build automation - Shell and PowerShell installation scripts
0 parents  commit f7b2c11

18 files changed

Lines changed: 1047 additions & 0 deletions

File tree

.github/workflows/release.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
8+
permissions:
9+
contents: write
10+
11+
jobs:
12+
release:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v4
18+
with:
19+
fetch-depth: 0
20+
21+
- name: Set up Go
22+
uses: actions/setup-go@v4
23+
with:
24+
go-version: '1.21'
25+
26+
- name: Run tests
27+
run: go test ./...
28+
29+
- name: Run GoReleaser
30+
uses: goreleaser/goreleaser-action@v5
31+
with:
32+
distribution: goreleaser
33+
version: latest
34+
args: release --clean
35+
env:
36+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/test.yml

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
name: Test
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+
13+
steps:
14+
- uses: actions/checkout@v4
15+
16+
- name: Set up Go
17+
uses: actions/setup-go@v4
18+
with:
19+
go-version: '1.21'
20+
21+
- name: Cache Go modules
22+
uses: actions/cache@v3
23+
with:
24+
path: |
25+
~/.cache/go-build
26+
~/go/pkg/mod
27+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
28+
restore-keys: |
29+
${{ runner.os }}-go-
30+
31+
- name: Run tests
32+
run: go test -v ./...
33+
34+
- name: Run go vet
35+
run: go vet ./...
36+
37+
- name: Run go fmt
38+
run: |
39+
if [ "$(gofmt -s -l . | wc -l)" -gt 0 ]; then
40+
echo "The following files are not formatted:"
41+
gofmt -s -l .
42+
exit 1
43+
fi
44+
45+
- name: Build
46+
run: go build -v .
47+
48+
test-multiple-os:
49+
runs-on: ${{ matrix.os }}
50+
strategy:
51+
matrix:
52+
os: [ubuntu-latest, windows-latest, macos-latest]
53+
go-version: ['1.21', '1.22']
54+
55+
steps:
56+
- uses: actions/checkout@v4
57+
58+
- name: Set up Go
59+
uses: actions/setup-go@v4
60+
with:
61+
go-version: ${{ matrix.go-version }}
62+
63+
- name: Build
64+
run: go build -v .
65+
66+
- name: Test
67+
run: go test -v ./...

.gitignore

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
20+
# Build artifacts
21+
/bin/
22+
/dist/
23+
24+
# IDE files
25+
.vscode/
26+
.idea/
27+
28+
# OS specific files
29+
.DS_Store
30+
Thumbs.db
31+
32+
# Temporary files
33+
*.tmp
34+
*.temp

.goreleaser.yaml

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
version: 2
2+
3+
before:
4+
hooks:
5+
# You may remove this if you don't use go modules.
6+
- go mod tidy
7+
# This ensures that all dependencies are downloaded before building.
8+
- go mod download
9+
10+
builds:
11+
- env:
12+
# CGO is disabled to ensure statically linked binaries for portability across systems.
13+
- CGO_ENABLED=0
14+
binary: "{{ .ProjectName }}"
15+
goos:
16+
- linux
17+
- darwin
18+
- windows
19+
goarch:
20+
- amd64
21+
- arm64
22+
ignore:
23+
- goos: windows
24+
goarch: arm64
25+
ldflags:
26+
- "-s -w -X github.com/rajamohan-rj/kdiff/cmd/kdiff.version={{ .Version }} -X github.com/rajamohan-rj/kdiff/cmd/kdiff.commit={{ .Commit }} -X github.com/rajamohan-rj/kdiff/cmd/kdiff.date={{ .Date }}"
27+
28+
archives:
29+
- name_template: >-
30+
{{ .ProjectName }}_ {{- .Version }}_ {{- title .Os }}_ {{- if eq .Arch "amd64" }}x86_64 {{- else if eq .Arch "386" }}i386 {{- else }}{{ .Arch }}{{ end }} {{- if .Arm }}v{{ .Arm }}{{ end }}
31+
files:
32+
- LICENSE
33+
- README.md
34+
35+
checksum:
36+
name_template: 'checksums.txt'
37+
38+
release:
39+
github:
40+
owner: rajamohan-rj
41+
name: kdiff
42+
draft: false
43+
prerelease: auto
44+
mode: replace
45+
46+
# Homebrew formula configuration
47+
brews:
48+
- name: kdiff
49+
repository:
50+
owner: rajamohan-rj
51+
name: homebrew-tap
52+
branch: main
53+
token: "{{ .Env.HOMEBREW_TAP_GITHUB_TOKEN }}"
54+
directory: Formula
55+
homepage: "https://github.com/rajamohan-rj/kdiff"
56+
description: "Kubernetes resource differ"
57+
license: "MIT"
58+
install: |
59+
bin.install "kdiff" => "kdiff"
60+
test: |
61+
system "#{bin}/kdiff", "--version"
62+
63+
changelog:
64+
use: github
65+
sort: asc
66+
filters:
67+
exclude:
68+
- "^docs:"
69+
- "^test:"
70+
- "README"
71+
groups:
72+
- title: Features
73+
regexp: "^.*feat[(\\w)]*:+.*$"
74+
order: 0
75+
- title: 'Bug fixes'
76+
regexp: "^.*fix[(\\w)]*:+.*$"
77+
order: 1
78+
- title: Others
79+
order: 999

HOMEBREW.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Setting up Homebrew Tap (Optional)
2+
3+
To enable `brew install kdiff`, you need to create a Homebrew tap repository:
4+
5+
## Steps:
6+
7+
1. **Create a new repository** named `homebrew-tap` on GitHub under your account
8+
- Repository: `https://github.com/rajamohan-rj/homebrew-tap`
9+
10+
2. **Initialize the repository**:
11+
```bash
12+
git clone https://github.com/rajamohan-rj/homebrew-tap.git
13+
cd homebrew-tap
14+
mkdir Formula
15+
echo "# Homebrew Tap for kdiff" > README.md
16+
git add .
17+
git commit -m "Initial commit"
18+
git push origin main
19+
```
20+
21+
3. **GoReleaser will automatically**:
22+
- Create Formula/kdiff.rb on each release
23+
- Update the formula with new versions
24+
- Handle dependencies and checksums
25+
26+
4. **Users can then install via**:
27+
```bash
28+
brew tap rajamohan-rj/tap
29+
brew install kdiff
30+
```
31+
32+
## Note:
33+
The Homebrew tap is configured in `.goreleaser.yaml` and will be automatically maintained by the release process.

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 kdiff
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Makefile

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
APP=kdiff
2+
VERSION=0.1.0
3+
COMMIT=$(shell git rev-parse --short HEAD 2>/dev/null || echo "none")
4+
DATE=$(shell date -u +%Y-%m-%dT%H:%M:%SZ)
5+
6+
.PHONY: build test dist deb clean help
7+
8+
help:
9+
@echo "Available targets:"
10+
@echo " build - Build the binary to bin/$(APP)"
11+
@echo " install - Build and install to /opt/homebrew/bin"
12+
@echo " test - Run all tests"
13+
@echo " dist - Build distribution binaries for multiple platforms"
14+
@echo " deb - Build Debian package"
15+
@echo " clean - Clean build artifacts"
16+
@echo " redeploy - Clean and rebuild"
17+
@echo " help - Show this help message"
18+
19+
build:
20+
mkdir -p bin
21+
go build -ldflags "-X github.com/rajamohan-rj/kdiff/cmd/kdiff.version=$(VERSION) -X github.com/rajamohan-rj/kdiff/cmd/kdiff.commit=$(COMMIT) -X github.com/rajamohan-rj/kdiff/cmd/kdiff.date=$(DATE)" -o bin/$(APP) .
22+
23+
install: build
24+
cp bin/$(APP) /opt/homebrew/bin/$(APP) 2>/dev/null || echo "Could not install to /opt/homebrew/bin, run 'sudo make install' or add bin/ to PATH"
25+
26+
test:
27+
go test ./...
28+
29+
dist: clean
30+
mkdir -p dist
31+
GOOS=linux GOARCH=amd64 go build -ldflags "-s -w -X github.com/rajamohan-rj/kdiff/cmd/kdiff.version=$(VERSION) -X github.com/rajamohan-rj/kdiff/cmd/kdiff.commit=$(COMMIT) -X github.com/rajamohan-rj/kdiff/cmd/kdiff.date=$(DATE)" -o dist/$(APP)-linux-amd64 .
32+
GOOS=darwin GOARCH=amd64 go build -ldflags "-s -w -X github.com/rajamohan-rj/kdiff/cmd/kdiff.version=$(VERSION) -X github.com/rajamohan-rj/kdiff/cmd/kdiff.commit=$(COMMIT) -X github.com/rajamohan-rj/kdiff/cmd/kdiff.date=$(DATE)" -o dist/$(APP)-darwin-amd64 .
33+
GOOS=darwin GOARCH=arm64 go build -ldflags "-s -w -X github.com/rajamohan-rj/kdiff/cmd/kdiff.version=$(VERSION) -X github.com/rajamohan-rj/kdiff/cmd/kdiff.commit=$(COMMIT) -X github.com/rajamohan-rj/kdiff/cmd/kdiff.date=$(DATE)" -o dist/$(APP)-darwin-arm64 .
34+
GOOS=linux GOARCH=arm64 go build -ldflags "-s -w -X github.com/rajamohan-rj/kdiff/cmd/kdiff.version=$(VERSION) -X github.com/rajamohan-rj/kdiff/cmd/kdiff.commit=$(COMMIT) -X github.com/rajamohan-rj/kdiff/cmd/kdiff.date=$(DATE)" -o dist/$(APP)-linux-arm64 .
35+
cd dist && tar -czf $(APP)_$(VERSION)_linux_amd64.tar.gz $(APP)-linux-amd64 && tar -czf $(APP)_$(VERSION)_linux_arm64.tar.gz $(APP)-linux-arm64 && tar -czf $(APP)_$(VERSION)_darwin_amd64.tar.gz $(APP)-darwin-amd64 && tar -czf $(APP)_$(VERSION)_darwin_arm64.tar.gz $(APP)-darwin-arm64
36+
37+
deb: build
38+
mkdir -p dist/deb/usr/local/bin dist/deb/DEBIAN
39+
cp bin/$(APP) dist/deb/usr/local/bin/kdiff
40+
echo "Package: kdiff" > dist/deb/DEBIAN/control
41+
echo "Version: $(VERSION)" >> dist/deb/DEBIAN/control
42+
echo "Section: utils" >> dist/deb/DEBIAN/control
43+
echo "Priority: optional" >> dist/deb/DEBIAN/control
44+
echo "Architecture: amd64" >> dist/deb/DEBIAN/control
45+
echo "Maintainer: You <your-email@example.com>" >> dist/deb/DEBIAN/control
46+
echo "Description: Kubernetes resource differ" >> dist/deb/DEBIAN/control
47+
dpkg-deb --build dist/deb dist/kdiff_$(VERSION)_amd64.deb
48+
49+
clean:
50+
rm -rf bin dist
51+
52+
redeploy: clean build

0 commit comments

Comments
 (0)