/
githubmirror
/
grafana
Обзор
Документация
Войти
/
githubmirror
/
grafana
Код
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
apps/example/pkg/app/mutation.go
31 строка
941 B
Austin Pond
Apps: Add Example App to `./apps` (#112069)
27 окт 2025, 19:01
Не верифицирован
27 окт 2025, 19:01
bf65c43
Код
Авторство
О чём код?
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 }