Commit 7fa2819
fix(remediation): honor RemediationPolicy.spec.dryRun (#93)
* fix(remediation): honor RemediationPolicy.spec.dryRun
The CRD field spec.dryRun was documented as "generates fixes but does
not create actual PRs" but the controller only logged the flag — it
always called RemediationEngine.ApplyPlan, so setting dryRun=true
still opened real GitOps PRs. The only reliable preview path was
ZelyoConfig.spec.mode=audit at the operator level, which contradicts
the per-policy contract.
Gate ApplyPlan + ResolveIncident in processIncidents: when dryRun is
true, generate the plan (so operators see fix count / risk in the log
and a DryRunPreview event) but skip PR creation, leave the incident
open for a later non-dry-run reconcile, and do not bump
status.remediationsApplied.
Adds an integration test in the controller envtest suite using a fake
llm.Client and fake gitops.Engine: asserts CreatePullRequest is never
called when dryRun=true, the seeded incident stays open, and the
status counter stays at 0. A counter-case with dryRun=false exercises
the same fakes to prove CreatePullRequest is called and the incident
is resolved — this guards the dry-run assertion from passing via a
broken test harness.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* refactor(remediation): extract gitops engine setup to cut cyclomatic complexity
The dry-run gating added one branch to processIncidents, which pushed
gocyclo from 15 to 16 and tripped the repo's threshold (15). Extract
the PAT-token lookup + GitOps engine wiring into a new helper
`maybeSetGitOpsEngineFromSecret` — a flat early-return style that
reads better than the previous deeply-nested if/if/if block and
drops 3 branches from processIncidents. Pure refactor, no behavior
change.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* fix(remediation): cap LLM plan generation per cycle in dry-run mode
Gemini PR review (PR #93) flagged that prsCreated never increments on
the dryRun path, so a policy with N open incidents fires N LLM calls
per reconcile regardless of spec.maxConcurrentPRs. On clusters with
many correlated incidents that's unbounded LLM cost and reconcile-
timeout risk.
Introduce a separate `processed` counter that increments once per
incident that makes it to the LLM call (before GeneratePlan, so
plan-generation failures still count against the budget). Use it as
the loop ceiling; keep prsCreated driving the status counter so
status semantics are unchanged.
Add a regression test seeding 5 incidents against maxConcurrentPRs=2
with dryRun=true and asserting the LLM is hit exactly 2 times and
every incident stays open.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 2c8023d commit 7fa2819
2 files changed
Lines changed: 331 additions & 19 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
247 | 247 | | |
248 | 248 | | |
249 | 249 | | |
250 | | - | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
251 | 258 | | |
252 | | - | |
253 | | - | |
| 259 | + | |
| 260 | + | |
254 | 261 | | |
255 | 262 | | |
256 | | - | |
| 263 | + | |
257 | 264 | | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
258 | 268 | | |
259 | 269 | | |
260 | 270 | | |
| |||
264 | 274 | | |
265 | 275 | | |
266 | 276 | | |
267 | | - | |
268 | | - | |
269 | | - | |
270 | | - | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
271 | 287 | | |
272 | 288 | | |
273 | 289 | | |
| |||
276 | 292 | | |
277 | 293 | | |
278 | 294 | | |
279 | | - | |
| 295 | + | |
280 | 296 | | |
281 | 297 | | |
282 | 298 | | |
283 | 299 | | |
284 | 300 | | |
285 | | - | |
| 301 | + | |
286 | 302 | | |
287 | 303 | | |
288 | 304 | | |
| |||
293 | 309 | | |
294 | 310 | | |
295 | 311 | | |
296 | | - | |
297 | | - | |
298 | | - | |
299 | | - | |
300 | | - | |
301 | | - | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
302 | 323 | | |
303 | 324 | | |
304 | 325 | | |
| |||
308 | 329 | | |
309 | 330 | | |
310 | 331 | | |
311 | | - | |
| 332 | + | |
| 333 | + | |
312 | 334 | | |
313 | 335 | | |
314 | 336 | | |
| |||
317 | 339 | | |
318 | 340 | | |
319 | 341 | | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
320 | 353 | | |
321 | 354 | | |
322 | 355 | | |
323 | 356 | | |
324 | 357 | | |
325 | 358 | | |
326 | | - | |
| 359 | + | |
327 | 360 | | |
328 | 361 | | |
329 | 362 | | |
| |||
337 | 370 | | |
338 | 371 | | |
339 | 372 | | |
340 | | - | |
| 373 | + | |
341 | 374 | | |
342 | 375 | | |
343 | 376 | | |
| |||
0 commit comments