Skip to content

Commit

Permalink
Migrate Helmize Chart (#6)
Browse files Browse the repository at this point in the history
Migrate Helm Chart
  • Loading branch information
oliverbaehler authored May 7, 2022
1 parent 40e5697 commit 95a66ca
Show file tree
Hide file tree
Showing 95 changed files with 1,936 additions and 469 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/lint-and-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#
# Reference: https://github.com/helm/chart-testing-action
#
name: Linting and Testing
on: pull_request
jobs:
chart-test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Set up Helm
uses: azure/setup-helm@v1

- uses: actions/setup-python@v2
with:
python-version: 3.7

- name: Setup Chart Linting
id: lint
uses: helm/[email protected]

- name: Install Plugins
run: |
helm plugin install https://github.com/quintush/helm-unittest > /dev/null 2>&1
- name: Run chart-testing (lint) Helmize
run: ct lint --config ./charts/ct.yaml --lint-conf ./charts/lint.yaml

- name: Run chart-testing (lint) Examples
run: ct lint --config ./examples/ct.yaml

- name: Create kind cluster
uses: helm/[email protected]
if: steps.list-changed.outputs.changed == 'true'

- name: Run chart-testing (install) Examples
run: ct install --config ./ct.yaml
if: steps.list-changed.outputs.changed == 'true'
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,32 @@ on:
branches:
- main # Set a branch to deploy
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Install Helm
uses: azure/setup-helm@v1

- name: Add dependency chart repos
run: |
helm repo add buttahtoast https://buttahtoast.github.io/helm-charts/
- name: Configure Git
run: |
git config user.name "$GITHUB_ACTOR"
git config user.email "[email protected]"
- name: Run chart-releaser
uses: helm/[email protected]
with:
charts_dir: charts
env:
CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}"

deploy:
runs-on: ubuntu-20.04
concurrency:
Expand Down Expand Up @@ -34,4 +60,5 @@ jobs:
if: ${{ github.ref == 'refs/heads/main' }}
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./hugo/public
publish_dir: ./hugo/public
keep_files: true
30 changes: 0 additions & 30 deletions .github/workflows/release.yml

This file was deleted.

14 changes: 14 additions & 0 deletions charts/ct.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
## Reference: https://github.com/helm/chart-testing/blob/master/doc/ct_lint-and-install.md
##
remote: origin
target-branch: main
chart-dirs:
- charts/
chart-repos:
- buttahtoast=https://buttahtoast.github.io/helm-charts/
validate-chart-schema: true
validate-maintainers: true
validate-yaml: true
helm-extra-args: "--timeout 600s"
exclude-deprecated: true
debug: true
7 changes: 3 additions & 4 deletions charts/helmize/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ apiVersion: v2
name: helmize
description: Go Sprig based deployment engine deployed via Helm
type: library
version: "0.1.0-rc.3"
version: "0.1.0-rc.4"
appVersion: "0.1.0"
home: https://helmize.dev
icon: https://raw.githubusercontent.com/buttahtoast/helmize/main/icons/icon-transparent.png
icon: https://raw.githubusercontent.com/buttahtoast/helmize/main/icon.png
dependencies:
- name: library
version: "2.2.3"
#repository: "file://../../../helm-charts-1/charts/library"
repository: https://buttahtoast.github.io/helm-charts/
repository: https://buttahtoast.github.io/helm-charts/
keywords:
- library
- sprig
Expand Down
File renamed without changes.
5 changes: 4 additions & 1 deletion charts/helmize/templates/config/_types.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
default: [ ".yaml", ".yml", ".tpl" ]
{{ include "inventory.render.defaults.files.identifier_template" $ }}:
types: [ "string" ]
default: "inventory.render.func.files.identifier.template"
default: "inventory.render.templates.identifier"
{{ include "inventory.entrypoint.defaults.render_template" $ }}:
types: [ "string" ]
default: "inventory.entrypoint.templates.render"
{{ include "inventory.postrenders.defaults.cfg.post_renderers" $ }}:
types: [ "slice" ]
default: [ "{{ include "inventory.postrenders.defaults.cfg.post_renderers.inject_key" $ }}" ]
Expand Down
26 changes: 22 additions & 4 deletions charts/helmize/templates/entrypoint/_defaults.tpl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{/* Force <Template>
{{/* Force Parameter <Template>
Default Configuration Key within configuration file for force option
Expand All @@ -7,7 +7,7 @@
force
{{- end -}}

{{/* Summary <Template>
{{/* Summary Parameter <Template>
Default Summary Values Key
Expand All @@ -16,11 +16,29 @@ force
summary
{{- end -}}

{{/* Debug <Template>
{{/* Debug Parameter <Template>
Default Debug Values Key
*/}}
{{- define "inventory.entrypoint.defaults.debug_value" -}}
debug
{{- end -}}
{{- end -}}

{{/* Timestamps Parameter <Template>
Print Timestamps (For Benchmarking)
*/}}
{{- define "inventory.entrypoint.defaults.benchmark_value" -}}
benchmark
{{- end -}}

{{/* Merge Strategy <Template>
Default Configuration Key within configuration for render template declaration
*/}}
{{- define "inventory.entrypoint.defaults.render_template" -}}
render_template
{{- end -}}
8 changes: 2 additions & 6 deletions charts/helmize/templates/entrypoint/func/_deploy.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,8 @@
{{/* Check if Errors were found */}}
{{- if or (not $deploy.errors) (and ($deploy.errors) ($force)) -}}

{{/* Iterate Over Files */}}
{{- range $file, $prop := $deploy.files -}}
{{- if $prop.content -}}
{{- printf "---\n# File: %s\n# Checksum %s\n%s\n" .id $prop.checksum (toYaml $prop.content) -}}
{{- end -}}
{{- end -}}
{{/* Call Render Template */}}
{{- include ((fromYaml (include "inventory.config.func.resolve" (dict "path" (include "inventory.entrypoint.defaults.render_template" $) "ctx" $))).res) (dict "ctx" $ "deploy" $deploy) -}}

{{- else -}}
{{- include "lib.utils.errors.fail" (printf "Found errors, please resolve those errors or use the force options:\n%s" (toYaml $deploy.errors | nindent 2)) -}}
Expand Down
8 changes: 6 additions & 2 deletions charts/helmize/templates/entrypoint/func/_resolve.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@
{{- $render_raw := include "inventory.render.func.resolve" $ -}}
{{- $render := fromYaml ($render_raw) -}}
{{- if (not (include "lib.utils.errors.unmarshalingError" $render)) -}}
{{/* Return */}}
{{- printf "%s" (toYaml $render) -}}
{{- $benchmark := (fromYaml (include "lib.utils.dicts.lookup" (dict "data" $.Values "path" (include "inventory.entrypoint.defaults.benchmark_value" $)))).res -}}
{{- if $benchmark -}}
{{- printf "%s" (toYaml $render) -}}
{{- else -}}
{{- printf "%s" (toYaml (omit $render "timestamps")) -}}
{{- end -}}
{{- else -}}
{{- include "lib.utils.errors.fail" (printf "Render template returned invalid YAML:%s" (toYaml $render_raw | nindent 2)) -}}
{{- end -}}
Expand Down
13 changes: 13 additions & 0 deletions charts/helmize/templates/entrypoint/templates/_render.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@


{{- define "inventory.entrypoint.templates.render" -}}
{{- if $.deploy.files -}}
{{- range $file, $prop := $.deploy.files -}}
{{- if $prop.render -}}
{{- if $prop.content -}}
{{- printf "---\n# File: %s\n# Checksum %s\n%s\n" .id $prop.checksum (toYaml $prop.content) -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}
3 changes: 3 additions & 0 deletions charts/helmize/templates/helpers/_timestamp.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{{- define "inventory.helpers.ts" -}}
{{- $_ := set $.ctx "timestamps" (append $.ctx.timestamps (dict "point" $.msg "time" now)) -}}
{{- end -}}
38 changes: 18 additions & 20 deletions charts/helmize/templates/render/_defaults.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,6 @@ Data
cfg
{{- end -}}


{{/* Match (File Configuration Type) <Template>
Match Strategy Key
*/}}
{{- define "inventory.render.defaults.file_cfg.match" -}}
match_ids
{{- end -}}

{{/* No Match (File Configuration Type) <Template>
Match Strategy Key
Expand All @@ -73,25 +63,33 @@ match_ids
no_match
{{- end -}}

{{/* Multiple filename id (File Configuration Type) <Template>
Allow multiple resources from one file to use the filename

*/}}
{{- define "inventory.render.defaults.file_cfg.multi_filename" -}}
multiple_filename_id
{{- define "inventory.render.defaults.file_cfg.max_match" -}}
max_match
{{- end -}}


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

{{/* Render (File Configuration Type, Local) <Template>
{{- define "inventory.render.defaults.file_cfg.subpath" -}}
subpath
Configure if a file should be rendered in the final output. Note that it will still show up in the Summary
*/}}
{{- define "inventory.render.defaults.file_cfg.render" -}}
render
{{- 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.fork" -}}
fork
{{- end -}}
{{/* Pattern (File Configuration Type, Local) <Template>
Expand Down
25 changes: 12 additions & 13 deletions charts/helmize/templates/render/_types.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,23 @@
*/}}
{{- define "inventory.render.types.file_configuration" -}}
{{ include "inventory.render.defaults.file_cfg.match" $ }}:
types: [ "string" ]
default: "all"
values: [ "single", "all" ]
{{ include "inventory.render.defaults.file_cfg.no_match" $ }}:
types: [ "string" ]
default: "append"
values: [ "append", "skip" ]
{{ 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" $ }}:
{{ include "inventory.render.defaults.file_cfg.pattern" $ }}:
types: [ "bool" ]
default: false
{{ include "inventory.render.defaults.file_cfg.pattern" $ }}:
{{ include "inventory.render.defaults.file_cfg.render" $ }}:
types: [ "bool" ]
default: true
{{ include "inventory.render.defaults.file_cfg.no_match" $ }}:
types: [ "string" ]
default: "append"
values: [ "append", "skip" ]
{{ include "inventory.render.defaults.file_cfg.max_match" $ }}:
types: [ "float64" ]
default: 0
{{ include "inventory.render.defaults.file_cfg.fork" $ }}:
types: [ "bool" ]
default: false
{{- end -}}
30 changes: 30 additions & 0 deletions charts/helmize/templates/render/func/_identifier.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{{/* Identifier <Template>
Calls Identifier Template
*/}}
{{- define "inventory.render.func.identifier" -}}
{{- if and $.wagon $.ctx -}}

{{/* Run Identifiert Template */}}
{{- $identifier_tpl_name := (fromYaml (include "inventory.config.func.resolve" (dict "path" (include "inventory.render.defaults.files.identifier_template" $.ctx) "ctx" $.ctx))).res -}}
{{- if $identifier_tpl_name -}}

{{/* included evaluated Template with current Root context */}}
{{- include $identifier_tpl_name $ -}}

{{/* Handle ID */}}
{{- if not ($.wagon.id) -}}
{{/* Set Filename as default, if nothing set */}}
{{- $_ := set $.wagon "id" (list $.wagon.file_id.filename) -}}
{{- else -}}
{{/* Convert to List */}}
{{- if not (kindIs "slice" $.wagon.id) -}}
{{- $_ := set $.wagon "id" (list $.wagon.id) -}}
{{- end -}}
{{- end -}}

{{- end -}}
{{- else -}}
{{- include "lib.utils.errors.params" (dict "tpl" "inventory.render.files.multi_yaml" "params" (list "content " "ctx")) -}}
{{- end -}}
{{- end -}}
Loading

0 comments on commit 95a66ca

Please sign in to comment.