LoadValues loads values from a reader. The reader is expected to contain one or more YAML documents, the values of which are merged. And the values can be either a chart's default values or user-supplied values.
(data io.Reader)
| 183 | // The reader is expected to contain one or more YAML documents, the values of which are merged. |
| 184 | // And the values can be either a chart's default values or user-supplied values. |
| 185 | func LoadValues(data io.Reader) (map[string]any, error) { |
| 186 | values := map[string]any{} |
| 187 | reader := utilyaml.NewYAMLReader(bufio.NewReader(data)) |
| 188 | for { |
| 189 | currentMap := map[string]any{} |
| 190 | raw, err := reader.Read() |
| 191 | if err != nil { |
| 192 | if errors.Is(err, io.EOF) { |
| 193 | break |
| 194 | } |
| 195 | return nil, fmt.Errorf("error reading yaml document: %w", err) |
| 196 | } |
| 197 | if err := yaml.Unmarshal(raw, ¤tMap); err != nil { |
| 198 | return nil, fmt.Errorf("cannot unmarshal yaml document: %w", err) |
| 199 | } |
| 200 | values = MergeMaps(values, currentMap) |
| 201 | } |
| 202 | return values, nil |
| 203 | } |
| 204 | |
| 205 | // MergeMaps merges two maps. If a key exists in both maps, the value from b will be used. |
| 206 | // If the value is a map, the maps will be merged recursively. |
searching dependent graphs…