Skip to content

Commit f871df7

Browse files
committed
Add jsonpath caching
Signed-off-by: Markus Blaschke <[email protected]>
1 parent 93ac72d commit f871df7

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

config/config.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ type (
2424

2525
PoolConfigSelector struct {
2626
Path string `yaml:"path"`
27+
jsonPath *jsonpath.JSONPath
2728
Match *string `yaml:"match"`
2829
Regexp *string `yaml:"regexp"`
2930
regexp *regexp.Regexp
@@ -49,17 +50,21 @@ func (p *PoolConfig) IsMatchingNode(node *corev1.Node) (bool, error) {
4950
for num, selector := range p.Selector {
5051
// auto compile regexp
5152
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
5455
}
5556

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
6065
}
6166

62-
values, err := jpath.FindResults(node)
67+
values, err := selector.jsonPath.FindResults(node)
6368
if err != nil {
6469
return false, err
6570
}

0 commit comments

Comments
 (0)