1
0
Fork 0
mirror of https://github.com/kubernetes-sigs/node-feature-discovery.git synced 2025-03-31 04:04:51 +00:00

Merge pull request #1482 from marquiz/devel/api-cleanup-2

apis/nfd: drop the private regexp caching field
This commit is contained in:
Kubernetes Prow Robot 2023-12-14 12:08:58 +01:00 committed by GitHub
commit 3ce5a1b218
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 42 deletions

View file

@ -42,8 +42,6 @@ var matchOps = map[MatchOp]struct{}{
MatchIsFalse: {},
}
type valueRegexpCache []*regexp.Regexp
// CreateMatchExpression creates a new MatchExpression instance. Returns an
// error if validation fails.
func CreateMatchExpression(op MatchOp, values ...string) (*MatchExpression, error) {
@ -71,8 +69,6 @@ func newMatchExpression(op MatchOp, values ...string) *MatchExpression {
// Validate validates the expression.
func (m *MatchExpression) Validate() error {
m.valueRe = nil
if _, ok := matchOps[m.Op]; !ok {
return fmt.Errorf("invalid Op %q", m.Op)
}
@ -106,13 +102,11 @@ func (m *MatchExpression) Validate() error {
if len(m.Value) == 0 {
return fmt.Errorf("value must be non-empty for Op %q", m.Op)
}
m.valueRe = make([]*regexp.Regexp, len(m.Value))
for i, v := range m.Value {
re, err := regexp.Compile(v)
for _, v := range m.Value {
_, err := regexp.Compile(v)
if err != nil {
return fmt.Errorf("value must only contain valid regexps for Op %q (have %v)", m.Op, m.Value)
}
m.valueRe[i] = re
}
default:
if len(m.Value) == 0 {
@ -172,18 +166,15 @@ func (m *MatchExpression) Match(valid bool, value interface{}) (bool, error) {
if len(m.Value) == 0 {
return false, fmt.Errorf("invalid expression, 'value' field must be non-empty for Op %q", m.Op)
}
if m.valueRe == nil {
m.valueRe = make([]*regexp.Regexp, len(m.Value))
for i, v := range m.Value {
re, err := regexp.Compile(v)
if err != nil {
m.valueRe = nil
return false, fmt.Errorf("invalid expressiom, 'value' field must only contain valid regexps for Op %q (have %v)", m.Op, m.Value)
}
m.valueRe[i] = re
valueRe := make([]*regexp.Regexp, len(m.Value))
for i, v := range m.Value {
re, err := regexp.Compile(v)
if err != nil {
return false, fmt.Errorf("invalid expressiom, 'value' field must only contain valid regexps for Op %q (have %v)", m.Op, m.Value)
}
valueRe[i] = re
}
for _, re := range m.valueRe {
for _, re := range valueRe {
if re.MatchString(value) {
return true, nil
}
@ -488,23 +479,3 @@ func (m *MatchValue) UnmarshalJSON(data []byte) error {
return nil
}
// DeepCopy supplements the auto-generated code
func (in *valueRegexpCache) DeepCopy() *valueRegexpCache {
if in == nil {
return nil
}
out := new(valueRegexpCache)
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is a stub to augment the auto-generated code
//
//nolint:staticcheck // re.Copy is deprecated but we want to use it here
func (in *valueRegexpCache) DeepCopyInto(out *valueRegexpCache) {
*out = make(valueRegexpCache, len(*in))
for i, re := range *in {
(*out)[i] = re.Copy()
}
}

View file

@ -226,9 +226,6 @@ type MatchExpression struct {
// In other cases Value should contain at least one element.
// +optional
Value MatchValue `json:"value,omitempty"`
// valueRe caches compiled regexps for "InRegexp" operator
valueRe valueRegexpCache `json:"-"`
}
// MatchOp is the match operator that is applied on values when evaluating a

View file

@ -215,7 +215,6 @@ func (in *MatchExpression) DeepCopyInto(out *MatchExpression) {
*out = make(MatchValue, len(*in))
copy(*out, *in)
}
in.valueRe.DeepCopyInto(&out.valueRe)
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MatchExpression.