argoproj / argo-cd

Declarative Continuous Deployment for Kubernetes
https://argo-cd.readthedocs.io
Apache License 2.0
17.42k stars 5.29k forks source link

[ApplicationSet] scmProvider generator: webhook support for topic/label updates #19689

Open ejhayes opened 2 weeks ago

ejhayes commented 2 weeks ago

Summary

Add webhook support for GitHub topic updates. This can be specified in the scmProvider generator but cannot receive updates via webhook notifications.

Motivation

Being able to add/remove apps based on topic is very useful but updates are often slow. Sure we could increase polling frequency but it'd be even more lightweight to add support for repository events!

Proposal

Here's an example ApplicationSet that uses a labelMatch filter.

apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
  name: test-appset
spec:
  generators:
  - scmProvider:
      filters:
        - labelMatch: someLabel # corresponds to repository topic
      github:
        organization: myOrg
        allBranches: false
        appSecretName: my-github-repo-secret
  template:
    metadata:
      name: '{{ repository }}-{{ branch }}'
    spec:
      destination:
        name: in-cluster
        namespace: default
      source:
        path: '.'
        repoURL: '{{ url }}'
        targetRevision: '{{ sha }}'
      project: default

The associated github app sends repository events (specific created and updated actions) when repository topics change (I'm using label and topic interchangeably here). In the github app configuration the event is called repository:

image

Here's a sample event when I add or remove a topic from a repo (shortened for brevity):

{
  "event": "repository",
  "payload": {
    "action": "created|edited",
    "changes": {
      "topics": {
        "from": []
      }
    },
    "repository": {
      "topics": [] /* this is what we care about */
    },
    "organization": {},
    "sender": {},
    "installation": {}
  }
}

And the logs from the applicationset controller show that the event is unsupported:

argocd-applicationset-controller-*** time="2024-08-26T23:27:08Z" level=info msg="Webhook processing failed: event not defined to be parsed"

Adding support for this event looks like it could go here: https://github.com/argoproj/argo-cd/blob/master/applicationset/webhook/webhook.go#L164C3-L164C10

More info about the repository object (we only care about edited and created actions):

ejhayes commented 2 weeks ago

Appears to be fixed by #16303