func NewGlobalAnchorHandler(anchor string, pattern interface{}, path string) ValidationHandler {
	return GlobalAnchorHandler{
		anchor:  anchor,
		pattern: pattern,
		path:    path,
	}
}
NewGlobalAnchorHandler returns an instance of condition acnhor handler
package anchor
import (
	"fmt"
	"strconv"
	"github.com/go-logr/logr"
	commonAnchors "github.com/kyverno/kyverno/pkg/engine/anchor/common"
	"github.com/kyverno/kyverno/pkg/engine/common"
	"sigs.k8s.io/controller-runtime/pkg/log"
)
type ValidationHandler interface {
	Handle(handler resourceElementHandler, resourceMap map[string]interface{}, originPattern interface{}, ac *common.AnchorKey) (string, error)
}
type resourceElementHandler = func(log logr.Logger, resourceElement, patternElement, originPattern interface{}, path string, ac *common.AnchorKey) (string, error)
func CreateElementHandler(element string, pattern interface{}, path string) ValidationHandler {
	switch {
	case commonAnchors.IsConditionAnchor(element):
		return NewConditionAnchorHandler(element, pattern, path)
	case commonAnchors.IsGlobalAnchor(element):
		return NewGlobalAnchorHandler(element, pattern, path)
	case commonAnchors.IsExistenceAnchor(element):
		return NewExistenceHandler(element, pattern, path)
	case commonAnchors.IsEqualityAnchor(element):
		return NewEqualityHandler(element, pattern, path)
	case commonAnchors.IsNegationAnchor(element):
		return NewNegationHandler(element, pattern, path)
	default:
		return NewDefaultHandler(element, pattern, path)
	}
}
func NewNegationHandler(anchor string, pattern interface{}, path string) ValidationHandler {
	return NegationHandler{
		anchor:  anchor,
		pattern: pattern,
		path:    path,
	}
}
type NegationHandler struct {
	anchor  string
	pattern interface{}
	path    string
}
func (nh NegationHandler) Handle(handler resourceElementHandler, resourceMap map[string]interface{}, originPattern interface{}, ac *common.AnchorKey) (string, error) {
	anchorKey, _ := commonAnchors.RemoveAnchor(nh.anchor)
	currentPath := nh.path + anchorKey + "/"
	if _, ok := resourceMap[anchorKey]; ok {
		return currentPath, fmt.Errorf("%s/%s is not allowed", currentPath, anchorKey)
	}
	return "", nil
}
func NewEqualityHandler(anchor string, pattern interface{}, path string) ValidationHandler {
	return EqualityHandler{
		anchor:  anchor,
		pattern: pattern,
		path:    path,
	}
}
type EqualityHandler struct {
	anchor  string
	pattern interface{}
	path    string
}
func (eh EqualityHandler) Handle(handler resourceElementHandler, resourceMap map[string]interface{}, originPattern interface{}, ac *common.AnchorKey) (string, error) {
	anchorKey, _ := commonAnchors.RemoveAnchor(eh.anchor)
	currentPath := eh.path + anchorKey + "/"
	if value, ok := resourceMap[anchorKey]; ok {
		returnPath, err := handler(log.Log, value, eh.pattern, originPattern, currentPath, ac)
		if err != nil {
			return returnPath, err
		}
		return "", nil
	}
	return "", nil
}
func NewDefaultHandler(element string, pattern interface{}, path string) ValidationHandler {
	return DefaultHandler{
		element: element,
		pattern: pattern,
		path:    path,
	}
}
type DefaultHandler struct {
	element string
	pattern interface{}
	path    string
}
func (dh DefaultHandler) Handle(handler resourceElementHandler, resourceMap map[string]interface{}, originPattern interface{}, ac *common.AnchorKey) (string, error) {
	currentPath := dh.path + dh.element + "/"
	if dh.pattern == "*" && resourceMap[dh.element] != nil {
		return "", nil
	} else if dh.pattern == "*" && resourceMap[dh.element] == nil {
		return dh.path, fmt.Errorf("%s/%s not found", dh.path, dh.element)
	} else {
		path, err := handler(log.Log, resourceMap[dh.element], dh.pattern, originPattern, currentPath, ac)
		if err != nil {
			return path, err
		}
	}
	return "", nil
}
func NewConditionAnchorHandler(anchor string, pattern interface{}, path string) ValidationHandler {
	return ConditionAnchorHandler{
		anchor:  anchor,
		pattern: pattern,
		path:    path,
	}
}
type ConditionAnchorHandler struct {
	anchor  string
	pattern interface{}
	path    string
}
func (ch ConditionAnchorHandler) Handle(handler resourceElementHandler, resourceMap map[string]interface{}, originPattern interface{}, ac *common.AnchorKey) (string, error) {
	anchorKey, _ := commonAnchors.RemoveAnchor(ch.anchor)
	currentPath := ch.path + anchorKey + "/"
	if value, ok := resourceMap[anchorKey]; ok {
		returnPath, err := handler(log.Log, value, ch.pattern, originPattern, currentPath, ac)
		if err != nil {
			ac.AnchorError = common.NewConditionalAnchorError(err.Error())
			return returnPath, ac.AnchorError.Error()
		}
		return "", nil
	}
	return "", nil
}