Skip to content

Simple template for Kubernetes operators written in Golang

License

Notifications You must be signed in to change notification settings

Luukvdm/operator-template

Repository files navigation

Operator Template

A repository that can be easily used as a base for a Kubernetes operator. I created this repository because I felt like the files that projects like Operator-SDK and Kubebuilder generate are to bloated and hard to understand.

Getting Started

Building and installing

Build the project and install the helm chart for the current context:

make install

Just build the source code:

make build

Install on a kind cluster, beside doing a normal install, this also loads the image onto the cluster:

make kind-install

Code Generation

The custom resource definition yaml, role yaml and Go copy functions for the resource are generated. You can use these make goals to (re)generate them:

make generate

Dependencies

Manager

The controller-runtime manager is used to easily create the controller for the custom resource. This replaces a lot of boilerplate code that allows us to focus on the logic for our custom resource.

Generation

This project uses the controller-tools controller-gen from Kubernetes to generate some files. The files that are generated are the custom resource yaml, role yaml, and the Go copy implementations for the resource.
By generating the Yaml files the Go code becomes the single source of truth about the custom resource definition properties.

CLI Interface

Like most Go projects, we use spf13/cobra to create the CLI interface. Right now the CLI code is relatively basic, but this could expand the more your project grows.
And other then that, using Cobra just makes your life easier.

Logging

The manager from controller runtime makes use of logr abstraction for loggers. There are many implementations for this abstraction like glogr (golog), klogr (logger from the Kubernetes project), stdr (the standard logger library) and many more.
This template uses the zapr implementation because of it's performance and my preferences.

About

Simple template for Kubernetes operators written in Golang

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages