@@ -18,6 +18,7 @@ package fieldpath
18
18
19
19
import (
20
20
"fmt"
21
+ "sigs.k8s.io/structured-merge-diff/v4/value"
21
22
"sort"
22
23
"strings"
23
24
@@ -148,8 +149,14 @@ func MustPrefixPattern(parts ...interface{}) *SetPattern {
148
149
}
149
150
150
151
// PrefixPattern creates a SetPattern that matches all field paths prefixed by the given list of pattern path parts.
151
- // The pattern parts may be PathPatterns, PathElements, strings (for field names) or ints (for array indices).
152
- // `MatchAnyPathElement()` may be used as a pattern path part to wildcard match a field path part.
152
+ // The pattern parts may any of:
153
+ //
154
+ // - PathPattern - for wildcards, `MatchAnyPathElement()` can be used as well.
155
+ // - PathElement - for any path element
156
+ // - value.FieldList - for associative list keys
157
+ // - value.Value - for scalar list elements
158
+ // - string - For field names
159
+ // - int - for array indices
153
160
func PrefixPattern (parts ... interface {}) (* SetPattern , error ) {
154
161
current := MatchAnySet () // match all field patch suffixes
155
162
for i := len (parts ) - 1 ; i >= 0 ; i -- {
@@ -160,6 +167,13 @@ func PrefixPattern(parts ...interface{}) (*SetPattern, error) {
160
167
pattern = t
161
168
case PathElement :
162
169
pattern = PathPattern {PathElement : t }
170
+ case * value.FieldList :
171
+ if len (* t ) == 0 {
172
+ return nil , fmt .Errorf ("associative list key type path elements must have at least one key (got zero)" )
173
+ }
174
+ pattern = PathPattern {PathElement : PathElement {Key : t }}
175
+ case value.Value :
176
+ pattern = PathPattern {PathElement : PathElement {Value : & t }}
163
177
case string :
164
178
pattern = PathPattern {PathElement : PathElement {FieldName : & t }}
165
179
case int :
@@ -639,7 +653,7 @@ func (s *SetNodeMap) Leaves() *SetNodeMap {
639
653
return out
640
654
}
641
655
642
- // Filter defines an interface for filtering a set.
656
+ // Filter defines an interface for excluding field paths from a set.
643
657
// NewExcludeFilter can be used to create a filter that removes
644
658
// excluded field paths.
645
659
// NewPatternFilter can be used to create a filter that removes all fields except
0 commit comments