Luke Hopkins

jack of all trades

To working in devops, you have to develop a very wide breadth of knowledge just to be able to do your job. However because you need a braoder understanding, your knowledge tends to be shallower in places. For the past few weeks I’ve been working on a project to migrate our microservices into a Kubernetes cluster. I’d like to run you few a few of the things I’ve been working with.

it starts with spring

I started working on some Spring Java projects. The existing projects get most of their configuration from runtime flags. Since we run Docker containers in Kubernetes, we wanted to be able to modify the config from Kubernetes. This involved modifying the command we run within the Docker container to use environmental variables and also setting the defaults for those environmental variables. I started the process running a few vim find and replaces to see what the end result might look like. These quickly grew and with a bit of googling I ended up with the following:
%s, ,\r,g | %s,-D\(.*\)=,\U&,g | %s,\(\u\|\d\)\(\.\)\(\u\|\d\),\1\u_\3\u,g | %s,=,=", | %s,$," \\,g | %s,-D,,g
%s, ,\r,g | %s,-D\([^=]*\)=\(.*\),-D\1=\$\U\1, | %s,\(\u\|\d\)\(\.\)\(\u\|\d\),\1\u_\3\u,g | %s,=\$,="\$,g | %s,.*=.*\u$,&",g | %s,$, \\,g
This converts the entire existing command into the new format in one go and incidentally taught me way more about vim’s find and replace feature than I ever knew before.

throw in some java

Because of some major changes that had been made recently to a process tracking tool some of our projects failed to compile. It was now time to fire up Intellij, a Java IDE, and learn how to use it. Once I was up and running in Intellij I was with the help of some colleagues that know more Java than I do able to go through the code with and fix where it was broken. In the process I learned a bit more about how Java works and how to debug issues with it.

a smidge of log4j

Logging in the Docker world is a bit different from before. While before we used to log to files in Docker, we now want to log to stdout and stderr. This avoids having to go into containers to see the log files. After some reading up on log4j I was able to write up a new log4j properties file that ensure that everything we logged went to console.

and now to drop some things

I next started work on some Dropwizard projects. Dropwizard projects use a YAML configuration file. With the addition of a bit of a code you can get Dropwizard to lookup environmental variables. This, however, requires you to specify what your environmental variables are called in the YAML configuration file. Since I was parsing YAML, I turned to Python which has some modules to parse YAML with. Each variable name had to be unique, so I ended up having to learn the intricacies of how Python dictionaries and arrays worked. I came up with an elegant solution that ran down the layers of the YAML file before pushing the modified results up the chain untill the entire file was updated.

javascript is like java right?

Finally I started on some NodeJS projects. This time I turns out that I was in luck because the config files for our NodeJS files are essentially in a JSON format. I subbed out the YAML parser in my Python script for a JSON one and modified the exact changes made at the lowest level and I quickly had a script that would convert our NodeJS projects. The logging for NodeJS turned out to be a bit trickier. After some consultation with one of our Javascript developers, we came up with a command line flag and an if statement that would ensure that when we wanted to we could log to console.

nope

So over this project I’ve had to learn some Java, some Javascript, some Python, the workings of various frameworks and much more. We shall have to see what the next few weeks brings.

If you enjoyed the read, drop us a comment below or share the article, follow us on Twitter or subscribe to our #MetaBeers newsletter. Before you go, grab a PDF of the article, and let us know if it’s time we worked together.

blog comments powered by Disqus