notification-controller: Events to Git Provider #101
-
The current work done with the Notification Controller would support sending events to Slack, MSTeams etc. in a similar way to how flux-cloud works today. The downside of consuming events through ChatOps is that the message could be considered ephemeral. Additionally it would be difficult to build a CI that could fetch the information in a reasonable way. Most Git providers offer a status API for tools outside of the "native" CI to feedback the status of a build job. Meaning that there exists an alternative destination for the notification events. I started building flux-status to try out my idea which I felt worked pretty well. The downside of flux-status is that it works the same way flux-cloud does, which means that it would have to be rewritten when FluxV2 gets released. After discussing the matter with @stefanprodan we came to the agreement that having yet another project to solve a small problem would be counter productive. Instead it might be better to add this functionality as a new provider in the notification controller. There would have to be some differences between the current providers and those that talk to git providers. First of all we would need to find the source repository for the event as the event only includes the sha of the commit. We would also need to translate the event type to a status state specific to that API. It is also unclear if all events can/should be sent to the commit status. As an example should a helm chart failure after it has been successfully running for days update the status of the commit or not. In my head a typical workflow would look something like this:
We would end up with n+1 commit statuses. One for the initial apply of the commit and then one for the health check of every HelmRelease and Kustomization. As far as I have checked all of the git providers would support sending multiple statuses per commit, I have seen that Github has a limit of 1000 statuses per SHA so it might be worthwhile looking into how we could bundle the events into a single or a couple of statuses instead. Doing it this way would cause an edge case, as it would be possible for a commit to apply but the time for the Pod to start might be long, allowing for a new commit to be made and applied during that time. We now end up with a situation where changes made in the first commit will have its status posted to the latest commit SHA. There are some challenges when working with commit status. The main one is the message size limit for each status, which are not documented. Azure DevOps seems to have a limit at 1000 characters while Github and the other providers have a limit at 200 characters. Stefan had an idea that if we used PRs we could post a lot more information as there are no limits on how large the comment can be. But I think that it would require a lot more work to achieve the functionality, so it is better to start off with commit statuses and see where that takes us. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 13 replies
-
Getting notifications to update a commit status was not too difficult, but my current solution is hard coded to a single repository. Now that I understand the relationship between events and their sources I don't think there are going to be any issues implementing the lookup. I have some points that need to be discussed though, as I think they will cause issues in the future.
Would love any feedback on the points above. |
Beta Was this translation helpful? Give feedback.
-
ProposalWe can introduce notification providers of type Github provider example: apiVersion: notification.fluxcd.io/v1alpha1
kind: Provider
metadata:
name: podinfo-gh-status
namespace: gitops-system
spec:
type: github-commit-status
address: https://github.com/stefanprodan/podinfo # repo URL
secretRef:
name: github-token # GH token with 'repo:status' scope Alert example: apiVersion: notification.fluxcd.io/v1alpha1
kind: Alert
metadata:
name: podinfo-status-update
namespace: gitops-system
spec:
providerRef:
name: podinfo-gh-status
eventSeverity: info
eventSources:
- kind: Kustomization
name: podinfo-staging
- kind: Kustomization
name: podinfo-prod The kustomize-controller issues events with the source revision stored as metadata: {
"severity": "info",
"reportingController": "kustomize-controller",
"reason": "ApplySucceed",
"message": "service/podinfo create/ndeployment/podinfo created/n....apply log can be huge",
"involvedObject": {
"kind": "Kustomization",
"name": "podinfo-prod",
"namespace": "gitops-system"
},
"metadata": {
"revision": "master/a1afe267b54f38b46b487f6e938a6fd508278c07",
}
} For alerts providers of type Using the above information, notification-controller will post to GH API a status of type {
"severity": "error",
"reportingController": "kustomize-controller",
"reason": "HealthCheckFailed",
"message": "health check failed for Deployment podinfo-prod/podinfo: long error message....",
"involvedObject": {
"kind": "Kustomization",
"name": "podinfo-prod",
"namespace": "gitops-system"
},
"metadata": {
"revision": "master/a1afe267b54f38b46b487f6e938a6fd508278c07",
}
} If the severity is Message format: |
Beta Was this translation helpful? Give feedback.
-
Hi all. We are triying to use alert to point commit used into bitbucket repo, with multiple clusters running with flux and same repo. What is the way to do? install podinfo is necessary? is necessary to add every crd at the same repo by every cluster? Thanks, |
Beta Was this translation helpful? Give feedback.
Proposal
We can introduce notification providers of type
<GIT-PROVIDER>-commit-status
.Github provider example:
Alert example: