{"modulePath":"github.com/operator-framework/operator-lib","version":"v0.19.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package predicate\n\n## Functions\n\n```go\nfunc NewPause[T client.Object](key string) (predicate.TypedPredicate[T], error)\n```\nNewPause returns a predicate that filters out objects with a truthy \"paused\" annotation. When an annotation with key string key is present on an object and has a truthy value, ex. \"true\", the watch constructed with this predicate will not pass events for that object to the event handler. Key string key must be a valid annotation key.\n\nA note on security: since users that can CRUD a particular API can apply or remove annotations with default cluster admission controllers, this same set of users can therefore start or stop reconciliation of objects via this pause mechanism. If this is a concern, configure an admission webhook to enforce a stricter annotation modification policy. See AdmissionReview configuration for user info available to a webhook: [https://kubernetes.io/docs/reference/access-authn-authz/extensible-admission-controllers/#request](https://kubernetes.io/docs/reference/access-authn-authz/extensible-admission-controllers/#request)\n\n## Types\n\n```go\ntype DependentPredicate struct {\n\tpredicate.Funcs\n}\n```\nDependentPredicate is a predicate that filters events for resources created as dependents of a primary resource. It follows the following rules:\n\n  - Create events are ignored because it is assumed that the controller reconciling the parent is the client creating the dependent resources.\n  - Update events that change only the dependent resource status are ignored because it is not typical for the controller of a primary resource to write to the status of one its dependent resources.\n  - Deletion events are always handled because a controller will typically want to recreate deleted dependent resources if the primary resource is not deleted.\n  - Generic events are ignored.\n\nDependentPredicate is most often used in conjunction with controller-runtime's handler.EnqueueRequestForOwner\n\n```go\nfunc (DependentPredicate) Create(e event.CreateEvent) bool\n```\nCreate filters out all events. It assumes that the controller reconciling the parent is the only client creating the dependent resources.\n\n```go\nfunc (DependentPredicate) Delete(e event.DeleteEvent) bool\n```\nDelete passes all events through. This allows the controller to recreate deleted dependent resources if the primary resource is not deleted.\n\n```go\nfunc (DependentPredicate) Generic(e event.GenericEvent) bool\n```\nGeneric filters out all events.\n\n```go\nfunc (DependentPredicate) Update(e event.UpdateEvent) bool\n```\nUpdate filters out events that change only the dependent resource status. It is not typical for the controller of a primary resource to write to the status of one its dependent resources.\n\n```go\ntype NoGenerationPredicate struct {\n\tpredicate.Funcs\n}\n```\nNoGenerationPredicate implements a update predicate function for objects with no Generation value, like a Pod.\n\nThis predicate will allow update events on objects that never have their metadata.generation field updated by the system, i.e. do not respect Generation semantics: [https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#metadata](https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#metadata) This allows a controller to update objects that may have had their spec changed but, because the object does not use a generation, will inform on that change in some other manner.\n\nThis predicate can be useful by itself, but is intended to be used in conjunction with sigs.k8s.io/controller-runtime/pkg/predicate.GenerationChangedPredicate to allow update events on all potentially changed objects, those that respect Generation semantics or those that do not:\n\n\timport (\n\t\tcorev1 \"k8s.io/api/core/v1\"\n\t\tappsv1 \"k8s.io/api/apps/v1\"\n\t\tctrl \"sigs.k8s.io/controller-runtime\"\n\t\t\"sigs.k8s.io/controller-runtime/pkg/event\"\n\t\tctrlpredicate \"sigs.k8s.io/controller-runtime/pkg/predicate\"\n\t\tlibpredicate \"github.com/operator-framework/operator-lib/predicate\"\n\n\t\t\"github.com/example/my-operator/api/v1alpha1\"\n\t)\n\n\tfunc (r *MyTypeReconciler) SetupWithManager(mgr ctrl.Manager) error {\n\t\treturn ctrl.NewControllerManagedBy(mgr).\n\t\t\tFor(\u0026v1alpha1.MyType{}).\n\t\t\tOwns(\u0026corev1.Pod{}).\t\t\t\t// Does not respect Generation.\n\t\t\tOwns(\u0026appsv1.Deployment{}).\t// Respects Generation.\n\t\t\tWithEventFilter(ctrlpredicate.Or(ctrlpredicate.GenerationChangedPredicate{}, libpredicate.NoGenerationPredicate{})).\n\t\t\tComplete(r)\n\t}\n\n```go\nfunc (NoGenerationPredicate) Update(e event.UpdateEvent) bool\n```\nUpdate implements the default UpdateEvent filter for validating absence Generation.\n\n","path":"github.com/operator-framework/operator-lib/predicate","name":"predicate","synopsis":"","isRedistributable":true}
