Author: Roberto Galaz
πŸ”— Connect on LinkedIn

By default, Fleet polls Git repositories (default: every 15 seconds) to sync changes. While this approach works well for a small number of repositories, it may lead to inefficiencies in setups with tens or hundreds of repositories. Additionally, polling introduces latency between a Git push and Fleet reacting to it. To improve performance and reduce latency, configuring webhooks in Gitea is recommended.

Pre-requisites

Configuration

  • Edit your GitRepo resource to disable polling by setting disablePolling to true. This ensures Fleet no longer automatically polls the repository.
apiVersion: fleet.cattle.io/v1alpha1
kind: GitRepo
metadata:
  name: sample
  namespace: fleet-local
spec:
  repo: "http://gitea-http.gitea.svc.cluster.local:3000/testing/testing.git"
  branch: main
  paths:
  - simple
  targetNamespace: default
  disablePolling: true
  • Run the port-forward to access Gitea
kubectl port-forward svc/gitea-http -n gitea 3000:3000
  • Go to http://localhost:3000
  • Go to repository settings and webhooks option
  • Add a new webhook
  • Set the URL to http://gitjob.cattle-fleet-system.svc.cluster.local, other settings can be left at their defaults.
  • Save the webhook and test it using the β€œTest Delivery” option
  • If configured correctly, the webhook test should return a 200 status code with a message stating succeeded in the response tab.
  • Now, every time you push changes to the repository, the webhook will trigger automatically, and Fleet will deploy the updates to the default namespace

References

  • https://fleet.rancher.io/0.11/webhook