-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathjustfile
More file actions
311 lines (248 loc) · 10.6 KB
/
Copy pathjustfile
File metadata and controls
311 lines (248 loc) · 10.6 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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
#!/usr/bin/env just --justfile
# DCops Development Justfile
# Set shell for recipes
set shell := ["bash", "-uc"]
# Default recipe to display help
default:
@just --list --unsorted
# ============================================================================
# Development Environment
# ============================================================================
# Shared k3s cluster checkout (override if layout differs)
export SHARED_K8S_CLUSTER_ROOT := env_var_or_default('SHARED_K8S_CLUSTER_ROOT', '../shared-gitops-k8s-cluster')
export KUBECONFIG := env_var_or_default('KUBECONFIG', SHARED_K8S_CLUSTER_ROOT + '/kubeconfig/shared-k8s.yaml')
export TILT_PORT := "10354"
export REGISTRY := "10.177.76.220:5000"
export NETBOX_UI_PORT := "8011"
# Start development environment (shared-k8s + Tilt)
dev-up:
python3 scripts/dev_up.py
# Stop Tilt only (shared-k8s cluster and registry mirror stay up)
dev-down:
python3 scripts/dev_down.py
# Verify shared-k8s prerequisites without starting Tilt
verify-shared-k8s:
(cd {{SHARED_K8S_CLUSTER_ROOT}} && just check-ready)
# Start Tilt only (assumes shared-k8s cluster is already running)
tilt-up: verify-shared-k8s
@echo "🎯 Starting Tilt..."
@echo " Tilt UI: http://0.0.0.0:{{TILT_PORT}} (LAN: http://<this-host>:{{TILT_PORT}}/)"
@echo " NetBox UI: http://localhost:{{NETBOX_UI_PORT}} (via Tilt port forward)"
@echo " Kea Control Agent: http://localhost:8010 (via Tilt port forward)"
@tilt up --host 0.0.0.0 --port {{TILT_PORT}}
# Stop Tilt only
tilt-down:
@echo "🛑 Stopping Tilt..."
@tilt down --port {{TILT_PORT}}
# Install systemd user unit for DCops Tilt (ms02)
dev-install-tilt-service:
@mkdir -p "${HOME}/.config/systemd/user"
@install -m 0644 deployment-configuration/systemd/tilt-dcops.service "${HOME}/.config/systemd/user/tilt-dcops.service"
@systemctl --user daemon-reload
@echo "Installed tilt-dcops.service (port 10354). Start with: systemctl --user start tilt-dcops"
# ============================================================================
# Building
# ============================================================================
# Build all (Rust binary + Docker image)
build: build-rust build-docker
# Test pxe-server crate
test-pxe-server:
@cargo test -p pxe-server
build-rust:
@echo "🔨 Building Rust binary..."
@cargo build --workspace
# Build Rust binary (release)
build-release:
@echo "🔨 Building Rust binary (release)..."
@cargo build --workspace --release
# Build Rust binary for musl target (cross-compilation)
build-musl:
@echo "🔨 Building Rust binary for musl target..."
@python3 scripts/host_aware_build.py --release
# Build Docker image (development)
build-docker:
@echo "🐳 Building Docker images (development)..."
@docker build -f dockerfiles/Dockerfile.pxe-intent-controller.dev -t {{REGISTRY}}/dcops-pxe-intent-controller:dev .
@docker build -f dockerfiles/Dockerfile.ip-claim-controller.dev -t {{REGISTRY}}/dcops-ip-claim-controller:dev .
# Build Docker image (production)
build-docker-prod:
@echo "🐳 Building Docker images (production)..."
@docker buildx build -f dockerfiles/Dockerfile.pxe-intent-controller -t {{REGISTRY}}/dcops-pxe-intent-controller:latest .
@docker buildx build -f dockerfiles/Dockerfile.ip-claim-controller -t {{REGISTRY}}/dcops-ip-claim-controller:latest .
# Build base images
build-base:
@echo "🐳 Building base Docker images..."
@docker buildx build -f dockerfiles/Dockerfile.base.rust-builder -t {{REGISTRY}}/dcops-rust-builder-base-image:latest .
@docker buildx build -f dockerfiles/Dockerfile.base.controller -t {{REGISTRY}}/dcops-controller-base-image:latest .
# ============================================================================
# Testing
# ============================================================================
# Run all tests
test: test-unit
# Run unit tests
test-unit:
@echo "🧪 Running unit tests..."
@cargo test --workspace --lib --no-fail-fast
# Run unit tests with output
test-unit-verbose:
@echo "🧪 Running unit tests (verbose)..."
@cargo test --workspace --lib -- --nocapture --no-fail-fast
# Run tests with nextest (faster test execution)
nextest-test:
@echo "🧪 Running tests with nextest..."
@cargo nextest run --workspace --all-targets --fail-fast --retries 1
alias nt := nextest-test
# Run tests with LLVM coverage
test-coverage:
@echo "🧪 Running tests with LLVM coverage..."
@echo "📦 Installing cargo-llvm-cov if needed..."
@cargo install cargo-llvm-cov --locked 2>/dev/null || true
@echo "🔍 Generating coverage report..."
@cargo llvm-cov --workspace --lib --lcov --output-path lcov.info
@cargo llvm-cov --workspace --lib --html --output-dir target/llvm-cov/html
@echo "✅ Coverage report generated:"
@echo " 📊 HTML: target/llvm-cov/html/index.html"
@echo " 📄 LCOV: lcov.info"
@cargo llvm-cov --workspace --lib --summary-only
# Open coverage report in browser
test-coverage-open:
@echo "🌐 Opening coverage report..."
@open target/llvm-cov/html/index.html || xdg-open target/llvm-cov/html/index.html || echo "Please open target/llvm-cov/html/index.html manually"
# ============================================================================
# Code Quality
# ============================================================================
# Format code
fmt:
@echo "🎨 Formatting code..."
@cargo fmt
# Check formatting
fmt-check:
@echo "🎨 Checking code formatting..."
@cargo fmt -- --check
# Lint code
lint:
@echo "🔍 Linting code..."
@cargo clippy --workspace -- -D warnings
# Lint and fix
lint-fix:
@echo "🔍 Linting and fixing code..."
@cargo clippy --fix --allow-dirty --allow-staged
# Audit dependencies
audit:
@echo "🔒 Auditing dependencies..."
@cargo audit
# Check code (compile without building)
check:
@echo "✅ Checking code..."
@cargo check --workspace --all-targets
# Validate all (format, lint, check, tests, coverage)
validate: fmt-check lint check test-unit test-coverage-check
@echo "✅ All validations passed!"
# Check coverage meets minimum (65%)
test-coverage-check:
@echo "📊 Checking test coverage (minimum 65%)..."
@cargo install cargo-llvm-cov --locked 2>/dev/null || true
@cargo llvm-cov --workspace --lib --summary-only | grep -E "^\s*Total\s+\|\s+[0-9]+\s+\|\s+[0-9]+\s+\|\s+([0-9]+)%" || echo "⚠️ Could not parse coverage, run 'just test-coverage' for full report"
# ============================================================================
# Deployment
# ============================================================================
# Deploy to Kubernetes (using kustomize)
deploy:
@echo "🚀 Deploying to Kubernetes..."
@kubectl apply -k config/
@echo "✅ Deployed to dcops-system / netbox namespaces"
# Deploy CRDs only
deploy-crd:
@echo "📝 Deploying CRDs..."
@kubectl apply -f config/crd/
@echo "✅ CRDs deployed"
# Undeploy from Kubernetes
undeploy:
python3 scripts/undeploy.py
# ============================================================================
# Utilities
# ============================================================================
# Clean build artifacts
clean:
@echo "🧹 Cleaning build artifacts..."
@cargo clean
@echo "✅ Cleaned"
# Show cluster and controller status
status:
python3 scripts/status.py
# Show PXE Intent Controller logs
logs-pxe:
@echo "📜 PXE Intent Controller logs..."
@kubectl logs -n dcops-system -l app=pxe-intent-controller --tail=100 -f
# Show IP Claim Controller logs
logs-ip:
@echo "📜 IP Claim Controller logs..."
@kubectl logs -n dcops-system -l app=ip-claim-controller --tail=100 -f
# Show all controller logs
logs-all:
@echo "📜 All controller logs..."
@kubectl logs -n dcops-system -l app.kubernetes.io/part-of=dcops --tail=100 -f --all-containers=true
# Port forward to PXE Intent Controller metrics
port-forward-pxe:
@echo "🔌 Port forwarding to PXE Intent Controller metrics (5000)..."
@kubectl port-forward -n dcops-system svc/pxe-intent-controller-metrics 5000:5000
# Port forward to IP Claim Controller metrics
port-forward-ip:
@echo "🔌 Port forwarding to IP Claim Controller metrics (5001)..."
@kubectl port-forward -n dcops-system svc/ip-claim-controller-metrics 5001:5000
# ============================================================================
# NetBox Management
# ============================================================================
# Deploy NetBox to shared-k8s cluster
deploy-netbox:
@echo "🚀 Deploying NetBox..."
@python3 scripts/deploy_netbox.py
# Undeploy NetBox from shared-k8s cluster
undeploy-netbox:
@echo "🛑 Undeploying NetBox..."
@python3 scripts/undeploy_netbox.py
# Show NetBox deployment status
netbox-status:
@echo "📊 NetBox Status..."
@python3 scripts/netbox_status.py
# Port forward to NetBox
port-forward-netbox:
@echo "🔌 Port forwarding to NetBox (8000)..."
@kubectl port-forward -n netbox svc/netbox 8000:80
# Manage NetBox API token for IP Claim Controller
# Usage: just netbox-token
# Or with token: NETBOX_TOKEN=abc123 just netbox-token
# Or with URL: NETBOX_URL=http://localhost:8011 just netbox-token
netbox-token:
@echo "🔑 Managing NetBox API token..."
@python3 scripts/manage_netbox_token.py
# Create a NetBox prefix
# Usage: NETBOX_TOKEN=<token> just netbox-create-prefix --prefix 192.168.1.0/24
netbox-create-prefix prefix:
@echo "📝 Creating NetBox prefix..."
@python3 scripts/create_netbox_prefix.py --token $${NETBOX_TOKEN} --prefix $(prefix)
# Verify NetBox CR reconciliation
# Usage: just verify-netbox-crs
# Or verify specific CRD: just verify-netbox-crs --crd netboxprefixes
# Or verify specific CR: just verify-netbox-crs --crd netboxprefixes --name control-plane-prefix
verify-netbox-crs:
@echo "🔍 Verifying NetBox CR reconciliation..."
@python3 scripts/verify_netbox_crs.py --all
# ============================================================================
# Dependencies & Tools
# ============================================================================
# Check prerequisites
check-deps:
python3 scripts/check_deps.py
# ============================================================================
# Documentation
# ============================================================================
# Generate documentation
docs:
@echo "📚 Generating documentation..."
@cargo doc --no-deps --open
# Generate documentation (without opening)
docs-build:
@echo "📚 Building documentation..."
@cargo doc --no-deps
@echo "✅ Documentation built: target/doc/"