Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: generic-kind e2e #237

Merged
merged 1 commit into from
Feb 25, 2025
Merged

chore: generic-kind e2e #237

merged 1 commit into from
Feb 25, 2025

Conversation

cmwylie19
Copy link
Contributor

Ensures that generic kinds go through admission and be watched over all events.

Signed-off-by: Case Wylie <[email protected]>
Copy link
Contributor

@samayer12 samayer12 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sync discussion & review shows a consistent test with other E2Es

@samayer12 samayer12 merged commit 31c796d into main Feb 25, 2025
2 checks passed
@samayer12 samayer12 deleted the 1838 branch February 25, 2025 21:55
github-merge-queue bot pushed a commit to defenseunicorns/pepr that referenced this pull request Feb 25, 2025
## 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)
 ```

![image](https://github.com/user-attachments/assets/4d7ece44-7936-46db-a2a8-18a36509690b)
![image](https://github.com/user-attachments/assets/1b3b40a4-8eea-4997-bb78-ac7a90e348b2)


## 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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants