Skip to content

Commit

Permalink
Merge pull request #136 from FairwindsOps/nh/schema-validation-jsonsc…
Browse files Browse the repository at this point in the history
…hema

Supporting Schema Validation
  • Loading branch information
nickfw authored Sep 27, 2019
2 parents b54beb3 + eac2d28 commit 591b09b
Show file tree
Hide file tree
Showing 23 changed files with 563 additions and 253 deletions.
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ jobs:
pip install --user .
cd installer
python -c 'from setuptools_scm import get_version; get_version(root="..", write_to="reckoner/version.txt")'
pyinstaller --noconfirm --paths .:../ --onefile --add-data ../reckoner/version.txt:reckoner --name reckoner cli.py
pyinstaller --noconfirm --paths .:../ --onefile --add-data ../reckoner/version.txt:reckoner --add-data ../reckoner/assets/course.schema.json:reckoner/assets --name reckoner cli.py
- run:
name: persist binaries
command: |
Expand Down Expand Up @@ -126,7 +126,7 @@ jobs:
python3 -c 'from setuptools_scm import get_version; get_version(root="..", write_to="reckoner/version.txt")'
echo "Running the binary compiler"
pyinstaller --noconfirm --paths .:../ --onefile --add-data ../reckoner/version.txt:reckoner --name reckoner cli.py
pyinstaller --noconfirm --paths .:../ --onefile --add-data ../reckoner/version.txt:reckoner --add-data ../reckoner/assets/course.schema.json:reckoner/assets --name reckoner cli.py
echo "Running the new Binary"
./dist/reckoner version
Expand Down
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
## [2.1.0]
- Added Helm 3 detection

### Breaking Changes
- Added end-to-end test for values files in sub-folders
- Schema Validation
- We are introducing schema validation on the course.yml. This will exit hard if your course.yml has indentation errors or other issues that don't conform to the course.yml expected schema. The schema can be found at [here](/reckoner/assets/course.schema.json).
- Reckoner now blocks on YAML duplicate keys. If your yaml has duplicate keys in any section of the yaml, the course will fail to load and no actions will be performed. There is no way to allow duplicate keys in course.yml anymore to avoid inconsistent behavior or unexpected course runs.
- More details on the implications of schema validations can be found here: [docs/changelog_details/schema_validation.md](/docs/changelog_details/schema_validation.md).
- As a part of defining a strict schema for course YAMLs, you will need to house any "reuable" YAML blocks in the top-level-key of `_references: {}`.

### Fixes
- Fixed the references for values to be relative: `files: []` now are referenced relative to the course yaml you're running. Also added end-to-end test for values files in subfolders.

