In T341553#10200997, T341553#10203241, and T341553#10208261, we discussed that cirrus-reindex-orchestrator, which currently shells out to mwscript, should instead shell out to mwscript-k8s, but it should be able to invoke a machine-readable output mode.
That might look like:
$ mwscript-k8s --output=json -- Version.php enwiki { ..., "config": "/etc/kubernetes/mw-script-codfw.config", "job": "mw-script.codfw.abcde123", ... }
With --output=json, the JSON on standard output contains all the information needed to interact with the Kubernetes API (either through the Python library or by invoking kubectl). Client software like the Cirrus reindexer can launch a job with mwscript-k8s, then follow up to get script output, exit code, or anything else.
We'll ensure that all the needed information is present in the output, and doesn't need to be inferred or constructed -- e.g. one could, but should not, construct the value of "config" by parsing the value of "job" in the example above. This way, Search team isn't affected when implementation details of the maintenance scripts' Helm config, like the format of the job name, change under the hood.
The --output=json mode is incompatible with --attach and --follow. Output from the maintenance script would interfere with reading the JSON from stdout. Plus, client software would want to reconnect in the event the underlying kubectl logs is interrupted by a network hiccup (for example) and so it'll manage fetching its own logs as appropriate.
Almost all of mwscript-k8s's own output (including progress updates like "Waiting for the container to start...") is currently on stderr, so it doesn't get in the way of the JSON on stdout and doesn't need to be affected by --output=json. There are a couple of exceptions, which I'll switch from stdout to stderr as part of this task. Note this is not the case when --verbose is passed, in which case we pipe through stdout from helmfile apply, so --verbose is incompatible with --output=json too.
We'll retronym the existing behavior as --output=none, because nothing is printed on stdout, and keep it as the default. That leaves us open for other flavors of output in the future.
Thanks to @Scott_French for talking through all this with me this afternoon.