-
Florent Aide authoredFlorent Aide authored
Beaver
____
| __ ) ___ __ ___ _____ _ __
| _ \ / _ \/ _` \ \ / / _ \ '__|
| |_) | __/ (_| |\ V / __/ |
|____/ \___|\__,_| \_/ \___|_|
Description
beaver
is a tool to build your k8s templates in a descriptive way.
Features
- template engine:
- patch engine:
- multi environment variables
- sha256 sum for any compiled resource can be used as variable
- inheritance between
beaver
project - each built resource is output inside it's own file
Usage
beaver build <path/to/beaver/project>
see beaver build --help
for more options.
Beaver project
A beaver
project consists of a folder with a beaver
config file, either beaver.yaml
or beaver.yml
.
Beaver config file
# Default namespace used for this project
namespace: default
# the desired beaver version. If the binary you use to process this file has a different
# version number, it will fail to avoid messing your resources.
beaverversion: 3.2.3
# an inherited beaver project - which can also inherit another beaver project
inherit: ../../base # path is relative to this beaver config file
inherits:
- ../../base1
- ../../base2
# your project charts
charts:
postgres: # your chart local name
type: helm # can be either helm or ytt
path: ../.vendor/helm/postgresql # path to your chart - relative to this file
name: pgsql # overwrite **helm** application name
# Keyword `namespace` only available for Helm charts
namespace: my-namespace # Set namespace only for the current chart(Optional)
# beaver variables that can be used inside your charts value files
# They are two methods
# First method :
variables:
- name: tag # give your variable a name
value: v1.2.3 # and a value
# Second method :
variables:
tag: v1.2.3
my_dict1:
my_key1: value1
my_dict2:
my_key2: value2
my_list:
- elem1
- elem2
# You can also use inherit to overlay variables
# in project/base1/beaver.yaml :
variables:
my_dict:
key1: value1
key2: value2
# If you want to redefine all dict
# in project/base2/beaver.yaml :
inherit: ../base1
variables:
my_dict:
newKey1: value3
# Or if you want to redifine part of dict
inherit: ../base1
variables:
my_dict.key1: value3
# result of dict :
variables:
my_dict:
key1:value3
key2: value1
# generate beaver variables from compiled resource file sha256
sha:
- key: configmap_demo # use to generate beaver variable name
resource: ConfigMap.v1.demo.yaml # compiled resource filename
# create some resources using `kubectl create`
create:
- type: configmap # resource kind as passed to kubectl create
name: xbus-pipelines # resource name
args: # kubectl create arguments
- flag: --from-file
value: pipelines
Value files
Value files filename use the following format:
<chart_local_name>.[yaml,yml]
you can provide a value file for your chart using its local name, and beaver
will pass this file to your template engine.
If you have a value file with the same name inside an inherited project then
beaver
will also pass this one, but prior to your project file. This ensures
that your current values overwrite inherited values.
example:
# folder structure
.
├── base
│ ├── beaver.yml
│ └── postgres.yml
└── environments
└── demo
├── beaver.yml
└── postgres.yaml
# base/beaver.yml
charts:
postgres:
type: postgres
path: ../.vendor/postgresql
# environments/demo/beaver.yml
inherit: ../../base
namespace: demo
In the example above beaver
will automaticaly pass base/postgres.yml
and then
environments/demo/postgres.yaml
to helm using .vendor/postgresql
as chart
folder.
Beaver variables
beaver
variables can be used inside your value files, using the following syntax:
<[variable_name]>
example:
# base/beaver.yaml
variables:
- name: pg_tag
value: 14.4-alpine
charts:
postgres:
type: postgres
path: ../.vendor/postgresql
# base/postgres.yml
image:
tag: <[pg_tag]>
beaver
variables are merged during inheritance, example: