MCPcopy Create free account
hub / github.com/cozystack/talm / loadValues

Function loadValues

pkg/engine/engine.go:1705–1776  ·  view source on GitHub ↗

Imported from Helm https://github.com/helm/helm/blob/c6beb169d26751efd8131a5d65abe75c81a334fb/pkg/cli/values/options.go#L44 nolint:gocritic // hugeParam: Options is the public configuration carrier; passing by pointer would propagate across pkg/commands and external consumers.

(opts Options)

Source from the content-addressed store, hash-verified

1703//
1704//nolint:gocritic // hugeParam: Options is the public configuration carrier; passing by pointer would propagate across pkg/commands and external consumers.
1705func loadValues(opts Options) (map[string]any, error) {
1706 // Base map to hold the merged values
1707 base := make(map[string]any)
1708
1709 // Load values from files specified with -f or --values.
1710 for _, filePath := range opts.ValueFiles {
1711 currentMap, err := loadValueFile(opts.Root, filePath)
1712 if err != nil {
1713 return nil, err
1714 }
1715
1716 base = mergeMaps(base, currentMap)
1717 }
1718
1719 // Parse and merge values from --set-json
1720 for _, value := range opts.JsonValues {
1721 currentMap := make(map[string]any)
1722
1723 err := json.Unmarshal([]byte(value), &currentMap)
1724 if err != nil {
1725 return nil, errors.Wrapf(err, "failed to unmarshal JSON value '%s'", value)
1726 }
1727
1728 base = mergeMaps(base, currentMap)
1729 }
1730
1731 // Screen --set values for IP / CIDR / version literals BEFORE
1732 // strvals.ParseInto chews them. The parser interprets dots in
1733 // the RHS as YAML key nesting, so `--set endpoint=10.0.0.1`
1734 // produces `{endpoint: {10: {0: {0: 1}}}}` — silently corrupt
1735 // config. The warning steers operators to --set-string.
1736 screenSetValuesForCoercion(opts.Values)
1737
1738 // Parse and merge values from --set
1739 for _, value := range opts.Values {
1740 err := strvals.ParseInto(value, base)
1741 if err != nil {
1742 return nil, errors.Wrapf(err, "failed to parse set value '%s'", value)
1743 }
1744 }
1745
1746 // Parse and merge values from --set-string
1747 for _, value := range opts.StringValues {
1748 err := strvals.ParseIntoString(value, base)
1749 if err != nil {
1750 return nil, errors.Wrapf(err, "failed to parse set-string value '%s'", value)
1751 }
1752 }
1753
1754 // Parse and merge values from --set-file
1755 for _, value := range opts.FileValues {
1756 content, err := os.ReadFile(value)
1757 if err != nil {
1758 return nil, errors.Wrapf(err, "failed to read file for set-file value '%s'", value)
1759 }
1760
1761 err = strvals.ParseInto(fmt.Sprintf("%s=%s", value, content), base)
1762 if err != nil {

Calls 3

loadValueFileFunction · 0.85
mergeMapsFunction · 0.85