helm-values-schema-json

command module
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 10, 2023 License: MIT Imports: 9 Imported by: 0

README

helm values schema json plugin

ci codecov Go Report Card Static Badge GitHub release (with filter)

Helm plugin for generating values.schema.json from single or multiple values files. Works only with Helm3 charts.

Install

$ helm plugin install https://github.com/losisin/helm-values-schema-json.git
Installed plugin: schema

Features

  • Add multiple values files and merge them together - required
  • Save output with custom name and location - default is values.schema.json in current working directory
  • Change schema draft version - default is draft 2020-12

Integrations

There are several ways to automate schema generation with this plugin. Main reason is that the json schema file can be hard to follow and we as humans tend to forget and update routine tasks. So why not automate it?

GitHub actions

There is GitHub action that I've build using typescript and published on marketplace. You can find it here. Basic usage is as follows:

name: Generate values schema json
on:
  - pull_request
jobs:
  generate:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v3
      with:
        ref: ${{ github.event.pull_request.head.ref }}
      - name: Generate values schema json
        uses: losisin/helm-values-schema-json-action@v1
        with:
          input: values.yaml
pre-commit hook

With pre-commit, you can ensure your JSON schema is kept up-to-date each time you make a commit.

First install pre-commit and then create or update a .pre-commit-config.yaml in the root of your Git repo with at least the following content:

repos:
  - repo: https://github.com/losisin/helm-values-schema-json
    rev: v0.2.0
    hooks:
      - id: helm-schema
        args: ["-input", "values.yaml"]

Then run:

pre-commit install
pre-commit install-hooks

Further changes to your chart files will cause an update to json schema when you make a commit.

Husky

This is a great tool for adding git hooks to your project. You can find it's documentation here. Here is how you can use it:

"husky": {
  "hooks": {
    "pre-commit": "helm schema -input values.yaml"
  }
},

Usage

$ helm schema -help
usage: helm schema [-input STR] [-draft INT] [-output STR]
  -draft int
    	Draft version (4, 6, 7, 2019, or 2020) (default 2020)
  -input value
    	Multiple yamlFiles as inputs (comma-separated)
  -output string
    	Output file path (default "values.schema.json")
Basic

In most cases you will want to run the plugin with default options:

$ helm schema -input values.yaml

This will read values.yaml, set draft version to 2020-12 and save outpout to values.schema.json.

Extended

Merge multiple values files, set json-schema draft version explicitly and save output to my.schema.json:

values_1.yaml

nodeSelector:
  kubernetes.io/hostname: ""
dummyList:
  - "a"
  - "b"
  - "c"
key1: "asd"
key2: 42
key3: {}
key4: []

custom/path/values_2.yaml

nodeSelector:
  kubernetes.io/hostname: "node1"
deep:
  deep1:
    deep2:
      deep3:
        deep4: "asdf"

Run the following command to merge the yaml files and output json schema:

$ helm schema -input values_1.yaml,custom/path/values_2.yaml -draft 7 -output my.schema.json

Output will be something like this:

{
    "$schema": "http://json-schema.org/draft-07/schema#",
    "type": "object",
    "properties": {
        "deep": {
            "type": "object",
            "properties": {
                "deep1": {
                    "type": "object",
                    "properties": {
                        "deep2": {
                            "type": "object",
                            "properties": {
                                "deep3": {
                                    "type": "object",
                                    "properties": {
                                        "deep4": {
                                            "type": "string"
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        },
        "dummyList": {
            "type": "array",
            "items": {
                "type": "string"
            }
        },
        "key1": {
            "type": "string"
        },
        "key2": {
            "type": "integer"
        },
        "key3": {
            "type": "object"
        },
        "key4": {
            "type": "array"
        },
        "nodeSelector": {
            "type": "object",
            "properties": {
                "kubernetes.io/hostname": {
                    "type": "string"
                }
            }
        }
    }
}

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL