grafana / grafana-app-sdk

An SDK for developing apps for grafana using kubernetes-like storage and operators
Apache License 2.0
48 stars 8 forks source link

App Logic and Runtime Separation #402

Closed IfSentient closed 1 month ago

IfSentient commented 2 months ago

What This PR Does / Why We Need It

This PR resolves https://github.com/grafana/grafana-app-sdk/issues/385 by introducing a new way to write and run apps focused around app logic implementing the interface app.App, and runtime logic (such as a standalone operator) existing as a layer over app.App which translates runtime-specific behaviors into the app.App method calls.

App Logic

App logic is now handled as implementation of the new app.App interface, which describes all possible app behaviors. A default implementation, akin to simple.Operator, exists as simple.App (created with simple.NewApp). A user can also write a custom implementation of app.App if they so wish, and it should be compatible with any runner that consumes an app.App/app.Provider.

app.Provider is an interface for usage by runners, which provides an app.Manifest to the runner to get app capabilities, and then allows for creation of an app.App with configuration sourced from the runner (such as KubeConfig, which may have varying methods by which it is loaded depending on the runner).

Runtime Logic

This PR introduces only one runner, simple.StandaloneOperator, which runs an app as a standalone operator. Combined with simple.App, this gives users the same (and slightly more) functionality that simple.Operator currently does. Planned in a future PR is plugin.App (or a similar name), which will run the app as a plugin and translate gRPC admission and CallResource calls into the app method calls.

Codegen & Documentation

Codegen for grafana-app-sdk component add will be introduced in a future PR to keep this one lighter, alongside documentation and examples for writing an app in this new manner (and existing documentation will be updated to working with apps this way). This PR is focused on introducing the new functionality, and as the "old" (current) way of writing apps is still perfectly valid, documentation will be added and updated in a docs-focused PR.

Other Changes

This PR also contains a drive-by fix for app manifest go codegen, as it currently improperly duplicates the Validation field for mutation when enabled.