Skip to content

Introduce resource-level filter for Receiver#1314

Merged
matheuscscp merged 1 commit into
mainfrom
resource-level-filter
May 23, 2026
Merged

Introduce resource-level filter for Receiver#1314
matheuscscp merged 1 commit into
mainfrom
resource-level-filter

Conversation

@matheuscscp
Copy link
Copy Markdown
Member

@matheuscscp matheuscscp commented May 22, 2026

Follow-up for #1313

CEL expressions get ugly fast (in general).

This PR introduces a .spec.resources[]-level .filter to enhance the readability for filtering CEL expressions in Receiver.

Note: .spec.resourceFilter and .spec.resources[].filter are stacked together i.e. they are AND'd together. If both are set, then both have to return true for a resource to be triggered.

Before this PR:

apiVersion: notification.toolkit.fluxcd.io/v1
kind: Receiver
metadata:
  name: flux-webhook-receiver
  namespace: flux-system
spec:
  type: generic-oidc
  oidcProviders:
    - issuerURL: https://token.actions.githubusercontent.com
      validations:
        - expression: >-
            claims.job_workflow_ref.matches(r"^controlplaneio-fluxcd/d2-fleet/\.github/workflows/push-artifact\.yaml@<< inputs.artifactSubjectGitRef >>$")
            || claims.job_workflow_ref.matches(r"^controlplaneio-fluxcd/flux-appx/\.github/workflows/push-image\.yml@refs/(heads/main|pull/[0-9]+/merge)$")
          message: "token job_workflow_ref is not an allowed d2-fleet/flux-appx workflow"
  resourceFilter: >-
    (claims.repository == 'controlplaneio-fluxcd/d2-fleet' && res.kind == 'OCIRepository') ||
    (claims.repository == 'controlplaneio-fluxcd/flux-appx' && res.kind == 'ResourceSetInputProvider')
  resources:
    - apiVersion: source.toolkit.fluxcd.io/v1
      kind: OCIRepository
      name: flux-system
    - apiVersion: fluxcd.controlplane.io/v1
      kind: ResourceSetInputProvider
      name: '*'
      matchLabels:
        preview: "true"

After this PR:

apiVersion: notification.toolkit.fluxcd.io/v1
kind: Receiver
metadata:
  name: flux-webhook-receiver
  namespace: flux-system
spec:
  type: generic-oidc
  oidcProviders:
    - issuerURL: https://token.actions.githubusercontent.com
      validations:
        - expression: "claims.repository_owner == 'controlplaneio-fluxcd'"
          message: "token is not from the controlplaneio-fluxcd org"
  resources:
    - apiVersion: source.toolkit.fluxcd.io/v1
      kind: OCIRepository
      name: flux-system
      filter: 'claims.job_workflow_ref.matches(r"^controlplaneio-fluxcd/d2-fleet/\.github/workflows/push-artifact\.yaml@<< inputs.artifactSubjectGitRef >>$")'
    - apiVersion: fluxcd.controlplane.io/v1
      kind: ResourceSetInputProvider
      name: '*'
      matchLabels:
        preview: "true"
      filter: 'claims.job_workflow_ref.matches(r"^controlplaneio-fluxcd/flux-appx/\.github/workflows/push-image\.yml@refs/(heads/main|pull/[0-9]+/merge)$")'

@matheuscscp matheuscscp requested a review from stefanprodan May 22, 2026 22:41
@matheuscscp matheuscscp added enhancement New feature or request area/receiver Webhook receiver related issues and PRs labels May 22, 2026
Signed-off-by: Matheus Pimenta <matheuscscp@gmail.com>
@matheuscscp matheuscscp force-pushed the resource-level-filter branch from 5b58c15 to bed3dc5 Compare May 22, 2026 22:52
@matheuscscp
Copy link
Copy Markdown
Member Author

@stefanprodan I successfully tested this API e2e across all my Receiver paths in an EKS fleet with 4 clusters.

Copy link
Copy Markdown
Member

@stefanprodan stefanprodan left a comment

Choose a reason for hiding this comment

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

LGTM

Thanks @matheuscscp 🏅

@matheuscscp matheuscscp merged commit 3847b2e into main May 23, 2026
9 checks passed
@matheuscscp matheuscscp deleted the resource-level-filter branch May 23, 2026 13:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/receiver Webhook receiver related issues and PRs enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants