Skip to content

Commit

Permalink
Merge pull request #5 from buttahtoast/dev
Browse files Browse the repository at this point in the history
Improved Chart Metadata
  • Loading branch information
oliverbaehler authored Apr 16, 2022
2 parents c8f0740 + 5c93ca4 commit 40e5697
Show file tree
Hide file tree
Showing 31 changed files with 207 additions and 146 deletions.
9 changes: 5 additions & 4 deletions charts/helmize/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ apiVersion: v2
name: helmize
description: Go Sprig based deployment engine deployed via Helm
type: library
version: "0.1.0-rc.2"
version: "0.1.0-rc.3"
appVersion: "0.1.0"
home: https://buttahtoast.github.io/helmize/
icon: https://raw.githubusercontent.com/buttahtoast/helmize/main/icon.jpg
home: https://helmize.dev
icon: https://raw.githubusercontent.com/buttahtoast/helmize/main/icons/icon-transparent.png
dependencies:
- name: library
version: "2.2.2"
version: "2.2.3"
#repository: "file://../../../helm-charts-1/charts/library"
repository: https://buttahtoast.github.io/helm-charts/
keywords:
- library
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
9 changes: 1 addition & 8 deletions charts/helmize/templates/config/_types.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,13 @@
*/}}
{{- define "inventory.config.types.config" -}}
{{- include "inventory.dropins.defaults.tpls_dir" $ }}:
types: [ "string" ]
{{ include "inventory.conditions.defaults.inv_dir" $ }}:
types: [ "string" ]
{{ include "inventory.dropins.defaults.dropins" $ }}:
types: [ "slice" ]
{{ include "inventory.conditions.defaults.conditions" $ }}:
types: [ "slice" ]
{{ include "inventory.entrypoint.defaults.force" $ }}:
types: [ "bool", "int" ]
default: false
{{ include "inventory.render.defaults.file.merge_strategy" $ }}:
types: [ "string" ]
default: "path"
values: [ "file", "path" ]
{{ include "inventory.render.defaults.file.excludes" $ }}:
types: [ "string", "slice" ]
{{ include "inventory.render.defaults.file.extensions" $ }}:
Expand All @@ -30,4 +22,5 @@
{{ include "inventory.postrenders.defaults.cfg.post_renderers" $ }}:
types: [ "slice" ]
default: [ "{{ include "inventory.postrenders.defaults.cfg.post_renderers.inject_key" $ }}" ]
{{ include "inventory.render.types.file_configuration" $ }}
{{- end -}}
2 changes: 0 additions & 2 deletions charts/helmize/templates/entrypoint/func/_deploy.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
{{- define "inventory.entrypoint.func.deploy" -}}
{{/* Summary */}}
{{- $summary := (fromYaml (include "lib.utils.dicts.lookup" (dict "data" $.Values "path" (include "inventory.entrypoint.defaults.summary_value" $)))).res -}}
t: {{- toYaml $summary | nindent 2 -}}

{{- if $summary -}}
{{- include "inventory.entrypoint.func.summary" $ -}}
{{- else -}}
Expand Down
19 changes: 19 additions & 0 deletions charts/helmize/templates/render/_defaults.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,22 @@ no_match
multiple_filename_id
{{- end -}}


{{- define "inventory.render.defaults.file_cfg.expand" -}}
expand
{{- end -}}


{{- define "inventory.render.defaults.file_cfg.subpath" -}}
subpath
{{- end -}}


{{/* Pattern (File Configuration Type, Local) <Template>
IDs are used as Patterns to match against other ids. If Enabled the file won't be added if nothing matches.
*/}}
{{- define "inventory.render.defaults.file_cfg.pattern" -}}
pattern
{{- end -}}
9 changes: 9 additions & 0 deletions charts/helmize/templates/render/_types.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,13 @@
{{ include "inventory.render.defaults.file_cfg.multi_filename" $ }}:
types: [ "bool" ]
default: false
{{ include "inventory.render.defaults.file_cfg.subpath" $ }}:
types: [ "bool" ]
default: true
{{ include "inventory.render.defaults.file_cfg.expand" $ }}:
types: [ "bool" ]
default: false
{{ include "inventory.render.defaults.file_cfg.pattern" $ }}:
types: [ "bool" ]
default: false
{{- end -}}
3 changes: 2 additions & 1 deletion charts/helmize/templates/render/func/_get.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@
{{- else -}}
{{- include "lib.utils.errors.fail" (printf "Render Returned invalid YAML:\n%s" (toYaml $render_raw | nindent 2)) -}}
{{- end -}}
{{- end -}}
{{- end -}}

146 changes: 72 additions & 74 deletions charts/helmize/templates/render/func/_train.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
{{- $return := dict "files" list "errors" list "debug" list -}}

{{/* Variables */}}
{{- $file_train := dict -}}
{{- $file_train := list -}}
{{- $order := 0 -}}

{{/* Shared Data Over All Files */}}
Expand All @@ -26,31 +26,16 @@
{{- range $file := $.files -}}
{{- $train_file := dict "files" (list $file) "errors" list "debug" list -}}

{{/* Resolve Dropins for current path */}}
{{- $dropins_data := dict -}}
{{- $dropins := fromYaml (include "inventory.dropins.func.resolve" (dict "path" $file.file "ctx" $.ctx)) -}}
{{- if (not (include "lib.utils.errors.unmarshalingError" $dropins)) -}}

{{/* Redirect Errors */}}
{{- with $dropins.errors -}}
{{- $_ := set $train_file "errors" (concat $train_file.errors .) -}}
{{- end -}}

{{/* Redirect Data */}}
{{- with $dropins.data -}}
{{- $dropins_data = . -}}
{{- end -}}

{{- end -}}

{{/* Merge Data Store with Dropins */}}
{{- $data := mergeOverwrite $dropins_data $shared_data -}}
{{/* Merge Data Store */}}
{{- $data := $shared_data -}}

{{/* Parse file(s) */}}
{{- $train_file_contents_raw := include "inventory.render.func.files.parse" (dict "parse" ($file) "extra_ctx" $data "extra_ctx_key" "Data" "shared_data" $shared_data "ctx" $.ctx) -}}
{{- $train_file_contents := fromYaml ($train_file_contents_raw) -}}
{{- if (not (include "lib.utils.errors.unmarshalingError" $train_file_contents)) -}}

{{- $_ := set $return "debug" (append $return.debug $train_file_contents) -}}

{{/* Foreach resolved file */}}
{{- range $incoming_wagon := $train_file_contents.files -}}

Expand All @@ -61,75 +46,92 @@
{{- if $ids -}}

{{/* Match Config Control Variables */}}
{{- $matched := 1 -}}
{{- $matched := 0 -}}

{{/* Preserve Data for File (Post-Rendering) */}}
{{- $_ := set $incoming_wagon "data" (mergeOverwrite $data $shared_data) -}}

{{/* Add Current File as Files (Assign Order) */}}
{{- $_ := set $incoming_wagon "files" (list (set $file "_order" $order)) -}}

{{/* Debug */}}
{{- if (include "inventory.entrypoint.func.debug" $.ctx) -}}
{{- $_ := set $return "debug" (append $return.debug (dict "Source" $file.file "Manifest" $incoming_wagon "Dropins" $dropins)) -}}

{{/* Add Current File as Files (Assign Order) */}}
{{- $_ := set $incoming_wagon "files" (list (set (set $file "_order" $order) "config" $incoming_wagon.cfg)) -}}

{{- $_ := set $return "debug" (append $return.debug (dict "Source" $file.file "Manifest" $incoming_wagon)) -}}
{{- end -}}

{{/* Parse Content, if not map */}}
{{- if $incoming_wagon.content -}}
{{- if not (kindIs "map" $incoming_wagon.content) -}}
{{- $parsed_content := (fromYaml ($incoming_wagon.content)) -}}
{{- if (not (include "lib.utils.errors.unmarshalingError" $parsed_content)) -}}
{{- $_ := set $incoming_wagon "content" $parsed_content -}}
{{- else -}}
{{- $_ := set $return "errors" (append $return.errors (dict "file" $file.file "errors" "Content not YAML" "trace" ($incoming_wagon.content))) -}}
{{- end -}}
{{- end -}}
{{- end -}}


{{/* Handle Errors (File Won't be merged) */}}
{{- if $incoming_wagon.errors -}}
{{- $_ := set $return "errors" (append $return.errors (dict "file" $file.file "errors" $incoming_wagon.errors)) -}}
{{- else -}}
{{/* Parse Content, if not map */}}
{{- if not (kindIs "map" $incoming_wagon.content) -}}
{{- $_ := set $incoming_wagon "content" (fromYaml ($incoming_wagon.content)) -}}
{{- end -}}
{{/* File can have multiple ids */}}
{{- range $id := $ids -}}
{{/* Iterate Trough Train to find Matches */}}
{{- range $i, $wagon := $file_train -}}
{{/* Check if matched and single */}}
{{- if not (and ($matched) (eq (get $incoming_wagon.cfg (include "inventory.render.defaults.file_cfg.match" $)) "single")) -}}
{{/* Check if any file with the same identifier is already present */}}
{{- $wagon := (get $file_train $id) -}}
{{/* Match for given ID */}}
{{- if $wagon -}}
{{/* Overwrite Matched */}}
{{- $matched = 0 -}}
{{/* Merge file Properties */}}
{{- with $incoming_wagon.files -}}
{{- $_ := set $wagon "files" (concat $wagon.files $incoming_wagon.files) -}}
{{- end -}}
{{/* Merge Contents */}}
{{- if $incoming_wagon.content -}}
{{- $_ := set $wagon "content" (mergeOverwrite (default dict $wagon.content) $incoming_wagon.content) -}}
{{- end -}}
{{/* Update Wagon */}}
{{- $_ := set $file_train $id $wagon -}}
{{/* No Match for given ID */}}
{{- else -}}
{{/* Skip File if configured */}}
{{- if not (eq (get $incoming_wagon.cfg (include "inventory.render.defaults.file_cfg.no_match" $)) "skip") -}}
{{/* Add File as new file */}}
{{- $_ := set $file_train $id $incoming_wagon -}}
{{/* Validate Subpath */}}
{{- if or (not (get $incoming_wagon.cfg (include "inventory.render.defaults.file_cfg.subpath" $))) (and (get $incoming_wagon.cfg (include "inventory.render.defaults.file_cfg.subpath" $)) (eq (default "" $incoming_wagon.subpath) (default "" $wagon.subpath))) -}}
{{/* ForEach incomfing ID iterate */}}
{{- range $id := $ids -}}
{{/* Check Against existing Wagon IDs */}}
{{- range $wagon_id := $wagon.id -}}
{{/* Checl Match */}}
{{- if eq $id $wagon_id -}}
{{/* Overwrite Matched */}}
{{- $matched = 1 -}}
{{/* Merge file Properties */}}
{{- with $incoming_wagon.files -}}
{{- $_ := set $wagon "files" (concat $wagon.files $incoming_wagon.files) -}}
{{- end -}}
{{/* Merge Contents */}}
{{- if $incoming_wagon.content -}}
{{- $_ := set $wagon "content" (mergeOverwrite (default dict $wagon.content) $incoming_wagon.content) -}}
{{- end -}}
{{/* Increase Order */}}
{{- $order = addf $order 1 -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{/* Handle unmatched files */}}
{{- if not ($matched) -}}
{{/* Increase Order */}}
{{- $order = addf $order 1 -}}
{{/* Skip if pattern enabled */}}
{{- if not (get $incoming_wagon.cfg (include "inventory.render.defaults.file_cfg.pattern" $)) -}}
{{/* Skip File if configured */}}
{{- if not (eq (get $incoming_wagon.cfg (include "inventory.render.defaults.file_cfg.no_match" $)) "skip") -}}
{{- $file_train = append $file_train (omit $incoming_wagon "cfg") -}}
{{- $order = addf $order 1 -}}
{{- end -}}
{{- end -}}
{{- else -}}
{{- $_ := set $return "errors" (append $return.errors (dict "file" $file.file "error" "Received empty ID" "trace" $incoming_wagon)) -}}
{{- end -}}
{{- end -}}
{{- end -}}
Expand Down Expand Up @@ -159,16 +161,12 @@
{{- end -}}
{{/* Convert to Slice */}}
{{- if not (kindIs "slice" $file_train) -}}
{{- range $f, $c := $file_train -}}
{{- $_ := set $return "files" (append $return.files $c) -}}
{{- end -}}
{{- else -}}
{{- $_ := set $return "files" $file_train -}}
{{- end -}}
{{- $_ := set $return "files" $file_train -}}
{{- end -}}
{{/* Return */}}
{{- printf "%s" (toYaml $return) -}}
{{- end -}}
{{- end -}}
7 changes: 5 additions & 2 deletions charts/helmize/templates/render/func/files/_parse.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
{{- range $partial_files -}}
{{/* File Struct */}}
{{- $partial_file := dict "id" list "content" "" "debug" list "errors" list -}}
{{- $partial_file := dict "id" list "content" "" "subpath" (regexReplaceAll $path $file "${1}" | trimPrefix "/" | dir) "debug" list "errors" list -}}
{{/* Template Content */}}
{{- $template_content_raw := tpl . $context -}}
Expand All @@ -71,7 +71,10 @@
{{- if not (include "lib.utils.errors.unmarshalingError" $templated_content) -}}
{{/* Resolve File Configuration within file, if not set get empty dict */}}
{{- $file_cfg := default dict (fromYaml (include "lib.utils.dicts.lookup" (dict "data" $templated_content "path" (include "inventory.render.defaults.file_cfg.key" $)))) -}}
{{- $file_cfg := default dict (fromYaml (include "lib.utils.dicts.lookup" (dict "data" $templated_content "path" (include "inventory.render.defaults.file_cfg.key" $)))).res -}}
{{- if $file_cfg -}}
{{- $_ := unset $templated_content (include "inventory.render.defaults.file_cfg.key" $) -}}
{{- end -}}
{{/* Compares against Type */}}
{{- $file_cfg_type := fromYaml (include "lib.utils.types.validate" (dict "type" "inventory.render.types.file_configuration" "data" $file_cfg "ctx" $.ctx)) -}}
Expand Down
23 changes: 23 additions & 0 deletions charts/test/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*.orig
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
24 changes: 24 additions & 0 deletions charts/test/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: v2
name: test
description: A Helm chart for Kubernetes

# A chart can be either an 'application' or a 'library' chart.
#
# Application charts are a collection of templates that can be packaged into versioned archives
# to be deployed.
#
# Library charts provide useful utilities or functions for the chart developer. They're included as
# a dependency of application charts to inject those utilities and functions into the rendering
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
type: application

# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.1.0

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "1.16.0"
6 changes: 6 additions & 0 deletions charts/test/templates/remove.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
t: |
{{- $data := $.Values.test -}}
{{- range $t, $p := $data -}}
{{- $_ := set $p "ids" "none" -}}
{{- end -}}
{{ toYaml $data | nindent 10}}
9 changes: 9 additions & 0 deletions charts/test/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
test:
- ids:
- 1
- 2
content: something
- ids:
- 3
- 4
content: something4
Loading

0 comments on commit 40e5697

Please sign in to comment.