<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Matthew Byng-Maddick on Medium]]></title>
        <description><![CDATA[Stories by Matthew Byng-Maddick on Medium]]></description>
        <link>https://medium.com/@matthewbyngmaddick?source=rss-ec36641e9438------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*YbaWkxHf4BYUuVpaBKuMOA.jpeg</url>
            <title>Stories by Matthew Byng-Maddick on Medium</title>
            <link>https://medium.com/@matthewbyngmaddick?source=rss-ec36641e9438------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 27 Nov 2026 22:20:14 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@matthewbyngmaddick/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How I learnt to love coding infrastructure]]></title>
            <link>https://tech.olx.com/how-i-learnt-to-love-coding-infrastructure-d275355666f5?source=rss-ec36641e9438------2</link>
            <guid isPermaLink="false">https://medium.com/p/d275355666f5</guid>
            <category><![CDATA[yaml]]></category>
            <category><![CDATA[infrastructure]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[infrastructure-as-code]]></category>
            <dc:creator><![CDATA[Matthew Byng-Maddick]]></dc:creator>
            <pubDate>Tue, 09 Jan 2018 10:24:53 GMT</pubDate>
            <atom:updated>2018-03-24T11:16:44.871Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Y0CTr68QplmJURrvcBLz2g.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/photos/9cCeS9Sg6nU?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">chuttersnap</a> on <a href="https://unsplash.com/search/photos/infrastructure?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>I’m a Site Reliability Engineer, and I keep hearing about this idea of “Infrastructure as Code.” And then, when I look at the “code” that people talk about, it’s not in a Turing-complete language, I sometimes can’t write tests against it, and sometimes the tools to run it lack a certain <em>je ne sais quoi</em>.</p><p>It’s always better to work on problems that actually affect you and haven’t been really solved yet, and all of the solutions for the problem that I decided to tackle felt a bit inadequate. As part of my day job, I manage 3 <a href="https://www.openshift.com/container-platform/">Openshift Origin</a> clusters, and right now, to configure these, there are at least 430 separate objects (represented as in its <a href="https://kubernetes.io/">Kubernetes</a> parent by yaml files) for the applications running on these clusters. These include secrets, configurations, privilege information, external routes, cluster internal load-balancing and, of course, actual software deployments.</p><p>I want to keep track of what’s supposed to be on these clusters, be able to rebuild them if necessary, and build out the base infrastructure for new clusters (I’ve already had to do this, and this tooling made it a <em>lot</em> easier).</p><p>Some people, at this point will say “<a href="https://helm.sh/">Helm Charts</a>!” but I started my career in the late 1990s and early 2000s, and I thought we had learned the hard way (regex substitutions of XML in Perl, anyone?) not to try and do textual substitutions of structured data. Here, though, we seem to like the idea of textual substitutions in YAML, but it’s very easy to suddenly treat a string like structured data in YAML (<em>eg</em>. your string is “false” or “true” or a number or starts with ‘[’ or ‘{’ or ‘!’), and YAML string representations (particularly in the case of a multi-line string) turn out to be somewhat varied and non-trivial.</p><p>Similarly, we’ve long had an internal implementation of something similar, using ERB (the embedded ruby templating so enamoured in Puppet) and magic (<em>qv</em>. <a href="https://direnv.net/">direnv</a>) commands to wrap kubectl or oc, which do the ERB expansion in place. This latter has the problem that we can’t easily see what’s going to end up in the cluster configuration, editing can be a bit “guess and hope”.</p><p>The core problem, though, is that when there is an error somewhere in the templating, the error messages from the Kubernetes / Openshift masters can be unhelpful in figuring out where, and what type is incorrect — there’s no type-checking of the resulting content before it gets sent to the masters.</p><p>So, how can we do better? Introducing <a href="https://github.com/olx-global/rubiks/"><strong>rubiks</strong></a>, our tool for generating all of the hundreds of YAML files we need to configure our cluster.</p><p>The rubiks model is to do infrastructure as (real) code (<a href="https://github.com/olx-global/rubiks-examples/">see here for example</a>). You write python, filling out the objects, and the rubiks compiler turns this into the (type-checked) YAML files. Because of the type-safety, rubiks can also do translations of other objects into the correct form for the output to be read by the cluster.</p><p>On every run, we generate the complete set of objects for update in our cluster, allowing us to carry through these links.</p><p>Rubiks acts on a git repository (we also use this property to allow us to run rubiks from anywhere inside the repository and still sanely act relative to the repository root), allowing us to refactor cleanly (by checking that the output didn’t change), and conversely to use git to help figure out what changed on the output from a change to the input, and thus what changes we should push out to our clusters (something that normally happens by an ‘<em>oc replace -f &lt;file&gt;</em>’).</p><p>So why is this better? Isn’t it more complicated to write code?</p><p>The answer turns out to not be simple. Make your Domain Specific Language (<em>“DSL”</em>) not powerful enough, and you’ll end up writing code to auto-generate it (as anyone who ever built a Nagios config of sufficient size will testify, as well as all the people currently thinking to do this with Terraform’s HCL). Similarly, make it too powerful but arcane, and you need a configuration generator too (<em>qv</em>. sendmail.cf and the m4 macros).</p><p><a href="https://puppet.com/">Puppet</a> has been through this. While its language isn’t (and explicitly aims not to be) Turing-complete, it’s had to add (finite) looping and branching constructs to actually make itself useful. At the same time, <a href="https://www.chef.io/chef/">Chef</a>, in the same space, doesn’t try to protect the user from themselves, and runs the recipe in plain Ruby, injecting special names (<em>“symbols”</em>) for internal functions and objects into the namespace of the program to refer to its resources as native Ruby.</p><p>Using a base language that many Site Reliability people know and use already (and in our industry, the number of languages necessary does seem to be increasing), should help here. In writing this tool, I chose Python because I understand the Python constructs much better than Ruby. The use of Python’s strong-but-dynamic typing helps here, too, as it enables much of the type safety and type mapping. I was also inspired quite significantly by the <a href="https://research.fb.com/publications/holistic-configuration-management-at-facebook/">configerator tool at Facebook</a> although this was written without any direct reference to any of that code.</p><p>In terms of python, I don’t use <em>pip</em> or <em>virtualenv</em> or anything else. This will run on a python2.7 and a python3 (&gt;3.5, I think) cleanly from just a checkout and making sure the binary (or a symlink to it) is on your path. This is (in my experience) a good start from the tools we want to try before we commit to using them.</p><p>But my files aren’t “*.py”, and what’s with the whole <a href="https://github.com/olx-global/rubiks-examples/blob/master/sources/monitoring/kube_ops_view.ekube#L8-L10">“import_python()”</a> thing?</p><p>We <em>could</em> try to solve this problem with just plain Python (or any other language), after all, general purpose languages are just that. This solution would have value, it works in editors without any additional configuration. But general purpose languages also have downsides, they’re general purpose, not tailored to the readability of a specific problem domain. Boilerplate impedes readability, and specifically it can hide the code that you might want to highlight. The job of the code written for rubiks is to write out a cluster configuration, not to be a general purpose python program.</p><p>Instead, the rubiks tool acts as a compiler, running the “special” python (and choosing which files to run), which, like the ruby in Chef, injects a bunch of symbols that facilitate writing easy code to generate the configurations, and attempt to reduce boilerplate.</p><p>There’s another trick we can do here too, we can run these python files more than once, in several different contexts (particularly, the output cluster), generating subtly different results for each one. This means, that, for example, <a href="https://github.com/olx-global/rubiks-examples/blob/master/sources/scc.ekube">scc.ekube</a> (in our examples) isn’t quite what it appears, it’s actually run twice, and there are two separate modules held in memory, with the name “scc” and with the exported symbol “scc”, once for <a href="https://github.com/olx-global/rubiks-examples/blob/master/.rubiks#L9-L10">“staging”</a> and once for <a href="https://github.com/olx-global/rubiks-examples/blob/master/.rubiks#L12">“production”</a>. This is, of course, the behaviour that we want, because we don’t want a service account added on staging in one of our other files to alter the production output.</p><p>And then to answer the import_python question, we can now carry across the cluster information correctly, making sure staging always imports staging and production imports production (or whatever your clusters are called), but also it allows us to have different (and complementary) behaviours with filename extensions. Python’s own import keyword is ultimately tied to files with a .py extension, and the search path. In python2, that means you need __init.py__ files everywhere (which are ugly). Having import_python as a function isn’t quite as clean as a real import keyword, but with the utility of the more intelligent import it’s probably the closest we can get.</p><p>None of this suggests that <a href="https://github.com/olx-global/rubiks/">rubiks</a> is a finished product yet. We’re using it internally at OLX to help manage some of our Openshift clusters, and it has definitely proved its utility already, allowing us to define our configuration in the most appropriate ways and give us lots of flexibility and some better readability, and it’s been a massive time saver for making changes already.</p><p>The initial conversion took time, although the tool has since acquired a parser and a code generator, which allows you to take your current clusters and generate a relatively ugly, but correct object. Some objects have proved more useful than others, <em>eg</em>. while rubiks supports “User” types, this turns out not to be useful because of the way Openshift handles authentication and the creation of the bindings. Similarly the rather ugly “Namespace” handling was designed fairly early in the life of the project; in Openshift we should more likely be using a “ProjectRequest” and a “Project” type (possible future features to come!).</p><p>We also found that where things were missing (because I was often too lazy to traverse oc explain or to write the code for the full object before we required it), that we have sometimes needed to write the Kubernetes / Openshift object-handling in parallel to the DSL code that was going to use it.</p><p>We’ve made it Open Source because we believe that this is a progression on the “Infrastructure as Code” ideal, particularly in the space of managing Kubernetes or Openshift clusters. It definitely doesn’t (yet?) have the package management features of Helm, but in terms of guiding you to write consistent and correct configurations, we hope that this is something worth your time.</p><p>That said, it has some advantages for us over something like Helm, in that we have an <a href="https://www.nginx.com/">nginx</a> proxy in our clusters behind the main Openshift <a href="https://www.haproxy.com/">haproxy</a> “router”. We do this to be able to customise the authentication based on IP address and do more intelligent routing and handling of google OAuth. Rubiks allows us to more clearly auto-generate the appropriate nginx config based on what services are available. We also run prometheus in-cluster for monitoring the cluster, and this allows us to do application monitoring in a more sane way too.</p><p>Please play with <a href="https://github.com/olx-global/rubiks/">it</a>, and feel free to use our <a href="https://github.com/olx-global/rubiks-examples/">examples</a>, and please let us know what you think, and, as always, patches (or pull-requests or whatever) welcome!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d275355666f5" width="1" height="1" alt=""><hr><p><a href="https://tech.olx.com/how-i-learnt-to-love-coding-infrastructure-d275355666f5">How I learnt to love coding infrastructure</a> was originally published in <a href="https://tech.olx.com/">OLX Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>