Add a subdirectories templating function - #105
Conversation
|
✅ CLA satisfied. All contributors have signed the current CLA. The |
|
| Filename | Overview |
|---|---|
| internal/model/model.go | Adds V1Subdirectory struct with Name and Path fields; minimal, clean addition |
| internal/template/v1/template.go | Adds subdirectories template function; contains a logic bug in the leaf-exclusion filter that incorrectly skips nodes that are both a secret and a directory |
| internal/template/v1/template_test.go | Adds five well-structured tests for subdirectories; missing coverage for the mixed secret+directory node edge case that the tree structure explicitly supports |
Reviews (1): Last reviewed commit: "Add a subdirectories templating function" | Re-trigger Greptile
Adds a subdirectories templating function which enables ConfigMap templating to be highly dynamic based on the structure of the project it's pulling from. This is useeful when a directory has a set of homogeneous subdirectories. (e.g. subdirectories a and b both have the same set of secrets, and the subdirectory names a and b may not be known).
Fixes the feedback from @greptile-apps: Incorrect leaf-exclusion filter silently drops valid subdirectories. The tree allows a node to carry both a `Secret` (when a secret key name matches a directory segment name) and `Children` (when that segment also has nested secrets). The current guard if child.Secret != nil { continue } skips any such node, so `subdirectories("/")` would never return a folder whose name collides with a root-level secret key, even though `BuildSecretTree` explicitly supports this state (see the "allows a secret key and folder segment with the same name" test). The correct predicate is to skip nodes that have no children (pure leaves), not nodes that happen to also carry a secret value.
This naming is more consistent with other templating function names and less ambiguous than subdirectories.
dc1ee2b to
9227420
Compare
Adds a subdirectories templating function which enables ConfigMap templating to be highly dynamic based on the structure of the project it's pulling from.
This is useeful when a directory has a set of homogeneous subdirectories. (e.g. subdirectories a and b both have the same set of secrets, and the subdirectory names a and b may not be known).