* [API Server] Add Example App for reference use. * Remove Printlns. * Upgrade app-sdk to v0.46.0, update apps to handle breaking changes. * Only start the reconciler for the example app if the v1alpha1 API version is enabled. * Some comment doc updates. * Run make update-workspace * Set codeowner for /apps/example * Run make gofmt and make update-workspace * Run prettier on apps/example/README.md * Add COPY apps/example to Dockerfile * Add an authorizer to the example app. * Fix import ordering. * Update apps/example/kinds/manifest.cue Co-authored-by: Owen Diehl <ow.diehl@gmail.com> * Run make update-workspace * Re-run make gen-go for enterprise import updates * Run make update-workspace --------- Co-authored-by: Owen Diehl <ow.diehl@gmail.com>
32 lines
941 B
Go
32 lines
941 B
Go
package app
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/grafana/grafana-app-sdk/app"
|
|
"github.com/grafana/grafana-app-sdk/simple"
|
|
)
|
|
|
|
var _ simple.KindMutator = NewMutator()
|
|
|
|
type Mutator struct{}
|
|
|
|
func NewMutator() *Mutator {
|
|
return &Mutator{}
|
|
}
|
|
|
|
// Mutate makes modifications to an input object from the API, and returns the changed object.
|
|
// This mutation will be done on every request, so it can be used to add or update things like labels
|
|
// or annotations. Here, we add an annotation noting the last resourceVersion this was called for.
|
|
func (m *Mutator) Mutate(ctx context.Context, req *app.AdmissionRequest) (*app.MutatingResponse, error) {
|
|
annotations := req.Object.GetAnnotations()
|
|
if annotations == nil {
|
|
annotations = make(map[string]string)
|
|
}
|
|
annotations["example.grafana.app/mutated"] = req.Object.GetResourceVersion()
|
|
req.Object.SetAnnotations(annotations)
|
|
return &app.MutatingResponse{
|
|
UpdatedObject: req.Object,
|
|
}, nil
|
|
}
|