## [2.0.0]
### Breaking Changes
- Changes to `values: {}` behavior:
Expand Down
2 changes: 2 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
include reckoner/assets/course.schema.json
include reckoner/version.txt
219 changes: 4 additions & 215 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,6 @@ Via Binary: *preferred method*
* Binary downloads of the Reckoner client can be found on the [Releases](https://github.com/FairwindsOps/reckoner/releases) page.
* Unpack the binary, `chmod +x`, add it to your PATH, and you are good to go!

Via pip:
**NOTE: Python2 pip will install a deprecated version of reckoner, Reckoner now requires python3.**
```shell
pip install reckoner
```

Via Git
```shell
pip install git+https://github.com/FairwindsOps/reckoner@master
```

For development see [CONTRIBUTING.md](./CONTRIBUTING.md).

## Quickstart
Expand All @@ -50,215 +39,15 @@ charts:
```
Then run:
```bash
```shell
reckoner plot course.yaml
```

Grafana and Polaris should now be installed on your cluster!

## Extended Usage

### As standalone shell command
- Usage: reckoner [OPTIONS] COMMAND [ARGS]...
- Options:
* `--help` Show this message and exit.
* `--log-level=TEXT` Set the log level for reckoner (defaults to `INFO`. Set to `DEBUG` for more details including helm commands)
- Commands:
* `plot FILE`: Runs helm based on specified yaml file (see configuration example below)
* Options:
* `--debug`: Pass --debug to helm
* `--dry-run`: Pass --dry-run to helm so no action is taken. Also includes `--debug`
* `--heading <chart>`: Run only the specified chart out of the course.yml
* `--continue-on-error`: If any charts or hooks fail, continue installing other charts in the course
* `--helm-args <helm-arg>`: Pass arbitrary flags and parameters to all
helm chart commands in your course.yml. Example:
`--helm-args --set=foo=toast`, or `--helm-args --recreate-pods`.
Multiples are supported but only one parameter per `--helm-args` is
supported. Note that specifying this flag will override `helm_args`
in the course.yml file.
* `version`: Output reckoner version

# Options

## Global Options

### namespace

The default namespace to deploy into. Defaults to kube-system

### repository

Repository to download chart from, defaults to 'stable'

### context

Optional. The kubectl cluster context to use for installing, defaults to the current context.

### repositories

Where to get charts from. We recommend at least the stable and incubator charts.

```
repositories:
incubator:
url: https://kubernetes-charts-incubator.storage.googleapis.com
stable:
url: https://kubernetes-charts.storage.googleapis.com
```

### helm_args

A list of arguments to pass to helm each time reckoner is run. Arguments are
applied for every chart install in your course. This cannot be used for args
that specify how Helm connects to the tiller.

```
helm_args:
- --recreate-pods
```

## Options for Charts

### values

Override values file for this chart. By default these are translated into `-f temp_values_file.yml` when helm is run. This means that anything in the `values: {}` settings should keep it's YAML type consistency.

```yaml
charts:
my-chart:
values:
my-string: "1234"
my-bool: false
```
### set-values
In-line values overrides for this chart. By default these are translated into `--set key=value` which means that the default helm type casting applies. Helm will try to cast `key: "true"` into a `true` boolean value, as well as casting strings of integers into the integer representation, ie: `mystr: "1234"` becomes `mystr: 1234` when using `--set`.

```yaml
charts:
my-chart:
my-int: "1234" # Converted into `int` when used with --set
my-string: 1.05 # Float numbers are converted to strings in --set
my-bool: "true" # Strings of bool values are converted to bool in --set
my-string-null: "null" # String of "null" get converted to null value in --set
my-null: null # null values are kept as null values in --set-strings
```
### values-strings
This is a wrapper around the helm functionality `--set-string`. Allows the specification of variables that would normally be interpreted as boolean or int as strings.

```
charts:
chartname:
values:
some.value: test
values-strings:
some.value.that.you.need.to.be.a.string: "1"
```
### files
Use a values file(s) rather than leaving them in-line:
```
charts:
chart_name:
files:
- /path/to/values/file.yml
```
Note: The file paths will be interpreted as relative to the working directory of
the shell calling reckoner.
### namespace
Override the default namespace.
### hooks
Hooks are run locally. For complex hooks, use an external script or Runner task.
```
charts:
chart_name:
hooks:
pre_install:
- ls
- env
post_install:
- rm testfile
- cp file1 file2
```
### version
The version of the chart to use
### plugin
A helm wrapper plugin to invoke for this chart.
Make sure that the plugin is installed in your environment, and is working properly.
Unfortunately, we cannot support every plugin.
```
charts:
chart_name:
plugin: secrets
files:
- /path/to/secret/values/file.yaml
```
## Repository Options
### name
Optional, name of repository.
### url
Optional if repository is listed above. Url of repository to add if not already included in above repositories section.
### git
Git url where chart exists. Supercedes url argument
### path
Path where chart is in the git repository. NOTE: If the chart folder is in the root, leave this blank.
```
charts:
chart_name:
repository: repository to download chart from, overrides global value
name: Optional, name of repository.
url: Optional if repository is listed above. Url of repository to add if not already included in above repositories section
git: Git url where chart exists. Supercedes url argument
path: Path where chart is in git repository. If the chart is at the root, leave blank
namespace: namespace to install chart in, overrides above value
```
## Caveats
### Strong Typing
Using `set-values: {}` will cast null, bool and integers from strings even if they are quoted in the course.yml. This is the default Helm behavior for `--set`. Note also that floats will be cast as strings when using `set-values: {}`. Also note that if you're using environment variable replacements and you set `my-key: ${MY_VAR}`, if `MY_VAR=yes` then helm will use YAML 1.1 schema and make `my-key: true`. You need to quote your environment variables in order for `"yes"` to be cast as a string instead of a bool (`my-key: "${MY_VAR}"`).
### Escaping
Keys and Values that have dots in the name need to be escaped. Have a look at the [helm docs](https://github.com/kubernetes/helm/blob/master/docs/using_helm.md#the-format-and-limitations-of---set) on escaping complicated values.
Example:
```
charts:
grafana:
namespace: grafana
values:
datasources:
datasources\.yaml:
apiVersion: 1
```
The alternative is to use the files method described above
## More Documentation
More advanced usage docs and course definition information can be found in the [docs/](/docs) folder of this repository.

## Contributing
* [Code of Conduct](CODE_OF_CONDUCT.md)
Expand Down
2 changes: 1 addition & 1 deletion development-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pytest
pytest==5.0.1
pytest-cov
wheel
mock
Expand Down
Loading

0 comments on commit 591b09b

Please sign in to comment.