Hacker News new | ask | show | jobs
by mdaniel 772 days ago
depending on what, exactly "bash commands don't work" <https://github.com/Megapixel99/nodejs-k8s/blob/master/functi...> is talking about, but a thing that bites A LOT of folks when dealing with command: [] (and its args:[] friend) is that they are exec style, not "sh -c" style as one might experience with a Dockerfile RUN command. I think Dockerfile's RUN [""] syntax is also exec style, but I don't use it much because it's horrifically verbose

As a concrete example, command: ["bash -c uptime"] will not work because there is no such command '/usr/bin/bash -c uptime' and the actual form is command: ["bash", "-c", "uptime"]

Related, it often bites people that exec does no shell interpolation, neither resolving variables nor redirection, so command: ["doit", ">/dev/null"] will not shake out, nor will command: ["echo", "$HOSTNAME"] (although there is a nuance to that since kubernetes itself will actually resolve any env:[] references in a (regrettably horrible) syntax of command: ["echo", "$(USERNAME)"], env: [{name: USERNAME, value: megapixel99}]

All in all, congratulations on your Show HN!

3 comments

Really a feature though. No quote issues, no shell interpolation, explicit variable resolution in the application’s scope — for most scripts I much prefer this as the default behavior.
Off the top of my head I do not remember what the issue was (the changes to the code are from a month ago). Looking at the code now, `dockerExec` <https://github.com/Megapixel99/nodejs-k8s/blame/master/funct...> uses `child_process` so that may have something to do with it... however, as I have said in other replies, I just wanted to learn more about the inner workings of k8s and I personally learn best when I create (or recreate) something, I doubt this project will take off, but if it does I will try to fix that when the time comes.

Regardless, thank you for the feedback.

I may read the source code to your project for fun.

If you ever feel inspired to do so, I *really* wish somebody would write a decent way to do controllers in JS rather than golang (metacontroller is a lovely idea but somewhat limited in what you can build with it).

https://github.com/kubernetes-client/javascript

Full disclosure I haven’t tried this but I’m curious if you have. The main component of a controller is its k8s client, so go will always have an advantage, but this JS client looks somewhat decently maintained

I have not tried it currently, because I had so far completely failed to realise it existed.

Muchas gracias and I'll have to have a look next time I'm in a suitably masochistic mood for k8s hackery.

This bites me all the time. It really shouldn't, as I'm always like: "man i'm an idiot". But inevitably I make this mistake and lose time over it.