Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: dadav/helm-schema
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 0.14.0
Choose a base ref
...
head repository: dadav/helm-schema
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: main
Choose a head ref

Commits on Sep 22, 2024

  1. Copy the full SHA
    04d13b3 View commit details
  2. chore: version++

    dadav committed Sep 22, 2024
    Copy the full SHA
    93475ad View commit details
  3. chore: version++

    dadav committed Sep 22, 2024
    Copy the full SHA
    fcb0a0b View commit details

Commits on Sep 23, 2024

  1. docs: Typo

    dadav committed Sep 23, 2024
    Copy the full SHA
    1368290 View commit details

Commits on Nov 5, 2024

  1. feat: Distribute as helm plugin

    Signed-off-by: Amine Benseddik <amine.benseddik@gmail.com>
    amine7536 committed Nov 5, 2024
    Copy the full SHA
    8304281 View commit details

Commits on Nov 26, 2024

  1. Fix ref unmarshal into BoolOrArrayOfString

    If a $ref has an object that declares `required` properties, helm-schema
    will return the error
    
    ```
    json: cannot unmarshal array into Go struct field
    Schema.properties.required of type schema.BoolOrArrayOfString
    ```
    
    Example:
    
    ```
    {
      "bar": {
        "type": "object",
        "description": "from ref",
        "properties": {
          "baz": {
            "type": "string",
            "description": "from ref"
          }
        },
        "required": [
          "baz"
        ]
      }
    }
    ```
    
    Another option is setting `required` to `false`.  Both cases cause the
    above error.
    
    The fix is to implement UnmarshalJSON on BoolOrArrayOfString.
    linux2647 committed Nov 26, 2024
    Copy the full SHA
    507df2d View commit details

Commits on Dec 6, 2024

  1. Merge pull request #77 from amine7536/feat-helm-plugin

    feat: Distribute as helm plugin
    dadav authored Dec 6, 2024
    Copy the full SHA
    e49f5a8 View commit details
  2. Merge pull request #79 from linux2647/fix-unmarshal-bool-or-array-of-…

    …string
    
    Fix ref unmarshal into BoolOrArrayOfString
    dadav authored Dec 6, 2024
    Copy the full SHA
    018cc56 View commit details
  3. fix: Format code

    dadav committed Dec 6, 2024
    Copy the full SHA
    68f7d41 View commit details
  4. fix: Use single lines

    dadav committed Dec 6, 2024
    Copy the full SHA
    ca94db2 View commit details
  5. Add renovate.json

    renovate[bot] authored Dec 6, 2024
    Copy the full SHA
    ac8f237 View commit details
  6. Merge pull request #81 from dadav/renovate/configure

    chore: Configure Renovate
    dadav authored Dec 6, 2024
    Copy the full SHA
    6253762 View commit details
  7. Copy the full SHA
    c55b97d View commit details
  8. Copy the full SHA
    8e69748 View commit details
  9. Merge branch 'fix_cleanup'

    dadav committed Dec 6, 2024
    Copy the full SHA
    f510f35 View commit details
  10. Copy the full SHA
    38dd082 View commit details
  11. Copy the full SHA
    2bbfae0 View commit details
  12. Copy the full SHA
    e039f9f View commit details
  13. Copy the full SHA
    3b7cac3 View commit details
  14. Copy the full SHA
    1b1d047 View commit details
  15. Merge pull request #88 from dadav/renovate/goreleaser-goreleaser-acti…

    …on-6.x
    
    chore(deps): update goreleaser/goreleaser-action action to v6
    dadav authored Dec 6, 2024
    Copy the full SHA
    289edcc View commit details
  16. Merge pull request #82 from dadav/renovate/github.com-masterminds-sem…

    …ver-v3-3.x
    
    fix(deps): update module github.com/masterminds/semver/v3 to v3.3.1
    dadav authored Dec 6, 2024
    Copy the full SHA
    9d57941 View commit details
  17. Merge pull request #87 from dadav/renovate/actions-setup-go-5.x

    chore(deps): update actions/setup-go action to v5
    dadav authored Dec 6, 2024
    Copy the full SHA
    f6523a4 View commit details
  18. Merge pull request #86 from dadav/renovate/actions-checkout-4.x

    chore(deps): update actions/checkout action to v4
    dadav authored Dec 6, 2024
    Copy the full SHA
    084e7f7 View commit details
  19. Merge pull request #85 from dadav/renovate/github.com-deckarep-golang…

    …-set-v2-2.x
    
    fix(deps): update module github.com/deckarep/golang-set/v2 to v2.7.0
    dadav authored Dec 6, 2024
    Copy the full SHA
    274e3fc View commit details
  20. Merge pull request #83 from dadav/renovate/alpine-3.x

    chore(deps): update alpine docker tag to v3.21
    dadav authored Dec 6, 2024
    Copy the full SHA
    810e6e0 View commit details
  21. Merge pull request #89 from dadav/renovate/github.com-santhosh-tekuri…

    …-jsonschema-v5-6.x
    
    fix(deps): update module github.com/santhosh-tekuri/jsonschema/v5 to v6
    dadav authored Dec 6, 2024
    Copy the full SHA
    1d67e8f View commit details
  22. chore: Adjust renovate config

    dadav committed Dec 6, 2024
    Copy the full SHA
    cdd2c8d View commit details

Commits on Dec 7, 2024

  1. Copy the full SHA
    8160cd5 View commit details
  2. Copy the full SHA
    b3b06fd View commit details
  3. Merge pull request #90 from dadav/renovate/github.com-magiconair-prop…

    …erties-1.x
    
    fix(deps): update module github.com/magiconair/properties to v1.8.8
    dadav authored Dec 7, 2024
    Copy the full SHA
    e6d6416 View commit details
  4. Copy the full SHA
    3f28428 View commit details
  5. Copy the full SHA
    21ff86a View commit details
  6. Merge pull request #91 from dadav/feat/add_minmax

    Feat/add minmax
    dadav authored Dec 7, 2024
    Copy the full SHA
    c4dd6e5 View commit details
  7. chore: Version++

    dadav committed Dec 7, 2024
    Copy the full SHA
    0d38eb8 View commit details

Commits on Dec 9, 2024

  1. Copy the full SHA
    ce8ed02 View commit details
  2. Copy the full SHA
    7c69bb3 View commit details
  3. Merge pull request #93 from dadav/renovate/github.com-magiconair-prop…

    …erties-1.x
    
    fix(deps): update module github.com/magiconair/properties to v1.8.9
    dadav authored Dec 9, 2024
    Copy the full SHA
    005349f View commit details
  4. Merge pull request #92 from dadav/renovate/pin-dependencies

    chore(deps): pin dependencies
    dadav authored Dec 9, 2024
    Copy the full SHA
    4968e43 View commit details
  5. Copy the full SHA
    8a3e773 View commit details
  6. Merge pull request #94 from dadav/feat/helm_docs_parsing

    feat: Add helm-docs compatibility mode
    dadav authored Dec 9, 2024
    Copy the full SHA
    c63ec14 View commit details

Commits on Dec 10, 2024

  1. chore: version++

    dadav committed Dec 10, 2024
    Copy the full SHA
    c6ee76c View commit details
  2. feat: Support yaml anchors

    dadav committed Dec 10, 2024
    Copy the full SHA
    5593ea2 View commit details
  3. chore: version++

    dadav committed Dec 10, 2024
    Copy the full SHA
    1b05e03 View commit details

Commits on Dec 11, 2024

  1. Copy the full SHA
    f61a2ca View commit details
  2. Copy the full SHA
    147d4ee View commit details
  3. Merge pull request #95 from dadav/renovate/actions-setup-go-digest

    chore(deps): update actions/setup-go digest to 3041bf5
    dadav authored Dec 11, 2024
    Copy the full SHA
    98b4f86 View commit details

