mirror of
https://github.com/grafana/grafana.git
synced 2025-01-27 16:57:14 -06:00
4e532b00e1
* Add List methods to mode 1 and 4 * Refactor errors
48 lines
1.6 KiB
Go
48 lines
1.6 KiB
Go
package rest
|
|
|
|
import (
|
|
"context"
|
|
|
|
metainternalversion "k8s.io/apimachinery/pkg/apis/meta/internalversion"
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
"k8s.io/apimachinery/pkg/runtime"
|
|
"k8s.io/apiserver/pkg/registry/rest"
|
|
"k8s.io/klog/v2"
|
|
)
|
|
|
|
type DualWriterMode1 struct {
|
|
DualWriter
|
|
}
|
|
|
|
// NewDualWriterMode1 returns a new DualWriter in mode 1.
|
|
// Mode 1 represents writing to and reading from LegacyStorage.
|
|
func NewDualWriterMode1(legacy LegacyStorage, storage Storage) *DualWriterMode1 {
|
|
return &DualWriterMode1{*NewDualWriter(legacy, storage)}
|
|
}
|
|
|
|
// Create overrides the behavior of the generic DualWriter and writes only to LegacyStorage.
|
|
func (d *DualWriterMode1) Create(ctx context.Context, obj runtime.Object, createValidation rest.ValidateObjectFunc, options *metav1.CreateOptions) (runtime.Object, error) {
|
|
legacy, ok := d.Legacy.(rest.Creater)
|
|
if !ok {
|
|
klog.FromContext(ctx).Error(errDualWriterCreaterMissing, "legacy storage rest.Creater is missing")
|
|
return nil, errDualWriterCreaterMissing
|
|
}
|
|
|
|
return legacy.Create(ctx, obj, createValidation, options)
|
|
}
|
|
|
|
// Get overrides the default behavior of the DualWriter and reads only to LegacyStorage.
|
|
func (d *DualWriterMode1) Get(ctx context.Context, name string, options *metav1.GetOptions) (runtime.Object, error) {
|
|
return d.Legacy.Get(ctx, name, options)
|
|
}
|
|
|
|
// List overrides the behavior of the generic DualWriter and reads only from LegacyStorage.
|
|
func (d *DualWriterMode1) List(ctx context.Context, options *metainternalversion.ListOptions) (runtime.Object, error) {
|
|
legacy, ok := d.Legacy.(rest.Lister)
|
|
if !ok {
|
|
return nil, errDualWriterListerMissing
|
|
}
|
|
|
|
return legacy.List(ctx, options)
|
|
}
|