Created
May 24, 2017 19:19
-
-
Save hosh/89099f6f14ca5101e22c55f8d7f9e65d to your computer and use it in GitHub Desktop.
Matsuri Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Matsuri.define will generate a custom class and registers it | |
# Because it is a Ruby class, you can create mixins by creating a Ruby | |
# module and `include` it in. | |
# Everything is broken down into smaller `let()`. If you are not familiar | |
# with it, it is taken from Rspec, and defines a memoized method. We can | |
# then customize functionality by overriding any of the lets. In this case, | |
# the base class of the pod definition defines the manifests: | |
# https://github.com/matsuri-rb/matsuri/blob/master/lib/matsuri/kubernetes/pod.rb#L10 | |
# Notice how I am overriding just enough to create a pod. However, I can override | |
# the entire `let(:spec)` to generate a completely different specification. | |
Matsuri.define :pod, :redis do | |
let(:labels) { { cache: 'redis' } } | |
let(:volumes) { [] } | |
let(:container) do | |
{ | |
name: 'redis', | |
image: 'docker.io/library/redis:3.2-alpine', # https://hub.docker.com/_/redis/ | |
ports: [port(6379)] | |
} | |
end | |
# port() is just a regular (non-memoized) Ruby method. Here, it is used as | |
# a helper to output the full port specification appropriate for a pod. | |
# You can write your own helpers. | |
# One of the helpers included in Matsuri is the ability to reference any of the | |
# other specs. This is most useful with deployments, replicasets, replicationcontrollers, | |
# or anything that embeds a PodSpec. This allows you to reuse the pod and instantiate | |
# a pod directly (say in, dev) while still creating a deployment out of it (say in production). | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment