helmette

package
v0.0.0-...-d8749bb Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 18, 2024 License: Apache-2.0 Imports: 27 Imported by: 1

Documentation

Overview

package helmette implements golang analogs for the constructs present within the helm template rendering environment. See also: - https://helm.sh/docs/chart_template_guide/function_list/ - http://masterminds.github.io/sprig/ - https://pkg.go.dev/text/template

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AsIntegral

func AsIntegral[T HelmNumber](value any) (T, bool)

AsIntegral is a helm-specific replacement for type assertions/tests of numeric types. The combination of helm, text/template, and sprig prevent us from being able to reasonably distinguish between the various types of numeric types. Instead we must rely on loose heuristic to determine if a value could reasonably be interpreted as anything other than a float64.

func AsNumeric

func AsNumeric(value any) (float64, bool)

AsNumeric attempts to interpret the provided value as a helm friendly "numeric" (float64). It should be used in place of type assertions to numeric types. Due to helm's, sprig's, and gotohelm's use of untyped JSON marshalling all numeric values are cast to float64s. To ensure that gocode and helm code function the same way, AsNumeric must be used.

func Atoi

func Atoi(in string) (int, error)

Atoi is the go equivalent of sprig's `atoi`. +gotohelm:builtin=atoi

func Coalesce

func Coalesce[T any](values ...T) T

Coalesce is the go equivalent of sprig's `coalesce`. +gotohelm:builtin=coalesce

func Concat

func Concat[T any](lists ...[]T) []T

Concat is the go equivalent of sprig's `concat`. +gotohelm:builtin=concat

func Contains

func Contains(substr, s string) bool

+gotohelm:builtin=contains

func Default

func Default[T any](default_, value T) T

Default is a go equivalent of sprig's `default`. +gotohelm:builtin=default

func DictTest

func DictTest[K comparable, V any](m map[K]V, key K) (V, bool)

