diff --git a/apps/playlist/kinds/playlist.cue b/apps/playlist/kinds/playlist.cue index 72a0813b987..3cbfee9bef2 100644 --- a/apps/playlist/kinds/playlist.cue +++ b/apps/playlist/kinds/playlist.cue @@ -5,6 +5,8 @@ externalName: { group: "playlist" apiResource: { groupOverride: "playlist.grafana.app" + mutation: operations: ["create","update"] + validation: operations: ["create","update"] } codegen: { frontend: false diff --git a/apps/playlist/pkg/apis/manifest.go b/apps/playlist/pkg/apis/manifest.go index effd6e4896d..369f30a62fd 100644 --- a/apps/playlist/pkg/apis/manifest.go +++ b/apps/playlist/pkg/apis/manifest.go @@ -27,7 +27,21 @@ var appManifestData = app.ManifestData{ Conversion: false, Versions: []app.ManifestKindVersion{ { - Name: "v0alpha1", + Name: "v0alpha1", + Admission: &app.AdmissionCapabilities{ + Validation: &app.ValidationCapability{ + Operations: []app.AdmissionOperation{ + app.AdmissionOperationCreate, + app.AdmissionOperationUpdate, + }, + }, + Mutation: &app.MutationCapability{ + Operations: []app.AdmissionOperation{ + app.AdmissionOperationCreate, + app.AdmissionOperationUpdate, + }, + }, + }, Schema: &versionSchemaPlaylistv0alpha1, }, }, diff --git a/apps/playlist/pkg/app/app.go b/apps/playlist/pkg/app/app.go index 9bdfdc3b8df..36d6b16e580 100644 --- a/apps/playlist/pkg/app/app.go +++ b/apps/playlist/pkg/app/app.go @@ -5,11 +5,11 @@ import ( "fmt" "github.com/grafana/grafana-app-sdk/app" - "github.com/grafana/grafana-app-sdk/logging" "github.com/grafana/grafana-app-sdk/operator" "github.com/grafana/grafana-app-sdk/resource" "github.com/grafana/grafana-app-sdk/simple" "k8s.io/apimachinery/pkg/runtime/schema" + "k8s.io/klog/v2" playlistv0alpha1 "github.com/grafana/grafana/apps/playlist/pkg/apis/playlist/v0alpha1" "github.com/grafana/grafana/apps/playlist/pkg/watchers" @@ -38,13 +38,27 @@ func New(cfg app.Config) (app.App, error) { KubeConfig: cfg.KubeConfig, InformerConfig: simple.AppInformerConfig{ ErrorHandler: func(ctx context.Context, err error) { - logging.DefaultLogger.With("error", err).Error("Informer processing error") + klog.ErrorS(err, "Informer processing error") }, }, ManagedKinds: []simple.AppManagedKind{ { Kind: playlistv0alpha1.PlaylistKind(), Watcher: playlistWatcher, + Mutator: &simple.Mutator{ + MutateFunc: func(ctx context.Context, req *app.AdmissionRequest) (*app.MutatingResponse, error) { + // modify req.Object if needed + return &app.MutatingResponse{ + UpdatedObject: req.Object, + }, nil + }, + }, + Validator: &simple.Validator{ + ValidateFunc: func(ctx context.Context, req *app.AdmissionRequest) error { + // do something here if needed + return nil + }, + }, }, }, }