mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-29 02:45:06 +00:00
fix: Result not correct when testing a mutate rule and foreach. (#7396)
* fix: Result not correct when testing a mutate rule and foreach Signed-off-by: Mariam Fahmy <mariamfahmy66@gmail.com> * fix: result not correct when testing a mutate rule and foreach Signed-off-by: Mariam Fahmy <mariamfahmy66@gmail.com> * use comparison to detect skip vs pass Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> * fix test Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> --------- Signed-off-by: Mariam Fahmy <mariamfahmy66@gmail.com> Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> Co-authored-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
This commit is contained in:
parent
bc35700e29
commit
44310b2e5a
3 changed files with 9 additions and 15 deletions
|
@ -12,6 +12,7 @@ import (
|
|||
"github.com/kyverno/kyverno/pkg/engine/mutate"
|
||||
engineutils "github.com/kyverno/kyverno/pkg/engine/utils"
|
||||
"github.com/kyverno/kyverno/pkg/utils/api"
|
||||
datautils "github.com/kyverno/kyverno/pkg/utils/data"
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||
)
|
||||
|
||||
|
@ -76,6 +77,7 @@ func (f *forEachMutator) mutateElements(ctx context.Context, foreach kyvernov1.F
|
|||
if reverse {
|
||||
engineutils.InvertedElement(elements)
|
||||
}
|
||||
|
||||
for index, element := range elements {
|
||||
if element == nil {
|
||||
continue
|
||||
|
@ -135,7 +137,12 @@ func (f *forEachMutator) mutateElements(ctx context.Context, foreach kyvernov1.F
|
|||
patchedResource.unstructured = mutateResp.PatchedResource
|
||||
}
|
||||
}
|
||||
return mutate.NewResponse(engineapi.RuleStatusPass, patchedResource.unstructured, "")
|
||||
|
||||
if !datautils.DeepEqual(f.resource.unstructured, patchedResource.unstructured) {
|
||||
return mutate.NewResponse(engineapi.RuleStatusPass, patchedResource.unstructured, "")
|
||||
}
|
||||
|
||||
return mutate.NewResponse(engineapi.RuleStatusSkip, patchedResource.unstructured, "no patches applied")
|
||||
}
|
||||
|
||||
func buildRuleResponse(rule *kyvernov1.Rule, mutateResp *mutate.Response, info resourceInfo) *engineapi.RuleResponse {
|
||||
|
|
|
@ -19,6 +19,5 @@ results:
|
|||
- policy: keda-prometheus-serveraddress
|
||||
rule: keda-prometheus-serveraddress
|
||||
resources: [service-3]
|
||||
patchedResource: patchedResource3.yaml
|
||||
kind: ScaledObject
|
||||
result: pass
|
||||
result: skip
|
||||
|
|
|
@ -1,12 +0,0 @@
|
|||
apiVersion: keda.sh/v1alpha1
|
||||
kind: ScaledObject
|
||||
metadata:
|
||||
name: service-3
|
||||
namespace: default
|
||||
spec:
|
||||
triggers:
|
||||
- type: "aws-sqs-queue"
|
||||
metadata:
|
||||
queueURL: https://sqs.eu-west-1.amazonaws.com/account_id/QueueName
|
||||
queueLength: "5"
|
||||
awsRegion: "eu-west-1"
|
Loading…
Add table
Reference in a new issue