mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-31 03:45:17 +00:00
744 added not found error type
This commit is contained in:
parent
43d412039c
commit
3a146a5952
2 changed files with 17 additions and 4 deletions
|
@ -70,6 +70,15 @@ func subArray(log logr.Logger, ctx context.EvalInterface, patternList []interfac
|
|||
return patternList, nil
|
||||
}
|
||||
|
||||
type NotFoundVariableErr struct {
|
||||
variable string
|
||||
path string
|
||||
}
|
||||
|
||||
func (n NotFoundVariableErr) Error() string {
|
||||
return fmt.Sprintf("could not find variable %v at path %v", n.variable, n.path)
|
||||
}
|
||||
|
||||
// subValR resolves the variables if defined
|
||||
func subValR(ctx context.EvalInterface, valuePattern string, path string) (interface{}, error) {
|
||||
originalPattern := valuePattern
|
||||
|
@ -92,7 +101,10 @@ func subValR(ctx context.EvalInterface, valuePattern string, path string) (inter
|
|||
}
|
||||
return nil, fmt.Errorf("failed to resolve %v at path %s", underlyingVariable, path)
|
||||
}
|
||||
return nil, fmt.Errorf("could not find variable %v at path %v", underlyingVariable, path)
|
||||
return nil, NotFoundVariableErr{
|
||||
variable: underlyingVariable,
|
||||
path: path,
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -2,7 +2,6 @@ package policy
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
kyverno "github.com/nirmata/kyverno/pkg/api/kyverno/v1"
|
||||
"github.com/nirmata/kyverno/pkg/engine/context"
|
||||
|
@ -69,12 +68,14 @@ func ContainsVariablesOtherThanObject(policy kyverno.ClusterPolicy) error {
|
|||
|
||||
func checkNotFoundErr(err error) bool {
|
||||
if err != nil {
|
||||
if strings.HasPrefix(err.Error(), "could not find variable") {
|
||||
switch err.(type) {
|
||||
case variables.NotFoundVariableErr:
|
||||
return true
|
||||
} else {
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue