func ApplyPatches(resource []byte, patches [][]byte) ([]byte, error) {
	joinedPatches := JoinPatches(patches)
	patch, err := jsonpatch.DecodePatch(joinedPatches)
	if err != nil {
		log.Log.V(4).Info("failed to decode JSON patch", "patch", patch)
		return resource, err
	}
	patchedDocument, err := patch.Apply(resource)
	if err != nil {
		log.Log.V(4).Info("failed to apply JSON patch", "patch", patch)
		return resource, err
	}
	log.Log.V(4).Info("applied JSON patch", "patch", patch)
	return patchedDocument, err
}
ApplyPatches patches given resource with given patches and returns patched document
return original resource if any error occurs
package utils
import (
	"fmt"
	jsonpatch "github.com/evanphx/json-patch/v5"
	commonAnchor "github.com/kyverno/kyverno/pkg/engine/anchor/common"
	"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
	"sigs.k8s.io/controller-runtime/pkg/log"
	"strconv"
	"strings"
)
type RuleType int
const (
	Mutation RuleType = iota
	Validation
	Generation
	ImageVerify
)
func (ri RuleType) String() string {
	return [...]string{
		"Mutation",
		"Validation",
		"Generation",
		"All",
	}[ri]
}