Skip to content
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

Add events on app CRs #121

Merged
merged 16 commits into from Apr 30, 2021
Merged

Add events on app CRs #121

merged 16 commits into from Apr 30, 2021

Conversation

tomahawk28
Copy link
Contributor

@tomahawk28 tomahawk28 commented Apr 28, 2021

Toward https://github.com/giantswarm/giantswarm/issues/16981

There was a discussion between @fiunchinho on this, https://gigantic.slack.com/archives/C01P7P3BS2C/p1619601080015300
and I think it would be okay with app-admission-controller to emit events since,

  1. it would be the single endpoint to validate app CRs.
  2. It will emit events when it spots the differences between the specs.

WDYT?

Checklist

  • Update changelog in CHANGELOG.md.

@tomahawk28 tomahawk28 self-assigned this Apr 28, 2021
@tomahawk28
Copy link
Contributor Author

Tested in ginger

Events:
  Type    Reason      Age   From                      Message
  ----    ------      ----  ----                      -------
  Normal  AppUpdated  54s   app-admission-controller  version has been changed to `1.1.1`
  Normal  AppUpdated  2s    app-admission-controller  version has been changed to `1.1.0`

@tomahawk28 tomahawk28 requested a deployment to ginger April 29, 2021 09:00 Abandoned
@tomahawk28
Copy link
Contributor Author

Events:
  Type    Reason      Age    From                      Message
  ----    ------      ----   ----                      -------
  Normal  AppUpdated  3m2s   app-admission-controller  version has been changed to `1.1.0`
  Normal  AppUpdated  2m49s  app-admission-controller  version has been changed to `1.1.1`
  Normal  AppUpdated  1s     app-admission-controller  appConfigMap has been resetted 

resetted is wrong, right?

return microerror.Maskf(parsingFailedError, "unable to parse app: %#v", err)
}

compareFunc := map[string]func(v1alpha1.App) string{
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think having a list of compare functions like below is much tidy.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes makes sense but also could be useful in other places.

What about moving to the key package in the app library? Since it's using lots of key funcs anyway.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also offtopic but the logging with namespace/name is nice.

I think @fiunchinho did that in apptest as well. We should improve the logging in app- and chart-operator too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rossf7 Do you mean moving compareFunc into the app library? But here I would like to show users about events that relevant to the user interface when we hide other changes (e.g. annotation, kubeconfig changes).

Both app-operator and chart-operator are using cmp.diff from the desired chart CRs, so there are not many places we could use this list other than app-admission-controller. So I'm inclined to stay this function here only, WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

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

OK sure if we're not going to reuse it then it's more readable to have it here IMO. 👍

But the ordering is weird here. Can we have this in alpha order?

@tomahawk28 tomahawk28 marked this pull request as ready for review April 29, 2021 09:16
@tomahawk28 tomahawk28 requested a review from a team April 29, 2021 09:16
newValue := f(app)
if newValue != f(oldApp) {
if newValue == "/" {
v.event.Emit(ctx, &app, "AppUpdated", "%s has been resetted", name)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Need a little help here from 🇬🇧

@fiunchinho
Copy link
Member

I think it looks good! nice job

Copy link
Contributor

@rossf7 rossf7 left a comment

Choose a reason for hiding this comment

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

@tomahawk28 This is cool thanks! 🚀

There was a discussion between @fiunchinho on this, https://gigantic.slack.com/archives/C01P7P3BS2C/p1619601080015300
and I think it would be okay with app-admission-controller to emit events since,

it would be the single endpoint to validate app CRs.
It will emit events when it spots the differences between the specs.

Emitting events from the admission controller makes sense but I would expect it's only serving webhooks. Can you update the README to cover that? For describing the webhooks what about linking to the docs?

My main concern is could we have duplicate events? Also what happens when we have a failure condition, like when chart-operator / helm is blocked by a webhook?

Could this generate a lot of events and impact the management cluster?
Can we have a metric for how many events are emitted?

pkg/app/validate_app.go Show resolved Hide resolved
return microerror.Maskf(parsingFailedError, "unable to parse app: %#v", err)
}

compareFunc := map[string]func(v1alpha1.App) string{
Copy link
Contributor

Choose a reason for hiding this comment

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

Yes makes sense but also could be useful in other places.

What about moving to the key package in the app library? Since it's using lots of key funcs anyway.

return microerror.Maskf(parsingFailedError, "unable to parse app: %#v", err)
}

compareFunc := map[string]func(v1alpha1.App) string{
Copy link
Contributor

Choose a reason for hiding this comment

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

Also offtopic but the logging with namespace/name is nice.

I think @fiunchinho did that in apptest as well. We should improve the logging in app- and chart-operator too.

@tomahawk28
Copy link
Contributor Author

tomahawk28 commented Apr 29, 2021

@rossf7 I checked the kube-state-metrics and it doesn't gather metrics about event resources as default.
https://github.com/kubernetes/kube-state-metrics/blob/master/docs/cli-arguments.md

So we either need to enable it from kube-state-metrics app or gather metrics ourselves. But I doubt we need to do it actually given the fact that the event resources have a 1-hour lifetime as default.
kubernetes/kubernetes#52521

Moreover, app-admission-controller emits events right just before it would admit app CRs' changes and only if it sees the actual difference between old and new spec. (e.g. change from the .spec.version)
So I don't think the number of events would be increased by these changes in any cases.

If you still want to have a metric on these events, do you perhaps know any metrics for event resources other than kube-state-metrics?

@rossf7
Copy link
Contributor

rossf7 commented Apr 30, 2021

If you still want to have a metric on these events, do you perhaps know any metrics for event resources other than kube-state-metrics?

@tomahawk28 That's a shame kube-state-metrics doesn't gather this. But the admission controller emits its own metrics so I think we could add our own.

https://github.com/giantswarm/app-admission-controller/blob/867987245b295d4a728a9708663b4ea520ea6efc/pkg/metrics/metrics.go

But I doubt we need to do it actually given the fact that the event resources have a 1-hour lifetime as default.

Yes, that's a good point. Let's see how it goes. We can add a custom metric later if we need one.

Copy link
Contributor

@rossf7 rossf7 left a comment

Choose a reason for hiding this comment

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

@tomahawk28 Thanks for the changes. Just some final 🇬🇧 nits then this looks good.

docs/events.md Outdated Show resolved Hide resolved
docs/events.md Outdated Show resolved Hide resolved
docs/events.md Outdated Show resolved Hide resolved
docs/events.md Show resolved Hide resolved
internal/recorder/recorder.go Outdated Show resolved Hide resolved
internal/recorder/recorder.go Outdated Show resolved Hide resolved
pkg/app/validate_app.go Outdated Show resolved Hide resolved
pkg/app/validate_app.go Outdated Show resolved Hide resolved
return microerror.Maskf(parsingFailedError, "unable to parse app: %#v", err)
}

compareFunc := map[string]func(v1alpha1.App) string{
Copy link
Contributor

Choose a reason for hiding this comment

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

OK sure if we're not going to reuse it then it's more readable to have it here IMO. 👍

But the ordering is weird here. Can we have this in alpha order?

}

if newValue == "/" {
v.event.Emit(ctx, &app, "AppUpdated", "%s has been reset", name)
Copy link
Contributor

Choose a reason for hiding this comment

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

It's already fixed here. 😄

Jihyuk Bok and others added 3 commits April 30, 2021 13:17
Co-authored-by: Ross Fairbanks <rossf7@users.noreply.github.com>

See [docs/tests.md](https://github.com/giantswarm/app-admission-controller/blob/master/docs/tests.md)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just a note; I'm deleting this tests.md, since we don't have this document.

Copy link
Contributor

@rossf7 rossf7 left a comment

Choose a reason for hiding this comment

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

LGTM once typos in the doc are fixed

docs/events.md Outdated
At the end of each successful validation of an app CR, app-admission-controller checks the changes for the following fields and emits an event.

- `.spec.version`
- `.sepc.catalog`
Copy link
Contributor

Choose a reason for hiding this comment

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

These ones still have the typo.

@tomahawk28 tomahawk28 enabled auto-merge (squash) April 30, 2021 12:00
@tomahawk28 tomahawk28 merged commit 4326bb7 into master Apr 30, 2021
@tomahawk28 tomahawk28 deleted the request-update-events branch April 30, 2021 12:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants