-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
162 lines (143 loc) · 5.01 KB
/
Makefile
File metadata and controls
162 lines (143 loc) · 5.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# Makefile for kubechronicle development
.PHONY: help build run test clean deps fmt vet lint docs docs-serve
# Default target
help:
@echo "kubechronicle Makefile"
@echo ""
@echo "Available targets:"
@echo " deps - Download and install dependencies"
@echo " build - Build the webhook binary"
@echo " run - Run the webhook locally (requires TLS certs)"
@echo " test - Run tests"
@echo " fmt - Format code"
@echo " vet - Run go vet"
@echo " lint - Run linter (if installed)"
@echo " clean - Clean build artifacts"
@echo " docker-build - Build Docker image"
@echo " docs - Build documentation (MkDocs)"
@echo " docs-serve - Serve documentation locally (MkDocs)"
# Download and install dependencies
deps:
@echo "Downloading dependencies..."
go mod download
go mod tidy
@echo "✓ Dependencies installed"
# Build the webhook binary
build:
@echo "Building webhook..."
@mkdir -p bin
go build -o bin/webhook ./cmd/webhook
@echo "✓ Binary built: bin/webhook"
# Build the API server binary
build-api:
@echo "Building API server..."
@mkdir -p bin
go build -o bin/api ./cmd/api
@echo "✓ Binary built: bin/api"
# Build the audit processor binary
build-audit-processor:
@echo "Building audit processor..."
@mkdir -p bin
go build -o bin/audit-processor ./cmd/audit-processor
@echo "✓ Binary built: bin/audit-processor"
# Run the webhook locally
run: build
@echo "Running webhook locally..."
@echo "Note: Requires TLS certificates in ./certs/ directory"
@if [ ! -f ./certs/tls.crt ] || [ ! -f ./certs/tls.key ]; then \
echo "Error: TLS certificates not found in ./certs/"; \
echo "Generate them with: cd deploy/webhook && ./generate-certs.sh"; \
echo "Then copy tls.crt and tls.key to ./certs/"; \
exit 1; \
fi
./bin/webhook \
-port=8443 \
-cert=./certs/tls.crt \
-key=./certs/tls.key
# Run tests
test:
@echo "Running tests..."
go test -v ./...
# Run tests with coverage
test-coverage:
@echo "Running tests with coverage..."
go test -v -coverprofile=coverage.out ./internal/...
go tool cover -func=coverage.out
@echo ""
@echo "Coverage report saved to coverage.out"
@echo "View HTML report with: make coverage-html"
@echo ""
@echo "Core packages coverage:"
@go tool cover -func=coverage.out | grep -E "(admission|diff|config)" | grep total || go tool cover -func=coverage.out | grep total
# Run tests and check coverage threshold (90% average for core packages)
# Core packages: admission, diff, config (excludes cmd/webhook and store)
test-coverage-check:
@echo "Running tests with coverage check (target: 90% average for core packages)..."
@go test -v -coverprofile=coverage.out ./internal/admission ./internal/diff ./internal/config
@echo ""
@echo "Coverage by package:"
@go tool cover -func=coverage.out | grep -E "(admission|diff|config)" | grep -v "100.0%" || true
@echo ""
@echo "Checking coverage threshold..."
@total_cov=$$(go tool cover -func=coverage.out 2>/dev/null | grep "total:" | awk '{print $$3}' | sed 's/%//'); \
if [ -n "$$total_cov" ]; then \
total_int=$$(echo $$total_cov | cut -d. -f1); \
echo "Total coverage for core packages: $$total_cov%"; \
if [ $$total_int -lt 90 ]; then \
echo "ERROR: Coverage $$total_cov% is below 90% threshold"; \
echo "Note: cmd/webhook (main) and store (requires DB) are excluded"; \
exit 1; \
else \
echo "✓ Coverage $$total_cov% meets 90% threshold"; \
fi \
else \
echo "✓ All tests passed"; \
fi
# Generate HTML coverage report
coverage-html:
@echo "Generating HTML coverage report..."
@go tool cover -html=coverage.out -o coverage.html
@echo "Coverage report saved to coverage.html"
@echo "Open with: open coverage.html"
# Format code
fmt:
@echo "Formatting code..."
go fmt ./...
# Run go vet
vet:
@echo "Running go vet..."
go vet ./...
# Run linter (requires golangci-lint)
lint:
@if ! command -v golangci-lint &> /dev/null; then \
echo "golangci-lint not found. Install with: go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest"; \
exit 1; \
fi
@echo "Running linter..."
golangci-lint run
# Clean build artifacts
clean:
@echo "Cleaning..."
rm -rf bin/
go clean
@echo "✓ Cleaned"
# Build Docker image
docker-build:
@echo "Building Docker image..."
docker build -t kubechronicle/webhook:latest .
# Install documentation dependencies (MkDocs + Material theme)
deps-docs:
@echo "Installing documentation dependencies..."
pip install -r requirements-docs.txt
@echo "✓ Documentation dependencies installed"
# Build documentation site (MkDocs)
docs:
@echo "Building documentation..."
@command -v mkdocs >/dev/null 2>&1 || { echo "MkDocs not found. Run: make deps-docs or pip install mkdocs mkdocs-material"; exit 1; }
mkdocs build
@echo "✓ Documentation built in site/"
# Serve documentation locally (live reload)
docs-serve:
@echo "Serving documentation at http://127.0.0.1:8000"
@command -v mkdocs >/dev/null 2>&1 || { echo "MkDocs not found. Run: make deps-docs or pip install mkdocs mkdocs-material"; exit 1; }
mkdocs serve