mirror of
https://github.com/kyverno/kyverno.git
synced 2024-12-14 11:57:48 +00:00
give public access to PreProcessPattern (#9887)
Signed-off-by: Arnaud Tournier <ltearno@gmail.com>
This commit is contained in:
parent
befcd73ea1
commit
1e09f22e59
3 changed files with 6 additions and 6 deletions
|
@ -57,7 +57,7 @@ func preProcessStrategicMergePatch(logger logr.Logger, pattern, resource string)
|
|||
patternNode := yaml.MustParse(pattern)
|
||||
resourceNode := yaml.MustParse(resource)
|
||||
|
||||
err := preProcessPattern(logger, patternNode, resourceNode)
|
||||
err := PreProcessPattern(logger, patternNode, resourceNode)
|
||||
|
||||
return patternNode, err
|
||||
}
|
||||
|
|
|
@ -44,7 +44,7 @@ func NewGlobalConditionError(err error) error {
|
|||
// A parent node having MappingNode keeps the data as <keyNode>, <ValueNode> inside it's Content field and Tag field as "!!map".
|
||||
// A parent node having Sequence keeps the data as array of Node inside Content field and a Tag field as "!!seq".
|
||||
// https://github.com/kubernetes-sigs/kustomize/blob/master/kyaml/yaml/rnode.go
|
||||
func preProcessPattern(logger logr.Logger, pattern, resource *yaml.RNode) error {
|
||||
func PreProcessPattern(logger logr.Logger, pattern, resource *yaml.RNode) error {
|
||||
err := preProcessRecursive(logger, pattern, resource)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
@ -1208,7 +1208,7 @@ func Test_ConditionCheck_SeveralElementsMatchExceptOne(t *testing.T) {
|
|||
pattern := yaml.MustParse(string(patternRaw))
|
||||
containers := yaml.MustParse(string(containersRaw))
|
||||
|
||||
err := preProcessPattern(logr.Discard(), pattern, containers)
|
||||
err := PreProcessPattern(logr.Discard(), pattern, containers)
|
||||
assert.NilError(t, err)
|
||||
|
||||
patternContainers := pattern.Field("containers")
|
||||
|
@ -1261,7 +1261,7 @@ func Test_NonExistingKeyMustFailPreprocessing(t *testing.T) {
|
|||
|
||||
pattern := yaml.MustParse(string(rawPattern))
|
||||
resource := yaml.MustParse(string(rawResource))
|
||||
err := preProcessPattern(logr.Discard(), pattern, resource)
|
||||
err := PreProcessPattern(logr.Discard(), pattern, resource)
|
||||
assert.Error(t, err, "condition failed: could not found \"key1\" key in the resource")
|
||||
}
|
||||
|
||||
|
@ -1272,7 +1272,7 @@ func Test_NestedConditionals(t *testing.T) {
|
|||
|
||||
pattern := yaml.MustParse(rawPattern)
|
||||
resource := yaml.MustParse(rawResource)
|
||||
err := preProcessPattern(logr.Discard(), pattern, resource)
|
||||
err := PreProcessPattern(logr.Discard(), pattern, resource)
|
||||
assert.NilError(t, err)
|
||||
resultPattern, _ := pattern.String()
|
||||
|
||||
|
@ -1312,6 +1312,6 @@ func Test_GlobalCondition_Fail(t *testing.T) {
|
|||
|
||||
pattern := yaml.MustParse(string(rawPattern))
|
||||
resource := yaml.MustParse(string(rawResource))
|
||||
err := preProcessPattern(logr.Discard(), pattern, resource)
|
||||
err := PreProcessPattern(logr.Discard(), pattern, resource)
|
||||
assert.Error(t, err, "global condition failed: could not found \"emptyDir\" key in the resource")
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue