File tree Expand file tree Collapse file tree 1 file changed +12
-7
lines changed Expand file tree Collapse file tree 1 file changed +12
-7
lines changed Original file line number Diff line number Diff line change 24
24
25
25
PoolConfigSelector struct {
26
26
Path string `yaml:"path"`
27
+ jsonPath * jsonpath.JSONPath
27
28
Match * string `yaml:"match"`
28
29
Regexp * string `yaml:"regexp"`
29
30
regexp * regexp.Regexp
@@ -49,17 +50,21 @@ func (p *PoolConfig) IsMatchingNode(node *corev1.Node) (bool, error) {
49
50
for num , selector := range p .Selector {
50
51
// auto compile regexp
51
52
if selector .Regexp != nil {
52
- p . Selector [ num ] .regexp = regexp .MustCompile (* selector .Regexp )
53
- selector . regexp = p .Selector [num ].regexp
53
+ selector .regexp = regexp .MustCompile (* selector .Regexp )
54
+ p .Selector [num ]. regexp = selector .regexp
54
55
}
55
56
56
- jpath := jsonpath .New (p .Name )
57
- jpath .AllowMissingKeys (true )
58
- if err := jpath .Parse (selector .Path ); err != nil {
59
- return false , err
57
+ // auto compile json path
58
+ if selector .jsonPath == nil {
59
+ selector .jsonPath = jsonpath .New (p .Name )
60
+ selector .jsonPath .AllowMissingKeys (true )
61
+ if err := selector .jsonPath .Parse (selector .Path ); err != nil {
62
+ return false , err
63
+ }
64
+ p .Selector [num ].jsonPath = selector .jsonPath
60
65
}
61
66
62
- values , err := jpath .FindResults (node )
67
+ values , err := selector . jsonPath .FindResults (node )
63
68
if err != nil {
64
69
return false , err
65
70
}
You can’t perform that action at this time.
0 commit comments