func (f *filter) Update(evt event.UpdateEvent) bool {
	if evt.ObjectNew != nil {
		return f.run(evt.ObjectNew)
	} else if evt.ObjectOld != nil {
		return f.run(evt.ObjectOld)
	}
	if f.hdlr == nil {
		f.log.Error(nil, "UpdateEvent received with no metadata", "event", evt)
	}
	return f.ret
}
Update implements predicate.Predicate.Update().
package annotation
import (
	"fmt"
	"strconv"
	"github.com/go-logr/logr"
	"k8s.io/apimachinery/pkg/api/validation"
	"k8s.io/apimachinery/pkg/util/validation/field"
	"k8s.io/client-go/util/workqueue"
	"sigs.k8s.io/controller-runtime/pkg/client"
	"sigs.k8s.io/controller-runtime/pkg/event"
	"sigs.k8s.io/controller-runtime/pkg/handler"
	logf "sigs.k8s.io/controller-runtime/pkg/log"
	"sigs.k8s.io/controller-runtime/pkg/predicate"
)
type Options struct {
	Log logr.Logger
	truthy bool
}
func NewFalsyPredicate(key string, opts Options) (predicate.Predicate, error) {
	opts.truthy = false
	return newFilter(key, opts)
}
func NewFalsyEventHandler(key string, opts Options) (handler.EventHandler, error) {
	opts.truthy = false
	return newEventHandler(key, opts)
}
func NewTruthyPredicate(key string, opts Options) (predicate.Predicate, error) {
	opts.truthy = true
	return newFilter(key, opts)
}
func NewTruthyEventHandler(key string, opts Options) (handler.EventHandler, error) {
	opts.truthy = true
	return newEventHandler(key, opts)
}
func defaultOptions(opts *Options) {
	if opts.Log == nil {
		opts.Log = logf.Log
	}
}
func newEventHandler(key string, opts Options) (handler.EventHandler, error) {
	f, err := newFilter(key, opts)
	if err != nil {
		return nil, err
	}
	f.hdlr = &handler.EnqueueRequestForObject{}
	return handler.Funcs{
		CreateFunc: func(evt event.CreateEvent, q workqueue.RateLimitingInterface) {
			if f.Create(evt) {
				f.hdlr.Create(evt, q)
			}
		},
		UpdateFunc: func(evt event.UpdateEvent, q workqueue.RateLimitingInterface) {
			if f.Update(evt) {
				f.hdlr.Update(evt, q)
			}
		},
		DeleteFunc: func(evt event.DeleteEvent, q workqueue.RateLimitingInterface) {
			if f.Delete(evt) {
				f.hdlr.Delete(evt, q)
			}
		},
		GenericFunc: func(evt event.GenericEvent, q workqueue.RateLimitingInterface) {
			if f.Generic(evt) {
				f.hdlr.Generic(evt, q)
			}
		},
	}, nil
}
func newFilter(key string, opts Options) (*filter, error) {
	defaultOptions(&opts)
	if err := validateAnnotation(key, opts.truthy); err != nil {
		return nil, err
	}
	f := filter{}
	f.key = key
	f.ret = !opts.truthy
	f.log = opts.Log.WithName("pause")
	return &f, nil
}
func validateAnnotation(key string, truthy bool) error {
	fldPath := field.NewPath("metadata", "annotations")
	annotation := map[string]string{key: fmt.Sprintf("%v", truthy)}
	return validation.ValidateAnnotations(annotation, fldPath).ToAggregate()
}
type filter struct {
	key  string
	ret  bool
	log  logr.Logger
	hdlr *handler.EnqueueRequestForObject
}
func (f *filter) Create(evt event.CreateEvent) bool {
	if evt.Object == nil {
		if f.hdlr == nil {
			f.log.Error(nil, "CreateEvent received with no metadata", "event", evt)
		}
		return f.ret
	}
	return f.run(evt.Object)
}