Goless

Overview It’s been a goal of mine for a while to write a Kubernetes operator. I was playing with Kubeless and I didn’t like how they implemented their support for Golang so I decided to write my own. Operators Operators are a deployment of a Kubernetes controller and Custom Resource Definitions (CRDs). The controller watches in a loop for new custom resources created and then takes some action. The controller lets you extend the ability of Kubernetes without directly changing any Kubernetes code....

October 2, 2021 · 2 min · 389 words · John Hooks

Bbolt Client

I use BoltDb in a few projects of mine because it’s lightweight and easily embedded in Go. However, everytime I write something that uses BoltDB I find myself writing a ton of boilerplate to complete the same tasks in every project. For example to create a bucket you need something like this: package main import ( "go.etcd.io/bbolt" "log" "fmt" ) func main() { db, err := bbolt.Open("mydb.db", 0664, nil) if err !...

May 29, 2021 · 3 min · 501 words · John Hooks

Functional Options

I was looking at ways to do method chaining in Go and found this article from Jon Calhoun about functional options. He made some really good points. I read through it probably three times, and being the dull knife that I am had trouble wrapping my head around it. So I sat down and tried to figure it out. I figured I’d put this post together for anyone who is in the same boat as me and wants a nice simple example of how functional options work....

August 4, 2020 · 4 min · 684 words · John Hooks

Contributing to Go Projects

Contributing to projects on GitHub is a great way to learn, contribute, and help make the software you use better. Normally, you would just make a fork of the project and then clone your fork and do your work. Then you would push to a branch in your fork and open a pull request for that branch. Go is a little different however. Since the imports are specific paths to GitHub/GitLab/etc projects you can’t necessarily just fork the project and do work in your fork....

April 20, 2020 · 2 min · 299 words · John Hooks

Testing Terraform with Terratest

This should be another short one. One of the advantages of IaC (infrastructure as code) is the fact you can test the things you write. There are multiple tools to test your Terraform configs with, but Gruntwork has created an awesome Go package to test your Terraform configs called Terratest. The advantage to Terratest is you just write Go like you would with anything else and it just works. Here’s an example module to create an ec2 instance:...

March 6, 2020 · 2 min · 355 words · John Hooks

Using Terraform and Ansible Together

This should be a short one. So Ansible has dynamic inventories however I’ve found it a bit slow with VMware if you have a lot of infrastructure to parse through (a lot being around 3,000 VMs in your vCenter and slow being around 15 minutes). I also couldn’t figure out a way to use tags to limit what you’re searching on. This admittedly could have changed recently but since I’ve been using this method I haven’t tried too hard to find out....

February 1, 2020 · 2 min · 219 words · John Hooks

Using AlertManager Webhooks

The defacto Alerting tool used with Prometheus is Alertmanager. Prometheus sends a notification to Alertmanager whenever a rule is triggered. Alertmanager then takes that notification and sends it to whatever receiver(s) you have defined in your config. It supports quite a few options: email, hipchat, pagerduty, pushover, slack, opsgenie, victorops, webhook, and wechat. For this post I’m focusing on the webhook receiver. First let’s set up our Alert struct: type Alert struct { Receiver string `json:"receiver"` Status string `json:"status"` Alerts []struct { Status string `json:"status"` Labels struct { Alertname string `json:"alertname"` Service string `json:"service"` Severity string `json:"severity"` } `json:"labels"` Annotations struct { Summary string `json:"summary"` } `json:"annotations"` StartsAt string `json:"startsAt"` EndsAt time....

October 19, 2019 · 3 min · 555 words · John Hooks