mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-31 03:45:17 +00:00
remove unused ctx (#6725)
Signed-off-by: ShutingZhao <shuting@nirmata.com>
This commit is contained in:
parent
43811733dc
commit
805f7b72a9
4 changed files with 15 additions and 17 deletions
|
@ -46,13 +46,13 @@ func ForceMutate(
|
|||
}
|
||||
|
||||
if r.Mutation.ForEachMutation != nil {
|
||||
patchedResource, err = applyForEachMutate(r.Name, r.Mutation.ForEachMutation, patchedResource, ctx, logger)
|
||||
patchedResource, err = applyForEachMutate(r.Name, r.Mutation.ForEachMutation, patchedResource, logger)
|
||||
if err != nil {
|
||||
return patchedResource, err
|
||||
}
|
||||
} else {
|
||||
m := r.Mutation
|
||||
patchedResource, err = applyPatches(r.Name, m.GetPatchStrategicMerge(), m.PatchesJSON6902, patchedResource, ctx, logger)
|
||||
patchedResource, err = applyPatches(r.Name, m.GetPatchStrategicMerge(), m.PatchesJSON6902, patchedResource, logger)
|
||||
if err != nil {
|
||||
return patchedResource, err
|
||||
}
|
||||
|
@ -62,7 +62,7 @@ func ForceMutate(
|
|||
return patchedResource, nil
|
||||
}
|
||||
|
||||
func applyForEachMutate(name string, foreach []kyvernov1.ForEachMutation, resource unstructured.Unstructured, ctx context.Interface, logger logr.Logger) (patchedResource unstructured.Unstructured, err error) {
|
||||
func applyForEachMutate(name string, foreach []kyvernov1.ForEachMutation, resource unstructured.Unstructured, logger logr.Logger) (patchedResource unstructured.Unstructured, err error) {
|
||||
patchedResource = resource
|
||||
for _, fe := range foreach {
|
||||
if fe.ForEachMutation != nil {
|
||||
|
@ -71,10 +71,10 @@ func applyForEachMutate(name string, foreach []kyvernov1.ForEachMutation, resour
|
|||
return patchedResource, fmt.Errorf("failed to deserialize foreach: %w", err)
|
||||
}
|
||||
|
||||
return applyForEachMutate(name, nestedForEach, patchedResource, ctx, logger)
|
||||
return applyForEachMutate(name, nestedForEach, patchedResource, logger)
|
||||
}
|
||||
|
||||
patchedResource, err = applyPatches(name, fe.GetPatchStrategicMerge(), fe.PatchesJSON6902, patchedResource, ctx, logger)
|
||||
patchedResource, err = applyPatches(name, fe.GetPatchStrategicMerge(), fe.PatchesJSON6902, patchedResource, logger)
|
||||
if err != nil {
|
||||
return resource, err
|
||||
}
|
||||
|
@ -83,8 +83,8 @@ func applyForEachMutate(name string, foreach []kyvernov1.ForEachMutation, resour
|
|||
return patchedResource, nil
|
||||
}
|
||||
|
||||
func applyPatches(name string, mergePatch apiextensions.JSON, jsonPatch string, resource unstructured.Unstructured, ctx context.Interface, logger logr.Logger) (unstructured.Unstructured, error) {
|
||||
patcher := mutate.NewPatcher(name, mergePatch, jsonPatch, resource, ctx, logger)
|
||||
func applyPatches(name string, mergePatch apiextensions.JSON, jsonPatch string, resource unstructured.Unstructured, logger logr.Logger) (unstructured.Unstructured, error) {
|
||||
patcher := mutate.NewPatcher(name, mergePatch, jsonPatch, resource, logger)
|
||||
resp, mutatedResource := patcher.Patch()
|
||||
if resp.Status != engineapi.RuleStatusPass {
|
||||
return mutatedResource, fmt.Errorf("mutate status %q: %s", resp.Status, resp.Message)
|
||||
|
|
|
@ -144,7 +144,7 @@ func (f *forEachMutator) mutateElements(ctx context.Context, foreach kyvernov1.F
|
|||
|
||||
mutateResp = m.mutateForEach(ctx)
|
||||
} else {
|
||||
mutateResp = mutate.ForEach(f.rule.Name, foreach, policyContext.JSONContext(), patchedResource.unstructured, f.log)
|
||||
mutateResp = mutate.ForEach(f.rule.Name, foreach, policyContext, patchedResource.unstructured, element, f.log)
|
||||
}
|
||||
|
||||
if mutateResp.Status == engineapi.RuleStatusFail || mutateResp.Status == engineapi.RuleStatusError {
|
||||
|
|
|
@ -42,7 +42,7 @@ func Mutate(rule *kyvernov1.Rule, ctx context.Interface, resource unstructured.U
|
|||
}
|
||||
|
||||
m := updatedRule.Mutation
|
||||
patcher := NewPatcher(updatedRule.Name, m.GetPatchStrategicMerge(), m.PatchesJSON6902, resource, ctx, logger)
|
||||
patcher := NewPatcher(updatedRule.Name, m.GetPatchStrategicMerge(), m.PatchesJSON6902, resource, logger)
|
||||
if patcher == nil {
|
||||
return NewResponse(engineapi.RuleStatusError, resource, nil, "empty mutate rule")
|
||||
}
|
||||
|
@ -69,13 +69,14 @@ func Mutate(rule *kyvernov1.Rule, ctx context.Interface, resource unstructured.U
|
|||
return NewResponse(engineapi.RuleStatusPass, patchedResource, resp.Patches, resp.Message)
|
||||
}
|
||||
|
||||
func ForEach(name string, foreach kyvernov1.ForEachMutation, ctx context.Interface, resource unstructured.Unstructured, logger logr.Logger) *Response {
|
||||
func ForEach(name string, foreach kyvernov1.ForEachMutation, policyContext engineapi.PolicyContext, resource unstructured.Unstructured, element interface{}, logger logr.Logger) *Response {
|
||||
ctx := policyContext.JSONContext()
|
||||
fe, err := substituteAllInForEach(foreach, ctx, logger)
|
||||
if err != nil {
|
||||
return NewErrorResponse("variable substitution failed", err)
|
||||
}
|
||||
|
||||
patcher := NewPatcher(name, fe.GetPatchStrategicMerge(), fe.PatchesJSON6902, resource, ctx, logger)
|
||||
patcher := NewPatcher(name, fe.GetPatchStrategicMerge(), fe.PatchesJSON6902, resource, logger)
|
||||
if patcher == nil {
|
||||
return NewResponse(engineapi.RuleStatusError, unstructured.Unstructured{}, nil, "no patches found")
|
||||
}
|
||||
|
@ -120,9 +121,9 @@ func substituteAllInForEach(fe kyvernov1.ForEachMutation, ctx context.Interface,
|
|||
return &updatedForEach, nil
|
||||
}
|
||||
|
||||
func NewPatcher(name string, strategicMergePatch apiextensions.JSON, jsonPatch string, r unstructured.Unstructured, ctx context.Interface, logger logr.Logger) patch.Patcher {
|
||||
func NewPatcher(name string, strategicMergePatch apiextensions.JSON, jsonPatch string, r unstructured.Unstructured, logger logr.Logger) patch.Patcher {
|
||||
if strategicMergePatch != nil {
|
||||
return patch.NewPatchStrategicMerge(name, strategicMergePatch, r, ctx, logger)
|
||||
return patch.NewPatchStrategicMerge(name, strategicMergePatch, r, logger)
|
||||
}
|
||||
|
||||
if len(jsonPatch) > 0 {
|
||||
|
|
|
@ -3,7 +3,6 @@ package patch
|
|||
import (
|
||||
"github.com/go-logr/logr"
|
||||
engineapi "github.com/kyverno/kyverno/pkg/engine/api"
|
||||
"github.com/kyverno/kyverno/pkg/engine/context"
|
||||
"k8s.io/apiextensions-apiserver/pkg/apis/apiextensions"
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||
)
|
||||
|
@ -18,16 +17,14 @@ type patchStrategicMergeHandler struct {
|
|||
ruleName string
|
||||
patch apiextensions.JSON
|
||||
patchedResource unstructured.Unstructured
|
||||
evalCtx context.EvalInterface
|
||||
logger logr.Logger
|
||||
}
|
||||
|
||||
func NewPatchStrategicMerge(ruleName string, patch apiextensions.JSON, patchedResource unstructured.Unstructured, context context.EvalInterface, logger logr.Logger) Patcher {
|
||||
func NewPatchStrategicMerge(ruleName string, patch apiextensions.JSON, patchedResource unstructured.Unstructured, logger logr.Logger) Patcher {
|
||||
return patchStrategicMergeHandler{
|
||||
ruleName: ruleName,
|
||||
patch: patch,
|
||||
patchedResource: patchedResource,
|
||||
evalCtx: context,
|
||||
logger: logger,
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue