• Stars
    star
    100
  • Rank 338,695 (Top 7 %)
  • Language
    Go
  • License
    Apache License 2.0
  • Created almost 4 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Migrations-Operator

A Kubernetes operator to manage database migrations or similar application setup tasks.

Quick Start

Install

TODO

Usage

For the common case of running SQL migrations for a deployment, create a Migrator object:

apiVersion: migrations.coderanger.net/v1beta1
kind: Migrator
metadata:
  name: mymigrations
spec:
  selector:
    matchLabels:
      app: myapp
  command:
  - python
  - manage.py
  - migrate

This will automatically run migrations on all future deployment changes.

API

There's one API object, the Migrator, with these fields:

  • selector: LabelSelector for which pods to watch to trigger an upgrade action.
  • templateSelector: optional LabelSelector for which specific pod, selected by selector, to use as a template for building the upgrade Job.
  • command: optional string array which will be used as the upgrade Job's command.
  • args: optional string array to be used as the upgrade Job's args.
  • image: optional image to use for the upgrade Job.
  • container: optional name of a container from the selected template Pod. The selected container will be used to run the upgrader.
  • labels: optional map of labels to set on the Job's pod template,
  • annotations: optional map of annotations to set on the Job's pod template,

The migrator Job will contain only the single template container, initContainers will be included but sidecars will not. Any livenessProbes and readinessProbes in the template will be ignored.

How It Works

The operator has three main components: the migrations controller, the waiter init container, and the injector webhook. The migrations controller watches for new pods matching its selector and if they are running a new image, it launches a Job to run the migrations as configured. The waiter init container stalls a pod from fully launching until the required migrations have been executed successfully. The injector webhook automatically adds the waiter init container to any pod that matches a Migrator object.

Put together, these three components allow relatively normal Kubernetes usage while ensuring migrations are applied in the expected way.

Alternatives

Migrations-Operator vs. Helm/Argo Hooks

A common choice for running database migrations is the pre-install/upgrade hook in both Helm and Argo-CD. This allows for ensuring that migrations succeed before the main segment of the chart or application is applied. The main frustration with this approach is you can end up having to move a lot of things into the hook. If your pod uses a Secret or ConfigMap for holding configuration data that's required for running migrations, that will have to be hook'd too. If you need a whole chart dependency to be up for migrations, it may not even be posible. Migrations-Operator solves this by lazily cloning the pod specification on the new, waiting pods.

Migrations-Operator vs. Init Container

Another common solution for database migrations is an init container to run the migration commands. The main problem here is locking, if you run 4 replicas of your application, all 4 of those are going to try and apply your migrations in parallel. You could add some leader election code to your migrations runner, however this has to be built in at the application image level and so requires a specific solution for each application framework or toolkit. Migrations-Operator has a top-level view of the world and so can ensure for only a single job at a time is created.

Development

Setting up GitHub Actions

In order for Actions to be able to push a container image into GHCR, a GHCR_PAT secret must be present on the repository. A container image will only be built on pushes to the default branch.

More Repositories

1

pychef

Python library to interact with the Chef server API
Python
196
star
2

supervisor-stdout

Python
110
star
3

pyzen

A continuous test runner for Python
Python
83
star
4

kitchen-sync

Test Kitchen transport plugin to speed up tests.
Ruby
81
star
5

nightlies

Tool to trigger nightly builds on Travis CI.
Ruby
68
star
6

commis

A Django implementation of a Chef server
Python
63
star
7

etcd-chef

etcd/chef integration PoC spike
Ruby
47
star
8

knife-solve

A knife plugin to see the Chef Server version solver solution for a given set of cookbooks.
Ruby
46
star
9

rspec-command

rspec-command is a helper module for using RSpec to test command-line applications.
Ruby
39
star
10

chef-collectd

Chef cookbook for collectd
Ruby
36
star
11

djangocon2011

DjangoCon 2011 Case Study
Ruby
32
star
12

traefik-forward-auth-dex

31
star
13

kitchen-kubernetes

