Skip to content

Commit

Permalink
docs.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
docs.yml committed Aug 30, 2024
1 parent f2538cc commit e5351c8
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions site/content/en/main/user-guide/filters.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
title: Pepr Filters
weight: 130
---


Filters are functions that take a `AdmissionReview` or Watch event and return a boolean. They are used to filter out resources that do not meet certain criteria. Filters are used in the package to filter out resources that are not relevant to the user-defined admission or watch process.

```ts
When(a.ConfigMap)
// This limits the action to only act on new resources.
.IsCreated()
// Namespace filter
.InNamespace("webapp")
// Name filter
.WithName("example-1")
// Label filter
.WithLabel("app", "webapp")
.WithLabel("env", "prod")
.Mutate(request => {
request
.SetLabel("pepr", "was-here")
.SetAnnotation("pepr.dev", "annotations-work-too");
});
```


## `Filters`

- `.WithName("name")`: Filters resources by name.
- `.InNamespace("namespace")`: Filters resources by namespace.
- `.WithLabel("key", "value")`: Filters resources by label. (Can be multiple)
- `.WithDeletionTimestamp()`: Filters resources that have a deletion timestamp.

Notes:
- `WithDeletionTimestamp()` is does not work on Delete through the `Mutate` or `Validate` methods because the Kubernetes Admission Process does not fire the DELETE event with a deletion timestamp on the resource.
- `WithDeletionTimestamp()` _will_ match on an Update event during Admission (`Mutate` or `Validate`) when pending-deletion permitted changes (like removing a finalizer) occur.

0 comments on commit e5351c8

Please sign in to comment.