DictTest is an equivalent of `val, ok := map[key]` that is exercised as a function call rather than a special form of syntax. See also: "_shims.dicttest". func DictTest[K comparable, V any](m map[K]V, key K) TestResult[V] {

func Dig

func Dig(m map[string]any, fallback any, path ...string) any

Dig is a go equivalent of sprig's `dig`.

func Empty

func Empty(value any) bool

Empty is the go equivalent of sprig's `empty`. +gotohelm:builtin=empty

func Fail

func Fail(msg string)

Fail is the go equivalent of sprig's `fail`. +gotohelm:builtin=fail

func First

func First[T any](x []T) any

First function can not return `T` as sprig implementation will return nil if array is of the size 0.

# Reference https://github.com/Masterminds/sprig/blob/581758eb7d96ae4d113649668fa96acc74d46e7f/list.go#L161-L163 +gotohelm:builtin=first

func Float64

func Float64(in string) (float64, error)

+gotohelm:builtin=float64

func FromJSON

func FromJSON(data string) any

FromJSON is the go equivalent of sprig's `fromJson`. +gotohelm:builtin=fromJson

func HasKey

func HasKey[K comparable, V any](m map[K]V, key K) bool

HasKey is the go equivalent of sprig's `hasKey`. +gotohelm:builtin=hasKey

func Indent

func Indent(spaces int, v string) string

+gotohelm:builtin=indent

func Join

func Join[T any](sep string, s []T) string

+gotohelm:builtin=join

func Keys

func Keys[K comparable, V any](m map[K]V) []K

Keys is the go equivalent of sprig's `keys`. +gotohelm:builtin=keys

func KindIs

func KindIs(kind string, v any) bool

KindIs is the go equivalent of sprig's `kindIs`. +gotohelm:builtin=kindIs

func KindOf

func KindOf(v any) string

KindOf is the go equivalent of sprig's `kindOf`. +gotohelm:builtin=kindOf

func Len

func Len(in any) int

+gotohelm:builtin=len

func Lookup

func Lookup[T any, PT kube.AddrofObject[T]](dot *Dot, namespace, name string) (obj *T, found bool)

Lookup is a wrapper around helm's builtin lookup function that instead returns `nil, false` if the lookup fails instead of an empty dictionary. See: https://github.com/helm/helm/blob/e24e31f6cc122405ae25069f5b3960036c202c46/pkg/engine/lookup_func.go#L60-L97

func Lower

func Lower(in string) string

Lower is the go equivalent of sprig's `lower`. +gotohelm:builtin=lower

func Merge

func Merge[K comparable, V any](sources ...map[K]V) map[K]V

Merge is a go equivalent of sprig's `merge`.

func MergeTo

func MergeTo[T any](sources ...any) T

MergeTo transpiles to `merge`, but in the golang domain it'll return the type requested

func Min

func Min(in ...int64) int64

Min is the go equivalent of sprig's `min` +gotohelm:builtin=min

func MustDuration

func MustDuration(duration string) *metav1.Duration

func MustFromJSON

func MustFromJSON(data string) any

MustFromJSON is the go equivalent of sprig's `mustFromJson`. +gotohelm:builtin=mustFromJson

func MustRegexMatch

func MustRegexMatch(pattern, s string) bool

MustRegexMatch is the go equivalent of sprig's `mustRegexMatch`. +gotohelm:builtin=mustRegexMatch

func MustToJSON

func MustToJSON(value any) string

MustToJSON is the go equivalent of sprig's `mustToJson`. +gotohelm:builtin=mustToJson

func NIndent

func NIndent(spaces int, v string) string

+gotohelm:builtin=nindent

func Printf

func Printf(format string, a ...any) string

Printf is the go equivalent of text/templates's `printf` +gotohelm:builtin=printf

func Quote

func Quote(vs ...any) string

Quote is the equivalent of sprig's `quote` - it takes an arbitrary list of arguments +gotohelm:builtin=quote

func RandAlphaNum

func RandAlphaNum(length int) string

+gotohelm:builtin=randAlphaNum

func RegexMatch

func RegexMatch(pattern, s string) bool

RegexMatch is the go equivalent of sprig's `regexMatch`. +gotohelm:builtin=regexMatch

func RegexReplaceAll

func RegexReplaceAll(regex, s, repl string) string

+gotohelm:builtin=regexReplaceAll

func Replace

func Replace(old, new, s string) string

+gotohelm:builtin=replace

func Required

func Required(msg string, value any)

Required is the go equivalent of sprig's `required`. +gotohelm:builtin=required

func SQuote

func SQuote(vs ...any) string

SQuote is the equivalent of sprig's `squote`. +gotohelm:builtin=squote

func SafeLookup

func SafeLookup[T any, PT kube.AddrofObject[T]](dot *Dot, namespace, name string) (*T, bool, error)

SafeLookup is a wrapper around helm's builtin lookup function. It acts exactly like Lookup except it returns any errors that may have occurred in the underlying lookup operations.

func SemverCompare

func SemverCompare(constraint, version string) (bool, error)

+gotohelm:builtin=semverCompare

func Sha256Sum

func Sha256Sum(input string) string

+gotohelm:builtin=sha256sum

func SortAlpha

func SortAlpha(x []string) []string

SortAlpha is the go equivalent of sprig's `sortAlpha`. It mutates the provided slice in place and returns the mutated slice. +gotohelm:builtin=sortAlpha

func SortedKeys

func SortedKeys[T any](m map[string]T) []string

SortedKeys is a convenience function to aid in iterating over maps in a deterministic order.

func ToJSON

func ToJSON(value any) string

ToJSON is the go equivalent of sprig's `toJson`. +gotohelm:builtin=toJson

func ToString

func ToString(input any) string

+gotohelm:builtin=toString

func TrimPrefix

func TrimPrefix(prefix, s string) string

TrimPrefix is the go equivalent of sprig's `trimPrefix` +gotohelm:builtin=trimPrefix

func TrimSuffix

func TrimSuffix(suffix, s string) string

TrimSuffix is the go equivalent of sprig's `trimSuffix` +gotohelm:builtin=trimSuffix

func Trunc

func Trunc(length int, in string) string

Trunc is a go equivalent of sprig's `trunc`. +gotohelm:builtin=trunc

func TypeAssertion

func TypeAssertion[T any](val any) T

TypeAssertion is an equivalent of `x.(type)` that is exercised as a function call rather than a special form of syntax. See also: "_shims.typeassertion".

func TypeIs

func TypeIs(typ string, v any) bool

KindIs is the go equivalent of sprig's `typeIs`. +gotohelm:builtin=typeIs

func TypeOf

func TypeOf(v any) string

TypeOf is the go equivalent of sprig's `typeOf`. +gotohelm:builtin=typeOf

func TypeTest

func TypeTest[T any](val any) (T, bool)

TypeTest is an equivalent of `val, ok := x.(type)` that is exercised as a function call rather than a special form of syntax. See also: "_shims.typetest".

func UnmarshalInto

func UnmarshalInto[T any](value any) T

UnmarshalInto valuesutil.UnmarshalInto without an error return for use to the gotohelm world.

It may be used to "convert" untyped values into values of type T provided that their JSON representations are the same. For example, an any type holding a known struct value that can't be asserted via a type assertion.

DANGER: In helm, no validation or default is done. This function effectively transpiles to `return value`. Use with care.

func UnmarshalYamlArray

func UnmarshalYamlArray[T any](repr string) []T

UnmarshalYaml fills in the type requested +gotohelm:builtin=fromYamlArray

func Unset

func Unset[K comparable, V any](d map[K]V, key K)

Unset is the go equivalent of sprig's `unset`. +gotohelm:builtin=unset

func Until

func Until(n int) []int

Until is the go equivalent of spring's `until`. There might be better ways to do things with gotohelm, but this represents a high-fidelity way to translate templates. +gotohelm:builtin=until

func Unwrap

func Unwrap[T any](from Values) T

Unwrap "unwraps" .Values into a golang struct. DANGER: Unwrap performs no defaulting or validation. At the helm level, this is transpiled into .Values.AsMap. Callers are responsible for verifying that T is appropriately validated by the charts values.schema.json.

func Upper

func Upper(in string) string

Upper is the go equivalent of sprig's `upper`. +gotohelm:builtin=upper

Types

type Chart

type Chart struct {
	Name       string
	Version    string
	AppVersion string
}

type Dot

type Dot struct {
	Values    Values
	Release   Release
	Chart     Chart
	Subcharts map[string]*Dot

	// KubeConfig is a hacked in value to allow `Lookup` to not rely on global
	// values. It's a kube.Config to support JSON marshalling and allow easy
	// transport into the `go run` test runner.
	// WARNING: DO NOT USE OR REFERENCE IN HELM CHARTS. IT WILL NOT WORK.
	KubeConfig kube.Config
}

Dot is a representation of the "global" context or `.` in the execution of a helm template. See also: https://github.com/helm/helm/blob/3764b483b385a12e7d3765bff38eced840362049/pkg/chartutil/values.go#L137-L166

type HelmNumber

type HelmNumber interface {
	~float64 | ~int | ~int64
}

HelmNumber is a union type of valid numeric primitives within the context of helm templates.

type Release

type Release struct {
	Name      string
	Namespace string
	Service   string
	IsUpgrade bool
	IsInstall bool
}

type Tuple2

type Tuple2[T1, T2 any] struct {
	T1 T1
	T2 T2
}

func Compact2

func Compact2[T1, T2 any](t1 T1, t2 T2) Tuple2[T1, T2]

type Tuple3

type Tuple3[T1, T2, T3 any] struct {
	T1 T1
	T2 T2
	T3 T3
}

func Compact3

func Compact3[T1, T2, T3 any](t1 T1, t2 T2, t3 T3) Tuple3[T1, T2, T3]

type Values

type Values = chartutil.Values

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL