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"
|
group: "playlist"
|
||||||
apiResource: {
|
apiResource: {
|
||||||
groupOverride: "playlist.grafana.app"
|
groupOverride: "playlist.grafana.app"
|
||||||
|
mutation: operations: ["create","update"]
|
||||||
|
validation: operations: ["create","update"]
|
||||||
}
|
}
|
||||||
codegen: {
|
codegen: {
|
||||||
frontend: false
|
frontend: false
|
||||||
|
@ -27,7 +27,21 @@ var appManifestData = app.ManifestData{
|
|||||||
Conversion: false,
|
Conversion: false,
|
||||||
Versions: []app.ManifestKindVersion{
|
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,
|
Schema: &versionSchemaPlaylistv0alpha1,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -5,11 +5,11 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/grafana/grafana-app-sdk/app"
|
"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/operator"
|
||||||
"github.com/grafana/grafana-app-sdk/resource"
|
"github.com/grafana/grafana-app-sdk/resource"
|
||||||
"github.com/grafana/grafana-app-sdk/simple"
|
"github.com/grafana/grafana-app-sdk/simple"
|
||||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||||
|
"k8s.io/klog/v2"
|
||||||
|
|
||||||
playlistv0alpha1 "github.com/grafana/grafana/apps/playlist/pkg/apis/playlist/v0alpha1"
|
playlistv0alpha1 "github.com/grafana/grafana/apps/playlist/pkg/apis/playlist/v0alpha1"
|
||||||
"github.com/grafana/grafana/apps/playlist/pkg/watchers"
|
"github.com/grafana/grafana/apps/playlist/pkg/watchers"
|
||||||
@ -38,13 +38,27 @@ func New(cfg app.Config) (app.App, error) {
|
|||||||
KubeConfig: cfg.KubeConfig,
|
KubeConfig: cfg.KubeConfig,
|
||||||
InformerConfig: simple.AppInformerConfig{
|
InformerConfig: simple.AppInformerConfig{
|
||||||
ErrorHandler: func(ctx context.Context, err error) {
|
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{
|
ManagedKinds: []simple.AppManagedKind{
|
||||||
{
|
{
|
||||||
Kind: playlistv0alpha1.PlaylistKind(),
|
Kind: playlistv0alpha1.PlaylistKind(),
|
||||||
Watcher: playlistWatcher,
|
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