Upgrade k8s package verison (#5358)
* upgrade k8s package version Signed-off-by: hongzhouzi <hongzhouzi@kubesphere.io> * Script upgrade and code formatting. Signed-off-by: hongzhouzi <hongzhouzi@kubesphere.io> Signed-off-by: hongzhouzi <hongzhouzi@kubesphere.io>
This commit is contained in:
71
vendor/sigs.k8s.io/kustomize/kyaml/yaml/match.go
generated
vendored
71
vendor/sigs.k8s.io/kustomize/kyaml/yaml/match.go
generated
vendored
@@ -5,6 +5,7 @@ package yaml
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@@ -42,9 +43,10 @@ type PathMatcher struct {
|
||||
// This is useful for if the nodes are to be printed in FlowStyle.
|
||||
StripComments bool
|
||||
|
||||
val *RNode
|
||||
field string
|
||||
matchRegex string
|
||||
val *RNode
|
||||
field string
|
||||
matchRegex string
|
||||
indexNumber int
|
||||
}
|
||||
|
||||
func (p *PathMatcher) stripComments(n *Node) {
|
||||
@@ -79,14 +81,47 @@ func (p *PathMatcher) filter(rn *RNode) (*RNode, error) {
|
||||
return p.val, nil
|
||||
}
|
||||
|
||||
if IsIdxNumber(p.Path[0]) {
|
||||
return p.doIndexSeq(rn)
|
||||
}
|
||||
|
||||
if IsListIndex(p.Path[0]) {
|
||||
// match seq elements
|
||||
return p.doSeq(rn)
|
||||
}
|
||||
|
||||
if IsWildcard(p.Path[0]) {
|
||||
// match every elements (*)
|
||||
return p.doMatchEvery(rn)
|
||||
}
|
||||
// match a field
|
||||
return p.doField(rn)
|
||||
}
|
||||
|
||||
func (p *PathMatcher) doMatchEvery(rn *RNode) (*RNode, error) {
|
||||
if err := rn.VisitElements(p.visitEveryElem); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return p.val, nil
|
||||
}
|
||||
|
||||
func (p *PathMatcher) visitEveryElem(elem *RNode) error {
|
||||
fieldName := p.Path[0]
|
||||
// recurse on the matching element
|
||||
pm := &PathMatcher{Path: p.Path[1:]}
|
||||
add, err := pm.filter(elem)
|
||||
for k, v := range pm.Matches {
|
||||
p.Matches[k] = v
|
||||
}
|
||||
if err != nil || add == nil {
|
||||
return err
|
||||
}
|
||||
p.append(fieldName, add.Content()...)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *PathMatcher) doField(rn *RNode) (*RNode, error) {
|
||||
// lookup the field
|
||||
field, err := rn.Pipe(Get(p.Path[0]))
|
||||
@@ -102,6 +137,36 @@ func (p *PathMatcher) doField(rn *RNode) (*RNode, error) {
|
||||
return p.val, err
|
||||
}
|
||||
|
||||
// doIndexSeq iterates over a sequence and appends elements matching the index p.Val
|
||||
func (p *PathMatcher) doIndexSeq(rn *RNode) (*RNode, error) {
|
||||
// parse to index number
|
||||
idx, err := strconv.Atoi(p.Path[0])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
p.indexNumber = idx
|
||||
|
||||
elements, err := rn.Elements()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// get target element
|
||||
element := elements[idx]
|
||||
|
||||
// recurse on the matching element
|
||||
pm := &PathMatcher{Path: p.Path[1:]}
|
||||
add, err := pm.filter(element)
|
||||
for k, v := range pm.Matches {
|
||||
p.Matches[k] = v
|
||||
}
|
||||
if err != nil || add == nil {
|
||||
return nil, err
|
||||
}
|
||||
p.append("", add.Content()...)
|
||||
return p.val, nil
|
||||
}
|
||||
|
||||
// doSeq iterates over a sequence and appends elements matching the path regex to p.Val
|
||||
func (p *PathMatcher) doSeq(rn *RNode) (*RNode, error) {
|
||||
// parse the field + match pair
|
||||
|
||||
Reference in New Issue
Block a user