Giter Site home page Giter Site logo

karuppiah7890 / helm-schema-gen Goto Github PK

View Code? Open in Web Editor NEW
128.0 4.0 60.0 64 KB

So that you don't have to write values.schema.json by hand from scratch for your Helm 3 charts. [CURRENTLY NOT MAINTAINED]

License: MIT License

Go 12.90% Shell 87.10%
helm-plugin helm golang plugin hacktoberfest json-schema helm-schema-gen k8s go

helm-schema-gen's Introduction

helm schema gen plugin [ CURRENTLY NOT MAINTAINED ]

So that you don't have to write values.schema.json by hand from scratch for your Helm 3 charts

Helm plugin to generate JSON Schema for values yaml

Note about maintenance

I currently don't have the bandwidth to reply to issues, write code and review PRs. For now I recommend forking the repo and making changes and using the fork πŸ˜…

Code stuff

Nothing fancy about the code, all the heavy lifting is done by:

Install

The plugin works with both Helm v2 and v3 versions as it's agnostic to the Helm binary version

$ helm plugin install https://github.com/karuppiah7890/helm-schema-gen.git
karuppiah7890/helm-schema-gen info checking GitHub for tag '0.0.4'
karuppiah7890/helm-schema-gen info found version: 0.0.4 for 0.0.4/Darwin/x86_64
karuppiah7890/helm-schema-gen info installed ./bin/helm-schema-gen
Installed plugin: schema-gen

But note that the schema feature is present only in Helm v3 charts, so Helm chart still has to be v3, meaning - based on the Helm chart v3 spec. And the schema validation is only done in Helm v3. Read more in the Schema Files section of the Helm official docs.

Usage

The plugin works with both Helm v2 and v3 versions

Let's take a sample values.yaml like the below

replicaCount: 1

image:
  repository: nginx
  pullPolicy: IfNotPresent

imagePullSecrets: []
nameOverride: ""
fullnameOverride: ""

serviceAccount:
  # Specifies whether a service account should be created
  create: true
  # The name of the service account to use.
  # If not set and create is true, a name is generated using the fullname template
  name:

podSecurityContext: {}
  # fsGroup: 2000

securityContext: {}
  # capabilities:
  #   drop:
  #   - ALL
  # readOnlyRootFilesystem: true
  # runAsNonRoot: true
  # runAsUser: 1000

service:
  type: ClusterIP
  port: 80

ingress:
  enabled: false
  annotations: {}
    # kubernetes.io/ingress.class: nginx
    # kubernetes.io/tls-acme: "true"
  hosts:
    - host: chart-example.local
      paths: []
  tls: []
  #  - secretName: chart-example-tls
  #    hosts:
  #      - chart-example.local

resources: {}
  # We usually recommend not to specify default resources and to leave this as a conscious
  # choice for the user. This also increases chances charts run on environments with little
  # resources, such as Minikube. If you do want to specify resources, uncomment the following
  # lines, adjust them as necessary, and remove the curly braces after 'resources:'.
  # limits:
  #   cpu: 100m
  #   memory: 128Mi
  # requests:
  #   cpu: 100m
  #   memory: 128Mi

nodeSelector: {}

tolerations: []

affinity: {}

Now if you use the plugin and pass the values.yaml to it, you will get the JSON Schema for the values.yaml

$ helm schema-gen values.yaml
{
    "$schema": "http://json-schema.org/schema#",
    "type": "object",
    "properties": {
        "affinity": {
            "type": "object"
        },
        "fullnameOverride": {
            "type": "string"
        },
        "image": {
            "type": "object",
            "properties": {
                "pullPolicy": {
                    "type": "string"
                },
                "repository": {
                    "type": "string"
                }
            }
        },
        "imagePullSecrets": {
            "type": "array"
        },
        "ingress": {
            "type": "object",
            "properties": {
                "annotations": {
                    "type": "object"
                },
                "enabled": {
                    "type": "boolean"
                },
                "hosts": {
                    "type": "array",
                    "items": {
                        "type": "object",
                        "properties": {
                            "host": {
                                "type": "string"
                            },
                            "paths": {
                                "type": "array"
                            }
                        }
                    }
                },
                "tls": {
                    "type": "array"
                }
            }
        },
        "nameOverride": {
            "type": "string"
        },
        "nodeSelector": {
            "type": "object"
        },
        "podSecurityContext": {
            "type": "object"
        },
        "replicaCount": {
            "type": "integer"
        },
        "resources": {
            "type": "object"
        },
        "securityContext": {
            "type": "object"
        },
        "service": {
            "type": "object",
            "properties": {
                "port": {
                    "type": "integer"
                },
                "type": {
                    "type": "string"
                }
            }
        },
        "serviceAccount": {
            "type": "object",
            "properties": {
                "create": {
                    "type": "boolean"
                },
                "name": {
                    "type": "null"
                }
            }
        },
        "tolerations": {
            "type": "array"
        }
    }
}

You can save it to a file like this

$ helm schema-gen values.yaml > values.schema.json

Issues? Feature Requests? Proposals? Feedback?

Note: I currently don't have the bandwidth to reply to issues, write code and review PRs. For now I recommend forking the repo and making changes and using the fork πŸ˜…

Put them all in GitHub issues 😁 I value every feedback. I really want to make sure that my tools help people and does not annoy people. I want my tools to enable people and not hinder them. I'll do my best to help you if you face any hindrance because of using my tools! :)

helm-schema-gen's People

Contributors

karuppiah7890 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

helm-schema-gen's Issues

[BUG] Plugin install fails with error: "karuppiah7890/helm-schema-gen crit platform windows/amd64 is not supported"

When I attempt to install the plugin (using GitBash) it fails and says it doesn't work on Windows.

Command Run:
helm plugin install https://github.com/karuppiah7890/helm-schema-gen

Error:

karuppiah7890/helm-schema-gen crit platform windows/amd64 is not supported.  Make sure this script is up-to-date and file request at https://github.com/karuppiah7890/helm-schema-gen/issues/new
Error: plugin install hook for "schema-gen" exited with error

Plugin doesn't install on Windows OS

I am trying on Windows laptop with WSL2 and without WSL2 , plugin fails to install with below error
Error: exec: "sh": executable file not found in %PATH%

Add parameter to output stricter schema

I would like to have the ability to run the tool and get a schema that already has "additionalProperties": false, defined for all objects. In this case, I can run helm lint against various values files and already see it failing.

helm schema-gen --strict values.yaml

Get rid of cobra for CLI work

I realized that cobra might be a little too much for the set of features I want to use. I think something lighter than cobra could do the work.

Actually I'm just showing help, and running the command. I'm not even having any flags to parse. And flag parsing can be done with standard library too. And I have only one command, no sub commands etc.

I just liked the way cobra showed the help and stuff though. It was one reason why I didn't use other CLI frameworks. But I didn't realize that we almost don't need a framework. Almost. Framework is probably just too much and is just going put a lot of weight on the binary size.

The two options are -

  • Checkout no framework and write plain code
  • Use a very very light framework for just the work that's needed to be done

Goal:

  • Use something lighter and simple
  • Make the binary size smaller

Profile and check performance

This is a very small tool, yes. I still want to check how much CPU and RAM it uses. I strongly believe that any software should try to optimize the usage of resources so that user's resources are not hogged :)

values.yaml annotations for regenerating values.schema.json

We have a few quite long values.yaml files, and they are constantly growing.

Unfortunately the current workflow supports only the initial creation of values.schema.json, but not its incremental updating.

Also many values are empty in values.yaml and are only set in accompanying values-<env>.yaml files which contain sensitive information and environment specific concrete values. Hence the type of these values is not derivable from values.yaml.

It would also be very helpful if the value constraints like e.g. enum, minimum or regex would also be reflected in values.yaml because it's cumbersome to find them in the very long values.schema.json file.

My proposal is to add (optional) comment line(s) with type annotations in values.yaml before each value line.
When generating values.schema.json from values.yaml these type annotation would then be used to refine the derived types (and to check for inconsistencies).

The syntax for the annotations should be succinct. Obvious and hence redundant information should be ommited, e.g. "type": "object" if there are child values, also derivable types like "string", "integer" of "boolean".
Also meaningful defaults should be used, e.g. all parent values should be considered as required by default. Only if the parent itself is optional this should be annotated.
In short only the manual changes necessary to the now generated values.schema.json file should be annotated.

To promote the adoption this approach it would also be helpful if there was a tool to create a new version of the existing values.yaml file by adding/updating these annotation comment lines based on the (manually edited) information in values.schema.json.

Thank you in advance

[feature request] offline installation

how can this repo being installed in disconnected environment?

issue

helm plugin install does not work if the repository is proxied.

$ helm plugin install <the-new-link>
karuppiah7890/helm-schema-gen info checking GitHub for tag '0.0.4'
karuppiah7890/helm-schema-gen crit unable to find '0.0.4' - use 'latest' or see https://github.com/karuppiah7890/helm-schema-gen/relea
ses for details
Error: plugin install hook for "schema-gen" exited with error

steps to reproduce

  • proxy the git repo
  • run helm plugin install http://the.new.link/after/proxy

Create schema from multiple files

Not all values are written out in values.yaml but most of them are commented. A good practise is to create test cases with various values. Therefore a good option to get a more complete schema would to combine all the value files and generate the schema based on those.

We have the following files in our helm charts:

./values.yaml
./ci/test-values.yaml
./ci/some-test-case.yaml

Merge files and create a schema from merged file.

This can already be achieved via yq merge but would be good to have built-in.

Expand Standard Values

A lot of helm charts follow standard values. Fields like serviceAccount, image, resources, etc...

It'd be cool if, either via a comment like # $type: resources, or just smart detection, schema gen could "fill-in" the schema for standard fields.

So resources would from

        "resources": {
            "type": "object"
        },

to

              "resources": {
                "description": "ResourceRequirements describes the compute resource requirements.",
                "properties": {
                  "limits": {
                    "additionalProperties": {
                      "oneOf": [
                        {
                          "type": [
                            "string",
                            "null"
                          ]
                        },
                        {
                          "type": [
                            "number",
                            "null"
                          ]
                        }
                      ]
                    },
                    "description": "Limits describes the maximum amount of compute resources allowed. More info: https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/",
                    "type": [
                      "object",
                      "null"
                    ]
                  },
                  "requests": {
                    "additionalProperties": {
                      "oneOf": [
                        {
                          "type": [
                            "string",
                            "null"
                          ]
                        },
                        {
                          "type": [
                            "number",
                            "null"
                          ]
                        }
                      ]
                    },
                    "description": "Requests describes the minimum amount of compute resources required. If Requests is omitted for a container, it defaults to Limits if that is explicitly specified, otherwise to an implementation-defined value. More info: https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/",
                    "type": [
                      "object",
                      "null"
                    ]
                  }
                },
                "type": [
                  "object",
                  "null"
                ]
              },

Could possibly use https://github.com/instrumenta/kubernetes-json-schema as an update to date src for these fields.

Helm plugin install README instruction issue

#5 mentions an issue in the README and suggests an addition of ".git" at the end of the repo URL for the installation to be successful.

Action: Check the Helm install instruction present in the README with Helm v3 latest version and also v3 older versions and also v2 latest version. It's not necessary to check v2 older versions as however v2 support is going away / gone. So, if it does not work with old v2 version, it's okay.

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.