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

Wrap microcluster app and API endpoints #283

Merged
merged 7 commits into from
Apr 3, 2024
Merged

Wrap microcluster app and API endpoints #283

merged 7 commits into from
Apr 3, 2024

Conversation

neoaggelos
Copy link
Contributor

@neoaggelos neoaggelos commented Apr 2, 2024

Summary

Capture all required state for the microcluster and the API endpoint implementation in structs.

Changes

  • *app.App now wraps the microcluster app and the snap interface
  • *app.App now implements api.Provider
  • *api.Endpoints now wraps the required provider (to have access to the snap and microcluster app), and implements the API endpoints
  • Do away with the wrapHandlerWithMicrocluster closure, and retrieving the snap through the server context.

Notes

This will allow us to add more configs to the application, and works towards making it easier to write tests for our API endpoints

@neoaggelos neoaggelos requested a review from a team as a code owner April 2, 2024 12:49
@neoaggelos
Copy link
Contributor Author

Blocked by #282 and #279, as there are conflicts

Copy link
Member

@berkayoz berkayoz left a comment

Choose a reason for hiding this comment

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

Nice work, LGTM.

Copy link
Contributor

github-actions bot commented Apr 3, 2024

Package Line Rate
github.com/canonical/k8s/api/v1 48%
github.com/canonical/k8s/cmd/k8s 27%
github.com/canonical/k8s/cmd/util 14%
github.com/canonical/k8s/pkg/client/dqlite 44%
github.com/canonical/k8s/pkg/component 9%
github.com/canonical/k8s/pkg/k8sd/api 2%
github.com/canonical/k8s/pkg/k8sd/controllers 67%
github.com/canonical/k8s/pkg/k8sd/database 48%
github.com/canonical/k8s/pkg/k8sd/pki 55%
github.com/canonical/k8s/pkg/k8sd/setup 70%
github.com/canonical/k8s/pkg/k8sd/types 62%
github.com/canonical/k8s/pkg/proxy 6%
github.com/canonical/k8s/pkg/snap 15%
github.com/canonical/k8s/pkg/snap/util 90%
github.com/canonical/k8s/pkg/utils 31%
github.com/canonical/k8s/pkg/utils/control 61%
github.com/canonical/k8s/pkg/utils/errors 100%
github.com/canonical/k8s/pkg/utils/k8s 69%
Summary 32% (1702 / 5355)

Copy link
Contributor

@bschimke95 bschimke95 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 overall. Only minor comments

// Endpoints returns the list of endpoints for a given microcluster app.
func Endpoints(app *microcluster.MicroCluster) []rest.Endpoint {
func (e *Endpoints) Endpoints() []rest.Endpoint {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Endpoints.Endpoints() reads a bit weird. Maybe call this API?

Copy link
Contributor Author

@neoaggelos neoaggelos Apr 3, 2024

Choose a reason for hiding this comment

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

Usage is api.New(...).Endpoints(), should we maybe rename the type to *api.API?

@@ -55,10 +55,10 @@ func New(ctx context.Context, cfg Config) (*App, error) {
func (a *App) Run(customHooks *config.Hooks) error {
// TODO: consider improving API for overriding hooks.
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: is this still relevant? Seems outdated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, we now pass a *config.Hooks and selectively apply some of the non-nil hooks. which works ok, as we do hange some hooks in a couple of tests.

but this is not too clean, i'd keep the TODO around for the future

@neoaggelos neoaggelos merged commit 2c90ea2 into main Apr 3, 2024
13 checks passed
@neoaggelos neoaggelos deleted the KU-537/state branch April 3, 2024 12:32
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.

3 participants