Page MenuHomePhabricator

Pipe stdin into one-off maintenance scripts on Kubernetes
Closed, ResolvedPublic

Description

Some maintenance scripts take input on stdin, like a list of URLs. On bare metal, that's easy, because the script is running in your own shell. With the script running on k8s, it can still be accomplished with kubectl attach, but it's unwieldy.

With the new wrapper script mwscript-k8s on the deployment host, we'd like to be able to pass input through to the pod using an underlying kubectl attach, with the UI being something like either:

$ cat urls.txt | mwscript-k8s --attach -- ScriptThatDoesStuffWithUrls.php --wiki=aawiki

or:

$ mwscript-k8s --attach -- ScriptThatDoesStuffWithUrls.php --wiki=aawiki
I'm a maintenance script, please enter URLs:

https://example.com/the-user-is-typing-this-in
^D

We should support both use cases. The former needs attach -i, with stdin: true in the container spec. (It also needs stdinOnce: true; I believe there are no maintenance situations where we want the default behavior with stdinOnce: false.) The latter also needs a TTY allocated, so the same plus attach -t and tty: true.

Event Timeline

Change #1051196 had a related patch set uploaded (by RLazarus; author: RLazarus):

[operations/deployment-charts@master] mediawiki: Allow setting `tty` and `stdin` for Jobs

https://gerrit.wikimedia.org/r/1051196

Change #1034633 had a related patch set uploaded (by RLazarus; author: RLazarus):

[operations/puppet@production] deployment_server: Add --follow, --attach to mwscript_k8s

https://gerrit.wikimedia.org/r/1034633

Change #1051196 merged by jenkins-bot:

[operations/deployment-charts@master] mediawiki: Allow setting `tty` and `stdin` for Jobs

https://gerrit.wikimedia.org/r/1051196

Change #1034633 merged by RLazarus:

[operations/puppet@production] deployment_server: Add --follow, --attach to mwscript_k8s

https://gerrit.wikimedia.org/r/1034633

rzl@deploy1002:~$ echo 'https://office.wikimedia.org/wiki/User:RLazarus_(WMF)' | ./mwscript-k8s --attach -- purgeList.php
⏳ Starting purgeList.php on Kubernetes...
[snip]
⏳ Waiting for the container to start...
🚀 Job is running.
📜 Attaching to stdin/stdout:
Purging 1 urls
Done!
rzl@deploy1002:~$ ./mwscript-k8s --attach -- purgeList.php
⏳ Starting purgeList.php on Kubernetes...
[snip]
⏳ Waiting for the container to start...
🚀 Job is running.
📜 Attaching to stdin/stdout:
https://office.wikimedia.org/wiki/User:RLazarus_(WMF)
Purging 1 urls
Done!