Skip to content

Conversation

@markomirosavljev
Copy link

@markomirosavljev markomirosavljev commented Dec 27, 2025

Closes #25804

Summary

This PR adds 2 additional filters in applicationSet PR generator, createdWithin and updatedWithin which allow PR filtering based on time after they are created, or last time updated.

Motivation

  • In cases we have lots of applicationsets creating review envs using PR generator, we can end up having lots of apps that are created based off stale PRs on repositories that are not being worked on atm. This filtering can prevent ArgoCD from creating apps for PRs older than specific duration, or that are not updated within specific time duration.

Implementation

  • Added createdAt and updatedAt field to pull request parameters - both parsed from values returned by SCM APIs and will also be available for templating
  • Added createdWithin and updatedWithin filters on applicationset CRD and updated filtering functions to parse time.Duration from CRD while compiling and applying filters to applicationset.
  • createdWithin will take precedence over updatedWithin when filtering PRs
  • Updated test cases to cover new fields in PR parameters, and extended test cases with filtering cases.

Manifests will look like this:

apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
  annotations:
    kubectl.kubernetes.io/last-applied-configuration: |
      ....
  creationTimestamp: "2025-12-27T10:55:06Z"
  generation: 2
  name: pr-preview-apps
  namespace: argocd
  resourceVersion: "48678"
  uid: 5d376305-51f7-4fd3-8ee4-3e4c8b47daae
spec:
  generators:
  - pullRequest:
      filters:
      - createdWithin: 168h
      - updatedWithin: 24h
      github:
        labels:
        - preview
        owner: ownerorg
        repo: core
        tokenRef:
          key: password
          secretName: creds-3812896623
      requeueAfterSeconds: 120
  template:
    metadata:
      annotations:
        pr-createdat: '{{created_at}}'
        pr-updatedat: '{{updated_at}}'
      labels:
        app-type: pr-preview
        pr-number: '{{number}}'
      name: pr-{{number}}-preview
    spec:
      destination:
        namespace: pr-{{number}}
        server: https://kubernetes.default.svc
      project: default
      source:
        path: charts/core
        repoURL: https://github.com/ownerorg/core.git
        targetRevision: '{{head_sha}}'
      syncPolicy:
        automated:
          prune: true
          selfHeal: true
        syncOptions:
        - CreateNamespace=true

Checklist:

  • Either (a) I've created an enhancement proposal and discussed it with the community, (b) this is a bug fix, or (c) this does not need to be in the release notes.
  • The title of the PR states what changed and the related issues number (used for the release note).
  • The title of the PR conforms to the Title of the PR
  • I've included "Closes [ISSUE #]" or "Fixes [ISSUE #]" in the description to automatically close the associated issue.
  • I've updated both the CLI and UI to expose my feature, or I plan to submit a second PR with them.
  • Does this PR require documentation updates?
  • I've updated documentation as required by this PR.
  • I have signed off all my commits as required by DCO
  • I have written unit and/or e2e tests for my change. PRs without these are unlikely to be merged.
  • My build is green (troubleshooting builds).
  • My new feature complies with the feature status guidelines.
  • I have added a brief description of why this PR is necessary and/or what this PR solves.
  • Optional. My organization is added to USERS.md.
  • Optional. For bug fixes, I've indicated what older releases this fix should be cherry-picked into (this may or may not happen depending on risk/complexity).

@markomirosavljev markomirosavljev requested a review from a team as a code owner December 27, 2025 11:42
@bunnyshell
Copy link

bunnyshell bot commented Dec 27, 2025

❗ Preview Environment stop on Bunnyshell failed

See: Environment Details | Pipeline Logs

Available commands (reply to this comment):

  • 🔴 /bns:stop to stop again the environment
  • 🔵 /bns:start to start the environment
  • 🚀 /bns:deploy to redeploy the environment
  • /bns:delete to remove the environment

Labels: getGithubPRLabelNames(pull.Labels),
Author: *pull.User.Login,
CreatedAt: pull.CreatedAt.Time,
UpdatedAt: pull.UpdatedAt.Time,
Copy link
Member

Choose a reason for hiding this comment

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

are there no tests where we can add these fields? I see that we have tests for other providers that you edited to add the timestamp field but not for GitHub.

Copy link
Author

Choose a reason for hiding this comment

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

That is correct. I've just added additional test cases for Github PR generator service.

Copy link
Member

@nitishfy nitishfy left a comment

Choose a reason for hiding this comment

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

Please fix the conflicts.

@markomirosavljev markomirosavljev requested review from a team as code owners December 28, 2025 13:09
Signed-off-by: Marko Mirosavljev <mirosavljevm023@gmail.com>
Signed-off-by: Marko Mirosavljev <mirosavljevm023@gmail.com>
Signed-off-by: Marko Mirosavljev <mirosavljevm023@gmail.com>
Signed-off-by: Marko Mirosavljev <mirosavljevm023@gmail.com>
Signed-off-by: Marko Mirosavljev <mirosavljevm023@gmail.com>
@markomirosavljev
Copy link
Author

Please fix the conflicts.

Conflicts resolved @nitishfy

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.

ApplicationSet PR generator time based filters

2 participants