applyNullOverrides set val to Zero if it matches any of the recorded paths
(target any, path tree.Path)
| 246 | |
| 247 | // applyNullOverrides set val to Zero if it matches any of the recorded paths |
| 248 | func (p *ResetProcessor) applyNullOverrides(target any, path tree.Path) error { |
| 249 | switch v := target.(type) { |
| 250 | case map[string]any: |
| 251 | KEYS: |
| 252 | for k, e := range v { |
| 253 | next := path.Next(k) |
| 254 | for _, pattern := range p.paths { |
| 255 | if next.Matches(pattern) { |
| 256 | delete(v, k) |
| 257 | continue KEYS |
| 258 | } |
| 259 | } |
| 260 | err := p.applyNullOverrides(e, next) |
| 261 | if err != nil { |
| 262 | return err |
| 263 | } |
| 264 | } |
| 265 | case []any: |
| 266 | ITER: |
| 267 | for i, e := range v { |
| 268 | next := path.Next(fmt.Sprintf("[%d]", i)) |
| 269 | for _, pattern := range p.paths { |
| 270 | if next.Matches(pattern) { |
| 271 | continue ITER |
| 272 | // TODO(ndeloof) support removal from sequence |
| 273 | } |
| 274 | } |
| 275 | err := p.applyNullOverrides(e, next) |
| 276 | if err != nil { |
| 277 | return err |
| 278 | } |
| 279 | } |
| 280 | } |
| 281 | return nil |
| 282 | } |
| 283 | |
| 284 | func (p *ResetProcessor) checkForCycle(node *yaml.Node, path tree.Path) error { |
| 285 | paths := p.visitedNodes[node] |