From 811b0f994061f0813cb730d2f08326015dfee58b Mon Sep 17 00:00:00 2001 From: Aleksandar Stojanov Date: Tue, 24 Oct 2023 17:06:09 +0200 Subject: [PATCH 1/7] add README --- README.md | 123 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 123 insertions(+) diff --git a/README.md b/README.md index e69de29..0946adb 100644 --- a/README.md +++ b/README.md @@ -0,0 +1,123 @@ +# helm values schema json plugin + +Helm plugin for generating values.schema.json from 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 + +Given 2 yaml files in different locations: + +values_1.yaml + +``` +nodeSelector: + kubernetes.io/hostname: "" +dummyList: + - "a" + - "b" + - "c" +key1: "asd" +key2: 42 +key3: {} +key4: [] +``` + +dummy/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,dummy/path/values_2.yaml -draft 2020 -output values.schema.json +``` + +Output will be something like this: + +``` +{ + "$schema": "https://json-schema.org/draft/2020-12/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" + } + } + } + } +} +``` + +## Usage + +``` +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") +``` From 0981b37ce947246d6a4a245cac67b74ef3f5269f Mon Sep 17 00:00:00 2001 From: Aleksandar Stojanov Date: Tue, 24 Oct 2023 17:15:57 +0200 Subject: [PATCH 2/7] update docs --- README.md | 50 +++++++++++++++++++++++++++++++------------------- 1 file changed, 31 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 0946adb..ece94b2 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # helm values schema json plugin -Helm plugin for generating values.schema.json from multiple values files. Works only with Helm3 charts. +Helm plugin for generating `values.schema.json` from single or multiple values files. Works only with Helm3 charts. ## Install @@ -15,9 +15,33 @@ Installed plugin: schema - 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 -Given 2 yaml files in different locations: +## Usage + +``` +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 +``` -values_1.yaml +This will read `values.yaml`, set draft version to `202-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: @@ -32,7 +56,7 @@ key3: {} key4: [] ``` -dummy/path/values_2.yaml +`custom/path/values_2.yaml` ``` nodeSelector: @@ -47,14 +71,14 @@ deep: Run the following command to merge the yaml files and output json schema: ``` -helm schema -input values_1.yaml,dummy/path/values_2.yaml -draft 2020 -output values.schema.json +helm schema -input values_1.yaml,custom/path/values_2.yaml -draft 2020 -output my.schema.json ``` Output will be something like this: ``` { - "$schema": "https://json-schema.org/draft/2020-12/schema", + "$schema": "http://json-schema.org/draft-07/schema#", "type": "object", "properties": { "deep": { @@ -108,16 +132,4 @@ Output will be something like this: } } } -``` - -## Usage - -``` -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") -``` +``` \ No newline at end of file From b35f109dad59a8de8943f7dd9749ad7a0d2f886f Mon Sep 17 00:00:00 2001 From: Aleksandar Stojanov Date: Tue, 24 Oct 2023 17:17:17 +0200 Subject: [PATCH 3/7] fix typo --- README.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index ece94b2..6b0eb43 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,7 @@ Installed plugin: schema ## 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) @@ -32,10 +33,10 @@ usage: helm schema [-input STR] [-draft INT] [-output STR] In most cases you will want to run the plugin with default options: ``` -helm schema -input values.yaml +$ helm schema -input values.yaml ``` -This will read `values.yaml`, set draft version to `202-12` and save outpout to `values.schema.json`. +This will read `values.yaml`, set draft version to `2020-12` and save outpout to `values.schema.json`. #### Extended @@ -71,7 +72,7 @@ deep: 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 2020 -output my.schema.json +$ helm schema -input values_1.yaml,custom/path/values_2.yaml -draft 2020 -output my.schema.json ``` Output will be something like this: From 5a6edbec4a6b3bb439820f5179ae9ab8bff00f69 Mon Sep 17 00:00:00 2001 From: Aleksandar Stojanov Date: Tue, 24 Oct 2023 17:20:01 +0200 Subject: [PATCH 4/7] add ci workflow --- .github/workflows/ci.yaml | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 .github/workflows/ci.yaml diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..b07d131 --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,31 @@ +name: ci +on: + pull_request: + branches: + - master +jobs: + test: + name: Test + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest, macos-latest, windows-latest] + env: + VERBOSE: 1 + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: '1.20' + cache: false + - name: golangci-lint + uses: golangci/golangci-lint-action@v3 + args: --timeout 5m0s + - name: Run fmt + run: go fmt ./... + - name: Run vet + run: go vet ./... + - name: Run tests + run: go test -v ./... From 070961a5b028db0928b7b3c726e7ef08868b1448 Mon Sep 17 00:00:00 2001 From: Aleksandar Stojanov Date: Tue, 24 Oct 2023 17:23:43 +0200 Subject: [PATCH 5/7] fix ci workflow --- .github/workflows/ci.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index b07d131..7b0a969 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -22,6 +22,7 @@ jobs: cache: false - name: golangci-lint uses: golangci/golangci-lint-action@v3 + with: args: --timeout 5m0s - name: Run fmt run: go fmt ./... From 51ff81c6124f2e811ac539e31509afff71277184 Mon Sep 17 00:00:00 2001 From: Aleksandar Stojanov Date: Tue, 24 Oct 2023 17:30:50 +0200 Subject: [PATCH 6/7] add CODEOWNERS file --- CODEOWNERS | 1 + 1 file changed, 1 insertion(+) create mode 100644 CODEOWNERS diff --git a/CODEOWNERS b/CODEOWNERS new file mode 100644 index 0000000..acd83c5 --- /dev/null +++ b/CODEOWNERS @@ -0,0 +1 @@ +* @losisin From 7c78e92a052381616f5883f6651eeaaa0022a5d1 Mon Sep 17 00:00:00 2001 From: Aleksandar Stojanov Date: Tue, 24 Oct 2023 17:36:35 +0200 Subject: [PATCH 7/7] syntax highlighting Signed-off-by: Aleksandar Stojanov --- README.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 6b0eb43..c165bb6 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ Helm plugin for generating `values.schema.json` from single or multiple values f ## Install -``` +```bash $ helm plugin install https://github.com/losisin/helm-values-schema-json.git Installed plugin: schema ``` @@ -17,7 +17,7 @@ Installed plugin: schema ## Usage -``` +```bash $ helm schema -help usage: helm schema [-input STR] [-draft INT] [-output STR] -draft int @@ -28,23 +28,23 @@ usage: helm schema [-input STR] [-draft INT] [-output STR] Output file path (default "values.schema.json") ``` -#### Basic +### Basic In most cases you will want to run the plugin with default options: -``` +```bash $ helm schema -input values.yaml ``` This will read `values.yaml`, set draft version to `2020-12` and save outpout to `values.schema.json`. -#### Extended +### Extended Merge multiple values files, set json-schema draft version explicitly and save output to `my.schema.json`: `values_1.yaml` -``` +```yaml nodeSelector: kubernetes.io/hostname: "" dummyList: @@ -59,7 +59,7 @@ key4: [] `custom/path/values_2.yaml` -``` +```yaml nodeSelector: kubernetes.io/hostname: "node1" deep: @@ -71,13 +71,13 @@ deep: Run the following command to merge the yaml files and output json schema: -``` +```bash $ helm schema -input values_1.yaml,custom/path/values_2.yaml -draft 2020 -output my.schema.json ``` Output will be something like this: -``` +```json { "$schema": "http://json-schema.org/draft-07/schema#", "type": "object",