Documentation ¶
Index ¶
- func ConvertMap[T any](m Map) (T, error)
- func GetPathAs[T any](m Map, name string) (T, bool)
- func GetValueForSetFlag(setFlags []string, path string) string
- func TryGetPathAs[T any](m Map, name string) T
- type Map
- func (m Map) DeepClone() Map
- func (m Map) GetPath(name string) (any, bool)
- func (m Map) GetPathBool(s string) bool
- func (m Map) GetPathMap(name string) (Map, bool)
- func (m Map) GetPathString(s string) string
- func (m Map) GetPathStringOr(s string, def string) string
- func (m Map) JSON() string
- func (m Map) MergeFrom(other Map)
- func (m Map) SetPath(paths string, value any) error
- func (m Map) SetPaths(paths ...string) error
- func (m Map) SetSpecPaths(paths ...string) error
- func (m Map) YAML() string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConvertMap ¶
ConvertMap translates a Map to a T, via JSON
func GetPathAs ¶
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 ¶
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 ¶
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 ¶
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 MakeMap ¶
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 ¶
MapFromJSON constructs a Map from JSON
func MapFromObject ¶
MapFromObject is a helper to construct a map from an object, through a roundtrip JSON
func MapFromYaml ¶
MapFromYaml constructs a Map from YAML
func MustCastAsMap ¶
MustCastAsMap casts a value to a Map; if the value is not a map, it will panic..
func (Map) GetPath ¶
GetPath gets values from input like `key.subkey`, `key.[0].var`, or `key.[name:foo]`.
func (Map) GetPathBool ¶
GetPathBool is a helper around TryGetPathAs[bool] to allow usage as a method (otherwise impossible with generics)
func (Map) GetPathMap ¶
GetPathMap gets values from input like `key.subkey`
func (Map) GetPathString ¶
GetPathString is a helper around TryGetPathAs[string] to allow usage as a method (otherwise impossible with generics)
func (Map) GetPathStringOr ¶
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) MergeFrom ¶
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 ¶
SetPath applies values from a path like `key.subkey`, `key.[0].var`, or `key.[name:foo]`.
func (Map) SetSpecPaths ¶
SetSpecPaths applies values from input like `key.subkey=val`, and applies them under 'spec'