A Test Kitchen driver for testing on top of a Kubernetes cluster.
Ruby
28
star
14

talk-mentorship

talk-mentorship
CSS
24
star
15

statusboard

A modular widget-based status board
Python
24
star
16

chef-sentry-handler

Ruby
19
star
17

brix

Balanced infrastructure definitions and scripts
Python
19
star
18

dco

A command line tool to help manage projects using the Developer Certificate of Origin contributor workflow.
Ruby
17
star
19

cfp-scraper

Python
16
star
20

alfred-lulz

16
star
21

controller-utils

Go
15
star
22

depot

Python
15
star
23

chef-collectd_plugins

Chef cookbook for collectd plugins
Ruby
13
star
24

farmrpg-ext

Python
11
star
25

chef-supervisor

Cookbook to install and configure supervisord
Ruby
11
star
26

kubernetes-wsgi

A web server for running your Python web application using Twisted in a way that works well for Kubernetes.
Python
7
star
27

octan_demo

This repository is an example of using Terraform and Chef to build a multi-tier web application in AWS.
HTML
7
star
28

pynomic

Python Nomic implementation for Google App Engine
Python
6
star
29

flask-zen

A Flask extension for PyZen support.
Python
6
star
30

talk-ideas

My talk proposals
5
star
31

devopstsdb

DevOpsDays Hackathon project
Ruby
5
star
32

buddy.farm

TypeScript
5
star
33

glitchtools

Python
4
star
34

bouncycastle

Go
4
star
35

now-cookbook

Ruby
4
star
36

ohai-example

An example of installing an Ohai plugin from a Chef cookbook.
Ruby
4
star
37

pycon-2011

Code for the Introduction to C tutorial at Pycon 2011
C
3
star
38

heroku-buildpack-cffi

A helper buildpack to get CFFI and projects that use it working on Heroku.
Shell
3
star
39

stratosphere

Object-oriented CloudFormation definitions
Python
3
star
40

serverspec-docset

CSS
3
star
41

farmrpg-wiki-archive

Python
3
star
42

sublime-plugins

Plugins for Sublime Text 2
Python
3
star
43

fabric-rundeck

Provides helpers for integration between Fabric and Rundeck.
Python
3
star
44

celery-local-exporter

Python
3
star
45

rabbitmq-operator

Go
3
star
46

chef-jenkins-example

An example of using Chef with Jenkins
Ruby
3
star
47

bigdata

PHP
3
star
48

ohai-softlayer

Ruby
2
star
49

yard-classmethods

Ruby
2
star
50

testemote

Minisite for the TEST Alliance emoticon pack
Python
2
star
51

house-dash

JavaScript
2
star
52

coderanger.net

Source files for coderanger.net
HTML
2
star
53

workflow

Experiments in asynchronous Python
Python
2
star
54

watbutton

PHP
2
star
55

invention

JavaScript
2
star
56

sourcelaforge

PHP
2
star
57

ispypiup

Python
2
star
58

chef-funnel

Ruby
2
star
59

rspec-param

An RSpec helper module for writing parameterized tests with less boilerplate.
Ruby
2
star
60

misc

Miscellaneous scripts and snippets
Python
2
star
61

chef-dialects-testbed

Random testbed for Chef dialects stuff
Ruby
1
star
62

poise-docker

Ruby
1
star
63

kolirc

Connect to Kingdom of Loathing chat from an IRC client.
CoffeeScript
1
star
64

farmrpg-etl2

Python
1
star
65

python-cookbook

Ruby
1
star
66

bitburner-scripts

TypeScript
1
star
67

rackspace_devex_jobs

Open Jobs for the Rackspace Developer Experience Team
1
star
68

gswd-vm

Ruby
1
star
69

antitrust

JavaScript
1
star
70

streamdeck

Python
1
star
71

trac-achievements

Python
1
star
72

buildpack-python-copy

Python
1
star
73

getchef

Python
1
star
74

coderanger.github.com

Blog content for blog.coderanger.net
JavaScript
1
star
75

trashpanda

The source for the trashpanda.club microsite.
HTML
1
star