mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
40 lines
1.2 KiB
Go
40 lines
1.2 KiB
Go
|
|
package rest
|
||
|
|
|
||
|
|
import (
|
||
|
|
"context"
|
||
|
|
"fmt"
|
||
|
|
|
||
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||
|
|
"k8s.io/apimachinery/pkg/runtime"
|
||
|
|
"k8s.io/apiserver/pkg/registry/rest"
|
||
|
|
"k8s.io/klog"
|
||
|
|
)
|
||
|
|
|
||
|
|
type DualWriterMode3 struct {
|
||
|
|
DualWriter
|
||
|
|
}
|
||
|
|
|
||
|
|
// NewDualWriterMode3 returns a new DualWriter in mode 3.
|
||
|
|
// Mode 3 represents writing to LegacyStorage and Storage and reading from Storage.
|
||
|
|
func NewDualWriterMode3(legacy LegacyStorage, storage Storage) *DualWriterMode3 {
|
||
|
|
return &DualWriterMode3{*NewDualWriter(legacy, storage)}
|
||
|
|
}
|
||
|
|
|
||
|
|
// Create overrides the default behavior of the DualWriter and writes to LegacyStorage and Storage.
|
||
|
|
func (d *DualWriterMode3) Create(ctx context.Context, obj runtime.Object, createValidation rest.ValidateObjectFunc, options *metav1.CreateOptions) (runtime.Object, error) {
|
||
|
|
legacy, ok := d.legacy.(rest.Creater)
|
||
|
|
if !ok {
|
||
|
|
return nil, fmt.Errorf("legacy storage rest.Creater is missing")
|
||
|
|
}
|
||
|
|
|
||
|
|
created, err := d.Storage.Create(ctx, obj, createValidation, options)
|
||
|
|
if err != nil {
|
||
|
|
return created, err
|
||
|
|
}
|
||
|
|
|
||
|
|
if _, err := legacy.Create(ctx, obj, createValidation, options); err != nil {
|
||
|
|
klog.Error("unable to create object in legacy storage", "error", err)
|
||
|
|
}
|
||
|
|
return created, nil
|
||
|
|
}
|