-
Notifications
You must be signed in to change notification settings - Fork 143
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Alerts/Github - is it possible to separate add additional metadata? #589
Comments
The The commit status API accepts the parameters |
I'll be happy with any solution that doesn't involve renaming my kustomizations per cluster.
to no avail, my understanding is that certain fields as context cannot be overridden https://github.com/fluxcd/notification-controller/pull/529/files#diff-9c161f071659a6d134b4cfdd27ad66fc88d93b5dfb102d7bb5a768b9e9e483eaR81 as you mentioned they are used by flux already. |
Looks like this PR described the same use case #340 |
@makkes maybe we should include it in the |
Would be fine from my perspective. |
@makkes : Please assign this issue to me. I can work on it. |
is there any workaround to achieve this? |
I see that ut uses uid of the provider in commit status like this: kustomization/tf-controller/25c8a95e |
No. |
@makkes |
|
@makkes the summary field is human-readable text, not an identifier. For this issue, it would be preferable to to change the context value of the github status to make it predictable for each cluster so that other CI steps can wait on the status to be set. |
We've implemented RFC-0008 in Flux 2.5 which allow custom metadata like GitHub deployment ID to be injected in Flux events. |
After bumping to Flux 2.5 and testing it seems that this issue should be reopened. While it is now possible to add custom metadata to flux events, this issue is about adding extra metadata to alerts targetting Notification providers of apiVersion: kustomize.toolkit.fluxcd.io/v1
kind: Kustomization
metadata:
annotations:
event.toolkit.fluxcd.io/context: mycustomcontext # ignored in github commit status
I don't see how this can be done with the current Github commit status API limitations, other than allowing us to override the |
One way to implement this would be an optional field in the Provider API called ...
spec:
commitStatusIDExpr: "'my-kustomization/' + event.metadata.foo + '/' + alert.metadata.name + '/' + provider.metadata.name" Here |
Yes, I believe so. If I understand you correctly we could then make the end result to be be changed in a manner like this?
|
Exactly, the expression for that would be:
See my CEL Playground test. |
Yes, this would suffice for the use case described in this issue. |
@matheuscscp i'd be happy to help work on this, but was curious about what this would mean for updates to the provider API -- would we want to add a status subresource to the also, opened this: fluxcd/pkg#882 |
@kathleenfrench That is a great design question, it turns out that we recently went through the process of cleaning up the reconcilers for It totally makes sense to me to do the same as what we did in I'd be for reintroducing the status subresource for // ReceiverStatus defines the observed state of the Receiver.
type ReceiverStatus struct {
meta.ReconcileRequestStatus `json:",inline"`
// Conditions holds the conditions for the Receiver.
// +optional
Conditions []metav1.Condition `json:"conditions,omitempty"`
// WebhookPath is the generated incoming webhook address in the format
// of '/hook/sha256sum(token+name+namespace)'.
// +optional
WebhookPath string `json:"webhookPath,omitempty"`
// ObservedGeneration is the last observed generation of the Receiver object.
// +optional
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
} For In the event server handler we can drop the alert sooner by looking at the condition like we did for
This would avoid evaluating the expression if we already know it's invalid from the object status. We also need And finally I think it would also be nice to add @stefanprodan does any of this make sense? |
all of that makes sense to me, though i do have a question about:
we probably do want a mechanism for blocking creation/updates entirely based on certain known conditions -- i've not worked with CEL previously, but my understanding is we do need knowledge of the variables that will be evaluated in order to compile the expression, which means won't we need to explicitly limit what can be referenced in the expression itself? i.e. so i think my first question is should
from my reading even this is fairly limited, though, no? we can go as far as validating that the expression compiles, but if -- for instance -- someone uses |
What I meant by CEL compiling CEL is about these These annotations in the spec struct generate these in the CRD: I meant we can't have one of those CEL expressions in the struct annotations to validate
It depends on the use case. For example, in the notification-controller/internal/server/receiver_resource_filter.go Lines 41 to 46 in 2763e54
But in the Custom CEL Health Checks feature we just shipped in kustomize-controller unfortunately we don't know all the fields a custom resource could have, so we build the expression without But in the case of
So I think we can probably build the expression with something like this: func newCommitStatusIDExpression(s string) (*cel.Expression, error) {
return cel.NewExpression(s,
cel.WithCompile(),
cel.WithOutputType(types.StringType),
cel.WithStructVariables("event", "alert", "provider"))
}
Btw because of this comment I noticed that we need to swap the order of these lines: notification-controller/internal/server/event_handlers.go Lines 254 to 260 in 2763e54
Passing the built commit status ID when present could also be an opportunity to refactor the notifier factory constructor, I really don't like this constructor taking all these inputs at the same time the way it does, not all of them are present i.e. some are actually optional. Explicit arguments are for mandatory parameters and not optional ones. Then inside
Fair point! But at the place of the code where we should compile+evaluate the expression all the three objects are easily available i.e. inside the function
You're right, the validation wouldn't be perfect anyway, but I think it still gives a bit of a head start, and also we did this already in three places:
So for consistency it would make sense to do the same for |
This is a fair point btw, I'm really unsure about what's best here, would folks in this thread prefer the status quo if the expression evaluation results in an error? We would log it as an error anyway of course, but maybe it's easier to see a commit status missing than a commit status with wrong ID? @audunsolemdal What would you prefer? |
I usually prefer failing catastrophically rather than making the best effort, to force people to fix their mistakes sooner rather than later |
@matheuscscp given the scope of changes to the provider api does this warrant a new |
Maybe, there's also other changes in |
Hey @kathleenfrench we discussed this in the flux dev meeting today and reached two conclusions:
By the way this also settles the discussion around dropping vs using a fallback, we should simply drop the alert if the configuration is wrong, we error out and let the error log be printed, that's it. Also the field is optional, so users that don't use it obviously won't be affected, so it's all good |
sounds good -- i'll get to work on something 👍🏻 |
So my goal is to run a github action step to check if fluxcd reconciliation for a kustomization towards a specificcluster was successful. There are three different kustomizations in three different clusters which may post
reconcilation successful
status to my commit on github. The kustomizations have the same exact name It does not seem like modifying theeventMetadata
orsummary
fields in the Alert resource adds any extra metadata to the github status.I guess a workaround is to name the kustomizations
tstsp1-github-info-${cluster}
rather than justtstsp1-github-info
, but I am wondering if there are other methods to inject this metadata into the Github status? Thedescription
orcontext
fields would be sufficient to modify in my use case.Say I have a repo with the following structure
orgX/wl-tstsp1:
Each folder is connected to the namespace called
tstsp1
in three different cluster (dev/test/prod)From each of the clusters there is a alert updating the github status
I end up with a status looking somewhat like the below:
The text was updated successfully, but these errors were encountered: