The newline that cost me a day
I love bash. It’s great. The Unix principle and all of it. Today there was one invisible guest that was giving me a hardtime though. You guessed it. The newline.
Background. I’m working with
k8s and I wanted to setup a quick database that I could connect to with my
Quarkus application. To do this I setup a postgres container and dutifully I used secrets in
k8s to encode the password. Now, these have to be base64 encoded strings. So I did this, and used the same base64 encoded string for the password for postgres as for my quarkus application.
Great. But when my application starts it says it can’t authenticate. Not so great. Ok, why? First I try with port forwarding but notice that I don’t even have to give a password to the postgres when doing this. Then I launch another postgres standalone pod in kubernetes and execute
psql from inside it. There I notice that my password does work.
Ok, so it works, but my application can’t use it. Why?
I think maybe there’s something wrong with Quarkus. So I start experimenting with overriding configurations using environment variables (which is the technique that I use for the password as well). It seems to work. Ok. I find another trick, you can exec env on your container to see what you injected. Ok, I do it:
k exec benchmark-store-56bcd4c79b-bk2cp -n e2e-test -it -- env. Hmm, there seems to be a newline in there. Ok, I used
pass to generate my password. Now I try using echo to feed base64, but I get the same result. Can it really be a newline that’s causing my issue?
I setup my container to print out the password on startup. Yes. It’s the newline.
Okay, I use the
-n flag, newline is gone. And my application starts. I’m one day later. My appartment one wall poorer. Everyone else pretty much the same, and the world still rotates around the sun.
Code of the Day
echo -n "I never want to redo that error again (:"