Skip to content

Commit

Permalink
Merge pull request #1721 from realshuting/webhook_ha
Browse files Browse the repository at this point in the history
Fix variable substitution in NumericOperatorHandler
  • Loading branch information
JimBugwadia committed Mar 18, 2021
2 parents 9a99cc3 + 7502e5d commit 802e6c2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
9 changes: 7 additions & 2 deletions pkg/api/kyverno/v1/utils.go
Expand Up @@ -3,13 +3,18 @@ package v1
import (
"encoding/json"
"reflect"
"strings"
)

// HasAutoGenAnnotation checks if a policy has auto-gen annotation
func (p *ClusterPolicy) HasAutoGenAnnotation() bool {
annotations := p.GetAnnotations()
_, ok := annotations["pod-policies.kyverno.io/autogen-controllers"]
return ok
val, ok := annotations["pod-policies.kyverno.io/autogen-controllers"]
if ok && strings.ToLower(val) != "none" {
return true
}

return false
}

//HasMutateOrValidateOrGenerate checks for rule types
Expand Down
7 changes: 4 additions & 3 deletions pkg/engine/variables/operator/numeric.go
Expand Up @@ -45,12 +45,13 @@ func compareByCondition(key float64, value float64, op kyverno.ConditionOperator
}

func (noh NumericOperatorHandler) Evaluate(key, value interface{}) bool {
if key, err := noh.subHandler(noh.log, noh.ctx, key); err != nil {
var err error
if key, err = noh.subHandler(noh.log, noh.ctx, key); err != nil {
// Failed to resolve the variable
noh.log.Error(err, "Failed to resolve variable", "variable", key)
return false
}
if value, err := noh.subHandler(noh.log, noh.ctx, value); err != nil {
if value, err = noh.subHandler(noh.log, noh.ctx, value); err != nil {
// Failed to resolve the variable
noh.log.Error(err, "Failed to resolve variable", "variable", value)
return false
Expand Down Expand Up @@ -133,7 +134,7 @@ func (noh NumericOperatorHandler) validateValueWithStringPattern(key string, val
if err == nil {
return noh.validateValueWithIntPattern(int64key, value)
}
noh.log.Error(fmt.Errorf("Parse Error: "), "Failed to parse both float64 and int64 from the string keyt")
noh.log.Error(err, "Failed to parse both float64 and int64 from the string keyt")
return false
}

Expand Down

0 comments on commit 802e6c2

Please sign in to comment.