mirror of
https://github.com/bjw-s-labs/helm-charts.git
synced 2025-07-04 00:47:04 +02:00
feat(common): Release v2.1.0 (#221)
Co-authored-by: Christopher Larivière <lariviere.c@gmail.com>
This commit is contained in:
parent
272dbef383
commit
b360c9885a
18 changed files with 288 additions and 44 deletions
35
charts/library/common/templates/lib/chart/_kahn.tpl
Normal file
35
charts/library/common/templates/lib/chart/_kahn.tpl
Normal file
|
@ -0,0 +1,35 @@
|
|||
{{/*
|
||||
Implementation of Kahn's algorithm based on
|
||||
https://en.wikipedia.org/wiki/Topological_sorting#Kahn's_algorithm
|
||||
|
||||
source: https://github.com/dastrobu/helm-charts/blob/main/environment-variables/templates/_kahn.tpl
|
||||
*/}}
|
||||
{{- define "bjw-s.common.lib.kahn" -}}
|
||||
{{- $graph := .graph -}}
|
||||
{{- if empty $graph -}}
|
||||
{{- $_ := set . "out" list -}}
|
||||
{{- else -}}
|
||||
{{- $S := list -}}
|
||||
|
||||
{{- range $node, $edges := $graph -}}
|
||||
{{- if empty $edges -}}
|
||||
{{- $S = append $S $node -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- if empty $S -}}
|
||||
{{- fail (printf "graph is cyclic or has bad edge definitions. Remaining graph is:\n%s" ( .graph | toYaml ) ) }}
|
||||
{{- end -}}
|
||||
|
||||
{{- $n := first $S -}}
|
||||
{{- $_ := unset $graph $n -}}
|
||||
|
||||
{{- range $node, $edges := $graph -}}
|
||||
{{- $_ := set $graph $node ( without $edges $n ) -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- $args := dict "graph" $graph "out" list -}}
|
||||
{{- include "bjw-s.common.lib.kahn" $args -}}
|
||||
{{- $_ = set . "out" ( concat ( list $n ) $args.out ) -}}
|
||||
{{- end -}}
|
||||
{{- end }}
|
Loading…
Add table
Add a link
Reference in a new issue