Skip to content
This repository has been archived by the owner on Jul 15, 2024. It is now read-only.

feat: refresh ApplicationSet resource with git generator using webhook #341

Merged
merged 3 commits into from
Sep 7, 2021

Conversation

chetan-rns
Copy link
Member

Currently, the repository used in git-generator will be polled every 3 mins. This commit adds support to refresh the application set using a git webhook. It exposes a service listening for incoming webhook payloads and triggers the application set controller.

Fixes: #222

pkg/utils/webhook.go Outdated Show resolved Hide resolved
pkg/utils/webhook.go Outdated Show resolved Hide resolved
pkg/utils/webhook.go Outdated Show resolved Hide resolved
pkg/utils/webhook.go Outdated Show resolved Hide resolved
pkg/utils/webhook.go Show resolved Hide resolved
pkg/utils/webhook.go Outdated Show resolved Hide resolved
@jgwest
Copy link
Member

jgwest commented Aug 24, 2021

@chetan-rns If you rebase to master it should fix the E2E tests, FYI

Currently, the repository used in git-generator will be polled every 3 mins. This commit adds support to refresh the applicationset using a git webhook. It exposes a service listening for incoming webhook payloads and triggers the applicationset controller.
Copy link
Member

@jgwest jgwest left a comment

Choose a reason for hiding this comment

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

Looks great, thanks @chetan-rns! Only one change requested:

Can you create a doc page (in /docs) for the webhook feature? You can probably just base it on the first step of the Argo CD Web Hook doc page. Content looks like it should basically be the same between the two (and we probably only need the first step from there).

Copy link
Member

@jgwest jgwest left a comment

Choose a reason for hiding this comment

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

Content looks great! Rather than having webhook be its own page (like it is for Argo CD docs), let's move the contents of the new Webhook page into the existing Generators-Git.md file, adding it to the end of the document, eg:

## Git Generator: Files

(... previous content of Git Generator: Files...)

## Git Generator Webhook Configuration

When using a Git generator, ApplicationSet polls Git repositories (...)

(At first I thought we should have it be a separate page (like with Argo CD, and in your last commit) but I think it makes sense to include this content on the Git generator page, as it is applicable to both generator types, but is only applicable to these two generators. )

@chetan-rns
Copy link
Member Author

@jgwest I agree it makes more sense to have the webhook section in the existing Git Generator page. I've updated it. Please take a look :)

@jgwest jgwest removed this from the Milestone 3 milestone Sep 2, 2021
Copy link
Member

@jgwest jgwest left a comment

Choose a reason for hiding this comment

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

Awesome, thanks @chetan-rns! Really great to get this feature in, which folks have been looking for 👍 .

@jgwest jgwest merged commit 105a2d4 into argoproj:master Sep 7, 2021
Comment on lines +210 to +221
func startWebhookServer(webhookHandler *utils.WebhookHandler) {
mux := http.NewServeMux()
mux.HandleFunc("/api/webhook", webhookHandler.Handler)
go func() {
setupLog.Info("Starting webhook server")
err := http.ListenAndServe(":7000", mux)
if err != nil {
setupLog.Error(err, "failed to start webhook server")
os.Exit(1)
}
}()
}
Copy link
Member

@mkilchhofer mkilchhofer Jan 5, 2022

Choose a reason for hiding this comment

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

Hmm, is it a good idea to hardcode the port here as other port bindings are configurable?: https://github.com/argoproj-labs/applicationset/blob/master/main.go#L84-L85

	flag.StringVar(&metricsAddr, "metrics-addr", ":8080", "The address the metric endpoint binds to.")
	flag.StringVar(&probeBindAddr, "probe-addr", ":8081", "The address the probe endpoint binds to.")

Also it would be nice to make the webhook handler optional. This introduces a hard dependency on the ConfigMap argocd-cm which makes it really hard to find a good solution for the helm chart update to 0.3.0:
argoproj/argo-helm#1070

Copy link
Member Author

Choose a reason for hiding this comment

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

Hi @mkilchhofer, thanks for bringing this up. I agree the webhook address should be configurable. I've raised a PR for this #450. It also makes the webhook handler optional by removing the hard exit.

Copy link
Member

Choose a reason for hiding this comment

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

Cool. Also worked on this :-D but you were faster, thanks. 🙏

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support Webhooks trigger For Git generators in application set
4 participants