Commits on Dec 18, 2024

  1. Copy the full SHA
    5ce2d9c View commit details
  2. Merge pull request #98 from dadav/feat/select_deps

    feat: Add dependency filter functionality
    dadav authored Dec 18, 2024
    Copy the full SHA
    2089934 View commit details
  3. chore(deps): bump golang.org/x/crypto from 0.21.0 to 0.31.0

    Bumps [golang.org/x/crypto](https://github.com/golang/crypto) from 0.21.0 to 0.31.0.
    - [Commits](golang/crypto@v0.21.0...v0.31.0)
    
    ---
    updated-dependencies:
    - dependency-name: golang.org/x/crypto
      dependency-type: indirect
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    dependabot[bot] authored Dec 18, 2024
    Copy the full SHA
    2533693 View commit details
12 changes: 6 additions & 6 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
@@ -8,21 +8,21 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v4
uses: actions/setup-go@f111f3307d8850f501ac008e886eec1fd1932a34 # v5
with:
go-version: ^1.21
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v4
uses: goreleaser/goreleaser-action@9ed2f89a662bf1735a48bc8557fd212fa902bebf # v6
with:
distribution: goreleaser
version: latest
args: release --snapshot --clean
- name: Upload result
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4
with:
name: helm-schema-tarball
path: dist/helm-schema_*-next_Linux_x86_64.tar.gz
@@ -31,11 +31,11 @@ jobs:
needs: goreleaser
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
with:
fetch-depth: 0
- name: Download helm-schema
uses: actions/download-artifact@v4
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4
with:
name: helm-schema-tarball
- shell: bash
8 changes: 4 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -15,20 +15,20 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v4
uses: actions/setup-go@f111f3307d8850f501ac008e886eec1fd1932a34 # v5
with:
go-version: ^1.21
- uses: docker/login-action@v3
- uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v4
uses: goreleaser/goreleaser-action@9ed2f89a662bf1735a48bc8557fd212fa902bebf # v6
with:
distribution: goreleaser
version: latest
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
repos:
- repo: https://github.com/dadav/helm-schema
rev: 0.13.1
rev: 0.18.1
hooks:
- id: helm-schema
# for all available options: helm-schema -h
8 changes: 8 additions & 0 deletions .pre-commit-hooks.yaml
Original file line number Diff line number Diff line change
@@ -6,3 +6,11 @@
language: golang
name: Generate jsonschema
require_serial: true
- id: helm-schema-container
args: []
description: Uses the container image of 'helm-schema' to create schema from the Helm chart's 'values.yaml' file, and inserts the result into a corresponding 'values.schema.json' file.
entry: ghcr.io/dadav/helm-schema:latest
files: values.yaml
language: docker_image
name: Helm Schema Container
require_serial: true
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
FROM alpine:3.20
FROM alpine:3.21@sha256:56fa17d2a7e7f168a043a2712e63aed1f8543aeafdcee47c58dcffe38ed51099
RUN adduser -k /dev/null -u 10001 -D helm-schema \
&& chgrp 0 /home/helm-schema \
&& chmod -R g+rwX /home/helm-schema
COPY helm-schema /
USER 10001
VOLUME [ "/home/helm-schema" ]
WORKDIR /home/helm-schema
ENTRYPOINT ["/helm-schema"]
43 changes: 41 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -42,6 +42,12 @@ Via `podman/docker`:
podman run --rm -v $PWD:/home/helm-schema ghcr.io/dadav/helm-schema:latest
```

As `helm plugin`:

```sh
helm plugin install https://github.com/dadav/helm-schema
```

## Usage

### Pre-commit hook
@@ -73,10 +79,13 @@ The binary has the following options:
```sh
Flags:
-r, --add-schema-reference "add reference to schema in values.yaml if not found"
-a, --append-newline append newline to generated jsonschema at the end of the file
-a, --append-newline "append newline to generated jsonschema at the end of the file"
-c, --chart-search-root string "directory to search recursively within for charts (default ".")"
-i, --dependencies-filter strings "only generate schema for specified dependencies (comma-separated list of dependency names)"
-g, --dont-add-global "dont auto add global property"
-x, --dont-strip-helm-docs-prefix "disable the removal of the helm-docs prefix (--)"
-d, --dry-run "don't actually create files just print to stdout passed"
-p, --helm-docs-compatibility-mode "parse and use helm-docs comments"
-h, --help "help for helm-schema"
-s, --keep-full-comment "keep the whole leading comment (default: cut at empty line)"
-l, --log-level string "level of logs that should printed, one of (panic, fatal, error, warning, info, debug, trace) (default "info")"
@@ -136,9 +145,11 @@ foo: bar
| [`allOf`](#allof) | Accepts an array of schemas. All must apply| Takes an `array` |
| [`not`](#not) | A schema that must not be matched. | Takes an `object` |
| [`if/then/else`](#ifthenelse) | `if` the given schema applies, `then` also apply the given schema or `else` the other schema| Takes an `object` |
| [`$ref`](#ref) | Accepts a URI to a valid `jsonschema`. Extend the schema for the current key | Takes an URI (or relative file) |
| [`$ref`](#ref) | Accepts an URI to a valid `jsonschema`. Extend the schema for the current key | Takes an URI (or relative file) |
| [`minLength`](#minlength) | Minimum string length. | Takes an `integer`. Must be smaller or equal than `maxLength` (if used) |
| [`maxLength`](#maxlength) | Maximum string length. | Takes an `integer`. Must be greater or equal than `minLength` (if used) |
| [`minItems`](#minItems) | Minimum length of an array. | Takes an `integer`. Must be smaller or equal than `maxItems` (if used) |
| [`maxItems`](#maxItems) | Maximum length of an array. | Takes an `integer`. Must be greater or equal than `minItems` (if used) |

## Validation & completion

@@ -180,6 +191,9 @@ If not provided, `title` will be the key and the `description` will be parsed fr
foo: []
```

If you use `-p`/`--helm-docs-compatibility-mode` flags, the `@default`, `(type)` annotations and helm-docs descriptions
are used if detected.

> [!NOTE]
> Make sure to place the `@schema` annotations **before** the actual key description to avoid having it in your `helm-docs` generated table

@@ -710,6 +724,31 @@ The value must be an integer greater than zero and defines the maximum length of
namespace: foo
```

#### `minItems`

The value must be an integer greater than zero and defines the minimum length of an array value.

```yaml
# @schema
# minItems: 1
# @schema
namespace:
- foo
```

#### `maxItems`

The value must be an integer greater than zero and defines the maximum length of an array value.

```yaml
# @schema
# maxItems: 2
# @schema
namespace:
- foo
- bar
```

#### `$ref`

The value must be an URI or relative file.
6 changes: 6 additions & 0 deletions cmd/helm-schema/cli.go
Original file line number Diff line number Diff line change
@@ -56,6 +56,8 @@ func newCommand(run func(cmd *cobra.Command, args []string) error) (*cobra.Comma
BoolP("keep-full-comment", "s", false, "keep the whole leading comment (default: cut at empty line)")
cmd.PersistentFlags().
BoolP("uncomment", "u", false, "consider yaml which is commented out")
cmd.PersistentFlags().
BoolP("helm-docs-compatibility-mode", "p", false, "parse and use helm-docs comments")
cmd.PersistentFlags().
BoolP("dont-strip-helm-docs-prefix", "x", false, "disable the removal of the helm-docs prefix (--)")
cmd.PersistentFlags().
@@ -69,6 +71,10 @@ func newCommand(run func(cmd *cobra.Command, args []string) error) (*cobra.Comma
StringP("output-file", "o", "values.schema.json", "jsonschema file path relative to each chart directory to which jsonschema will be written")
cmd.PersistentFlags().
StringSliceP("skip-auto-generation", "k", []string{}, "comma separated list of fields to skip from being created by default (possible: title, description, required, default, additionalProperties)")
cmd.PersistentFlags().
StringSliceP("dependencies-filter", "i", []string{}, "only generate schema for specified dependencies (comma-separated list of dependency names)")
cmd.PersistentFlags().
BoolP("dont-add-global", "g", false, "dont auto add global property")

viper.AutomaticEnv()
viper.SetEnvPrefix("HELM_SCHEMA")
66 changes: 48 additions & 18 deletions cmd/helm-schema/main.go
Original file line number Diff line number Diff line change
@@ -12,11 +12,13 @@ import (
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"gopkg.in/yaml.v3"

"github.com/dadav/helm-schema/pkg/chart"
"github.com/dadav/helm-schema/pkg/schema"
)

func searchFiles(startPath, fileName string, queue chan<- string, errs chan<- error) {
func searchFiles(chartSearchRoot, startPath, fileName string, dependenciesFilter map[string]bool, queue chan<- string, errs chan<- error) {
defer close(queue)
err := filepath.Walk(startPath, func(path string, info os.FileInfo, err error) error {
if err != nil {
@@ -25,7 +27,30 @@ func searchFiles(startPath, fileName string, queue chan<- string, errs chan<- er
}

if !info.IsDir() && info.Name() == fileName {
queue <- path
if filepath.Dir(path) == chartSearchRoot {
queue <- path
return nil
}

if len(dependenciesFilter) > 0 {
chartData, err := os.ReadFile(path)
if err != nil {
errs <- fmt.Errorf("failed to read Chart.yaml at %s: %w", path, err)
return nil
}

var chart chart.ChartFile
if err := yaml.Unmarshal(chartData, &chart); err != nil {
errs <- fmt.Errorf("failed to parse Chart.yaml at %s: %w", path, err)
return nil
}

if dependenciesFilter[chart.Name] {
queue <- path
}
} else {
queue <- path
}
}

return nil
@@ -45,10 +70,17 @@ func exec(cmd *cobra.Command, _ []string) error {
noDeps := viper.GetBool("no-dependencies")
addSchemaReference := viper.GetBool("add-schema-reference")
keepFullComment := viper.GetBool("keep-full-comment")
helmDocsCompatibilityMode := viper.GetBool("helm-docs-compatibility-mode")
uncomment := viper.GetBool("uncomment")
outFile := viper.GetString("output-file")
dontRemoveHelmDocsPrefix := viper.GetBool("dont-strip-helm-docs-prefix")
appendNewline := viper.GetBool("append-newline")
dependenciesFilter := viper.GetStringSlice("dependencies-filter")
dependenciesFilterMap := make(map[string]bool)
dontAddGlobal := viper.GetBool("dont-add-global")
for _, dep := range dependenciesFilter {
dependenciesFilterMap[dep] = true
}
if err := viper.UnmarshalKey("value-files", &valueFileNames); err != nil {
return err
}
@@ -62,16 +94,14 @@ func exec(cmd *cobra.Command, _ []string) error {
return err
}

// 1. Start a producer that searches Chart.yaml and values.yaml files
queue := make(chan string)
resultsChan := make(chan schema.Result)
results := []*schema.Result{}
errs := make(chan error)
done := make(chan struct{})

go searchFiles(chartSearchRoot, "Chart.yaml", queue, errs)
go searchFiles(chartSearchRoot, chartSearchRoot, "Chart.yaml", dependenciesFilterMap, queue, errs)

// 2. Start workers and every worker does:
wg := sync.WaitGroup{}
go func() {
wg.Wait()
@@ -88,7 +118,9 @@ func exec(cmd *cobra.Command, _ []string) error {
uncomment,
addSchemaReference,
keepFullComment,
helmDocsCompatibilityMode,
dontRemoveHelmDocsPrefix,
dontAddGlobal,
valueFileNames,
skipConfig,
outFile,
@@ -111,9 +143,7 @@ loop:
}
}

// sort results with topology sort (only if we're checking the dependencies)
if !noDeps {
// sort results with topology sort
results, err = schema.TopoSort(results)
if err != nil {
if _, ok := err.(*schema.CircularError); !ok {
@@ -126,16 +156,16 @@ loop:
}

conditionsToPatch := make(map[string][]string)
// Sort results if dependencies should be processed
// Need to resolve the dependencies from deepest level to highest

if !noDeps {
// Iterate over deps to find conditions we need to patch (dependencies that have a condition)
for _, result := range results {
if len(result.Errors) > 0 {
continue
}
for _, dep := range result.Chart.Dependencies {
if len(dependenciesFilterMap) > 0 && !dependenciesFilterMap[dep.Name] {
continue
}

if dep.Condition != "" {
conditionKeys := strings.Split(dep.Condition, ".")
conditionsToPatch[conditionKeys[0]] = conditionKeys[1:]
@@ -147,9 +177,7 @@ loop:
chartNameToResult := make(map[string]*schema.Result)
foundErrors := false

// process results
for _, result := range results {
// Error handling
if len(result.Errors) > 0 {
foundErrors = true
if result.Chart != nil {
@@ -170,7 +198,9 @@ loop:

log.Debugf("Processing result for chart: %s (%s)", result.Chart.Name, result.ChartPath)
if !noDeps {
// Patch condition into schema if needed
chartNameToResult[result.Chart.Name] = result
log.Debugf("Stored chart %s in chartNameToResult", result.Chart.Name)

if patch, ok := conditionsToPatch[result.Chart.Name]; ok {
schemaToPatch := &result.Schema
lastIndex := len(patch) - 1
@@ -198,6 +228,10 @@ loop:
}

for _, dep := range result.Chart.Dependencies {
if len(dependenciesFilterMap) > 0 && !dependenciesFilterMap[dep.Name] {
continue
}

if dep.Name != "" {
if dependencyResult, ok := chartNameToResult[dep.Name]; ok {
log.Debugf(
@@ -211,8 +245,6 @@ loop:
Description: dependencyResult.Chart.Description,
Properties: dependencyResult.Schema.Properties,
}
// you don't NEED to overwrite the values
// so every required check will be disabled
depSchema.DisableRequiredProperties()

if dep.Alias != "" {
@@ -228,10 +260,8 @@ loop:
log.Warnf("Dependency without name found (checkout %s).", result.ChartPath)
}
}
chartNameToResult[result.Chart.Name] = result
}

// Print to stdout or write to file
jsonStr, err := result.Schema.ToJson()
if err != nil {
log.Error(err)
2 changes: 1 addition & 1 deletion cmd/helm-schema/version.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package main

var version string = "0.14.0"
var version string = "0.18.1"
Loading