Code Monkey home page Code Monkey logo

helm-jsonschema-gen's Introduction

helm-jsonschema-gen

helm-jsonschema-gen is a cli tool and go libary for generating Helm values.schema.json, values.yaml and values.docs.yaml. It uses a source of truth that is written in go.

cert-manager example (example/values)

The go structs are defined in their corresponding go source files.

Below is a snippet of the main.go file that references the "root" object with the default values.

package main

import (
	"github.com/amurant/helm-jsonschema-gen/pkg/schema"
)

//go:generate go run github.com/amurant/helm-jsonschema-gen/cmd/jsonschema-gen -p .

func main() {	
	if err := schema.GenSchema(&defaultValues, "../values.schema.json"); err != nil {
		panic(err)
	}
	if err := schema.GenDefaults(&defaultValues, "../values.yaml"); err != nil {
		panic(err)
	}
	if err := schema.GenDocs(&defaultValues, "../values.docs.yaml"); err != nil {
		panic(err)
	}
}

var defaultValues = Values{
    ...
}

Using the following commands, we can now generate the values.schema.json, values.yaml and values.docs.yaml files.

$ cd example/values
$ go generate . && go run .

$ cat ../values.schema.json
{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "required": [
    "installCRDs",
    "replicaCount",
    "podLabels",
    "strategy",
    "nodeSelector",
    "affinity",
    "tolerations",
    "image",
    "resources",
...

$ cat ../values.yaml
affinity: {}
cainjector:
  affinity: {}
  containerSecurityContext: {}
  enabled: true
  extraArgs: []
  extraEnv: []
...

$ cat ../values.docs.yaml
- default: false
  path: installCRDs
  required: true
  type: boolean
- default: 1
  path: replicaCount
  required: true
  type: integer
- path: deploymentAnnotations
  required: false
  type: map[string]string
...

Generating markdown documentation

Use the tem tool.

$ cd example
$ tem -f valuesdocs=./values.docs.yaml -t docs.template.md
| command | type | description | default |
| ------- | ---- | ----------- | ------- |
| --set installCRDs | boolean | If true, CRD resources will be installed as part of the Helm chart. If enabled, when uninstalling CRD resources will be deleted causing all installed custom resources to be DELETED. | `false` |
| --set replicaCount | integer | Number of replicas | `1` |
| --set deploymentAnnotations | map[string]string | Annotations to add to the deployment | `` |
| --set podAnnotations | map[string]string | Annotations to add to the pods | `` |
| --set podLabels | map[string]string | Annotations to add to the pods | `` |
...

helm-jsonschema-gen's People

Contributors

inteon avatar

Forkers

ivyostosh

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.