fix(taskmanager): flush flow runs on Infrahub 1.13, which takes no number of days

Draft
SA
6d ago
+208-7

Summary

  • Problem: Infrahub 1.13 removes --days-to-keep and --batch-size from infrahub tasks flush flow-runs (opsmill/infrahub#11289): the task manager deletes up to its own task history retention, and --rewrite returns the disk space. infrahub-taskmanager flush flow-runs passes both options. An unknown option is not the "no such command" error that starts the tool's script fallback, so on 1.13 the tool fails.
  • Change: the tool reads infrahub tasks flush flow-runs --help in the task worker and strips ANSI color formatting before checking the options. Forced-color help therefore uses the same detection as plain help.
    • When the help offers --rewrite and no --days-to-keep (1.13 and later), the tool runs infrahub tasks flush flow-runs, with --rewrite when the new --rewrite flag is given. It warns when days_to_keep or batch_size were given, because those releases ignore them, and names the setting to use instead: INFRAHUB_TASK_MANAGER_RETENTION_TASK_HISTORY.
    • Otherwise the tool behaves as before, including the script fallback for releases without the command. --rewrite is then ignored, with a warning.
    • flush stale-runs is unchanged: its options stay in 1.13.
  • Release order: this can ship before Infrahub 1.13, because earlier releases keep the previous behaviour.

Validation of colored-help detection

The new colored-help cases fail against the previous implementation and pass with ANSI normalization, alongside the existing detection, command and warning cases. These tests ran in an isolated Go package containing the affected production declarations and the repository's test file; gofmt passed. The full package suite could not run locally because dependency downloads were denied and the embedded watchdog binaries were absent.

Original branch validation

  • Unit tests for the detection, the command and the warning. The detection fixtures are the real help texts, printed with COLUMNS=100 by the Infrahub 1.11.4 image and by a build of opsmill/infrahub#10869.
  • go vet, gofmt and golangci-lint v2.5.0 (0 issues), in containers.
  • End to end, with a macOS build of this branch, against a Docker Compose dev stack built from the opsmill/infrahub stack that ships 1.13:
    • flush flow-runs 7 --rewrite warned that the 7 days are ignored, then deleted 20,000 runs that ended 35 days ago and printed the per-table rewrite summary (21.4 MB before, 3.7 MB after);
    • flush flow-runs --rewrite with no days gave no warning and deleted 5,000 runs;
    • flush stale-runs completed.
  • Not run: a Kubernetes deployment, and an end-to-end run against a release before 1.13. On Kubernetes the run goes through ExecStream, which builds its kubectl exec arguments, environment included, with the same function as Exec, and returns an error when the command fails; the tool's script fallback already uses it.
  • go test ./... also fails in src/internal/updater (install_test.go:22: direct: got "container") when run inside a container, on main as well; it is unrelated to this change.

šŸ¤– Generated with Claude Code


Summary by cubic

Fixes infrahub-taskmanager flush flow-runs on Infrahub 1.13, which removed --days-to-keep and --batch-size from infrahub tasks flush flow-runs. The tool passes both options, and since an unknown option isn't the "no such command" error that triggers its script fallback, the command failed on 1.13.

The tool now reads the command's help in the task worker to detect the Infrahub version. When 1.13 or later is detected, it runs the command without the removed flags, passes the new --rewrite flag when requested, and warns when days_to_keep or batch_size were given that they are ignored, pointing to INFRAHUB_TASK_MANAGER_RETENTION_TASK_HISTORY instead. Earlier releases keep the previous behavior, with --rewrite ignored and a warning.

Migration

  • On Infrahub 1.13+, days_to_keep and batch_size are meaningless; set INFRAHUB_TASK_MANAGER_RETENTION_TASK_HISTORY instead.