Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: watch-processor support watching generic kind (#1873)
## Description We support doing mutates/validates on GenericKinds by allowing the user to add in the GVK manually as the second argument to the `When()`. The problem occurs when the user then tries to watch a resource through `.Watch() or .Reconcile()` then the KFC does not know how to lookup the generic kind because the second argument is not passed to the [k8s function](https://github.com/defenseunicorns/kubernetes-fluent-client/blob/00a7be6c71fb39855e1e2329850c5fa868979576/src/fluent/index.ts#L26). The second point here is that the same GVK look up happening twice, [once](https://github.com/defenseunicorns/pepr/blob/fe7f40df5e062d6b64fd65418a310ce35e2eb975/src/lib/core/capability.ts#L184) in the Capability class when the modules are being transformed into capability exports, and then again when Pepr calls the KFC watch (and KFC watch does a second [lookup](https://github.com/defenseunicorns/kubernetes-fluent-client/blob/00a7be6c71fb39855e1e2329850c5fa868979576/src/fluent/index.ts#L29)). This is an important backstop for KFC since it is its own project and does not rely on Pepr, but in this case, we already have all of the information. The K8s KFC function takes filters that account for `kindOverride`, by adding kindOverride as the kind, then we pass the information from the first GVK lookup OR the GVK from the binding directly to the K8s function. There is no need to consider the kind of the Kubernetes object, whether it is a GenericKind or well known, since the kindOverrides filter will always have the appropriate information, whether from the GVK map or from the GVK argument in `When()`. (Capability adds correct types to binding kind [here](https://github.com/defenseunicorns/pepr/blob/fe7f40df5e062d6b64fd65418a310ce35e2eb975/src/lib/core/capability.ts#L194)) ```ts When(a.GenericKind, { group: "pepr.dev", version: "v1", kind: "Unicorn", }) ``` - [x] **Needs excellent example coverage** [PEXEX](defenseunicorns/pepr-excellent-examples#237) ```bash PASS capabilities/genericKind.e2e.test.ts (46.82 s) genericKind.ts ✓ watches resource creates (542 ms) ✓ watches resource create-or-updates (544 ms) ✓ watches resource updates (568 ms) ✓ watches resource deletes (527 ms) ```   ## Related Issue Fixes #1838 <!-- or --> Relates to # ## Type of change - [x] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Other (security config, docs update, etc) ## Checklist before merging - [x] Unit, [Journey](https://github.com/defenseunicorns/pepr/tree/main/journey), [E2E Tests](https://github.com/defenseunicorns/pepr-excellent-examples), [docs](https://github.com/defenseunicorns/pepr/tree/main/docs), [adr](https://github.com/defenseunicorns/pepr/tree/main/adr) added or updated as needed - [x] [Contributor Guide Steps](https://docs.pepr.dev/main/contribute/#submitting-a-pull-request) followed Signed-off-by: Case Wylie <[email protected]>
- Loading branch information