values

package
v0.0.0-...-e7c9706 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertMap

func ConvertMap[T any](m Map) (T, error)

ConvertMap translates a Map to a T, via JSON

func GetPathAs

func GetPathAs[T any](m Map, name string) (T, bool)

GetPathAs is a helper function to get a patch value and cast it to a specified type. If the path is not found, or the cast fails, false is returned.

func GetValueForSetFlag

func GetValueForSetFlag(setFlags []string, path string) string

GetValueForSetFlag parses the passed set flags which have format key=value and if any set the given path, returns the corresponding value, otherwise returns the empty string. setFlags must have valid format.

func TryGetPathAs

func TryGetPathAs[T any](m Map, name string) T

TryGetPathAs is a helper function to get a patch value and cast it to a specified type. If the path is not found, or the cast fails, the zero value is returned.

Types

type Map

type Map map[string]any

Map is a wrapper around an untyped map. This is used throughout the operator codebase to provide generic access. While un-intuitive, as generally strong typing is preferred, this solves a number of problems: A large portion of the codebase is dealing with inherently unstructured input. The core type, the Helm values, is already an untyped value.

For example, while we do have a value_types.proto representation, this isn't actually appropriate for direct usage. For example, we allow passing `unvalidatedValues` which is a completely opaque blob. We also allow many types to be both string or ints, for instance, which makes usage awkward. Really this is useful for *validation* but not usage throughout the codebase. Historically, there were attempts to use the direct typed value. In practice, what we ended up doing is converting to/from the typed struct, protobuf.Struct, JSON/YAML, and an unstructured Map, depending on the needs of the current codebase.

Some other problems with attempting to use typed structs:

  • There is a mix of golang protobuf (Istio) and gogo protobuf (Kubernetes types) which have poor interactions
  • Typed structs lose context on what was explicitly set by a user vs the zero value (without taking care at every point, and making more painful struct definitions). For instance, `pilot.enabled=false` is very different from just not setting `enabled`, which defaults to 'true'. Some of these types also come from others (Kubernetes), which we don't control.
  • A large portion of the code is dynamically getting or setting values, like applying `--set values.foo.bar=baz`. These are MUCH easier to do on a Map than on a struct which requires complex reflection.

func CastAsMap

func CastAsMap(cur any) (Map, bool)

CastAsMap casts a value to a Map, if possible.

func MakeMap

func MakeMap(contents any, path ...string) Map

MakeMap is a helper to construct a map that has a single value, nested under some set of paths. For example, `MakeMap(1, "a", "b") = Map{"a": Map{"b": 1}}`

func MapFromJSON

func MapFromJSON(input []byte) (Map, error)

MapFromJSON constructs a Map from JSON

func MapFromObject

func MapFromObject[T any](contents T) (Map, error)

MapFromObject is a helper to construct a map from an object, through a roundtrip JSON

func MapFromYaml

func MapFromYaml(input []byte) (Map, error)

MapFromYaml constructs a Map from YAML

func MustCastAsMap

func MustCastAsMap(cur any) Map

MustCastAsMap casts a value to a Map; if the value is not a map, it will panic..

func (Map) DeepClone

func (m Map) DeepClone() Map

DeepClone performs a deep clone of the map

func (Map) GetPath

func (m Map) GetPath(name string) (any, bool)

GetPath gets values from input like `key.subkey`, `key.[0].var`, or `key.[name:foo]`.

func (Map) GetPathBool

func (m Map) GetPathBool(s string) bool

GetPathBool is a helper around TryGetPathAs[bool] to allow usage as a method (otherwise impossible with generics)

func (Map) GetPathMap

func (m Map) GetPathMap(name string) (Map, bool)

GetPathMap gets values from input like `key.subkey`

func (Map) GetPathString

func (m Map) GetPathString(s string) string

GetPathString is a helper around TryGetPathAs[string] to allow usage as a method (otherwise impossible with generics)

func (Map) GetPathStringOr

func (m Map) GetPathStringOr(s string, def string) string

GetPathStringOr is a helper around TryGetPathAs[string] to allow usage as a method (otherwise impossible with generics), with an allowance for a default value if it is not found/not set.

func (Map) JSON

func (m Map) JSON() string

JSON serializes a Map to a JSON string.

func (Map) MergeFrom

func (m Map) MergeFrom(other Map)

MergeFrom does a key-wise merge between the current map and the passed in map. The other map has precedence, and the result will modify the current map.

func (Map) SetPath

func (m Map) SetPath(paths string, value any) error

SetPath applies values from a path like `key.subkey`, `key.[0].var`, or `key.[name:foo]`.

func (Map) SetPaths

func (m Map) SetPaths(paths ...string) error

SetPaths applies values from input like `key.subkey=val`

func (Map) SetSpecPaths

func (m Map) SetSpecPaths(paths ...string) error

SetSpecPaths applies values from input like `key.subkey=val`, and applies them under 'spec'

func (Map) YAML

func (m Map) YAML() string

YAML serializes a Map to a YAML string.

Jump to

Keyboard shortcuts

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