mirror of
https://github.com/grafana/grafana.git
synced 2024-11-25 02:10:45 -06:00
Playlist: Add mutation and validation (#95708)
This commit is contained in:
parent
c125ead121
commit
280c27507c
@ -5,6 +5,8 @@ externalName: {
|
||||
group: "playlist"
|
||||
apiResource: {
|
||||
groupOverride: "playlist.grafana.app"
|
||||
mutation: operations: ["create","update"]
|
||||
validation: operations: ["create","update"]
|
||||
}
|
||||
codegen: {
|
||||
frontend: false
|
||||
|
@ -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,
|
||||
},
|
||||
},
|
||||
|
@ -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
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user