K8s/Storage: Deprecate StorageTypeLegacy (#98096)
This commit is contained in:
@@ -178,6 +178,8 @@ func InstallAPIs(
|
||||
// this is needed to support setting a default RESTOptionsGetter for new APIs that don't
|
||||
// support the legacy storage type.
|
||||
var dualWrite grafanarest.DualWriteBuilder
|
||||
|
||||
// nolint:staticcheck
|
||||
if storageOpts.StorageType != options.StorageTypeLegacy {
|
||||
dualWrite = func(gr schema.GroupResource, legacy grafanarest.LegacyStorage, storage grafanarest.Storage) (grafanarest.Storage, error) {
|
||||
key := gr.String() // ${resource}.{group} eg playlists.playlist.grafana.app
|
||||
|
||||
@@ -50,7 +50,8 @@ func applyGrafanaConfig(cfg *setting.Cfg, features featuremgmt.FeatureToggles, o
|
||||
o.RecommendedOptions.Admission = nil
|
||||
o.RecommendedOptions.CoreAPI = nil
|
||||
|
||||
o.StorageOptions.StorageType = options.StorageType(apiserverCfg.Key("storage_type").MustString(string(options.StorageTypeLegacy)))
|
||||
// nolint:staticcheck
|
||||
o.StorageOptions.StorageType = options.StorageType(apiserverCfg.Key("storage_type").MustString(string(options.StorageTypeUnified)))
|
||||
o.StorageOptions.DataPath = apiserverCfg.Key("storage_path").MustString(filepath.Join(cfg.DataPath, "grafana-apiserver"))
|
||||
o.StorageOptions.Address = apiserverCfg.Key("address").MustString(o.StorageOptions.Address)
|
||||
o.StorageOptions.BlobStoreURL = apiserverCfg.Key("blob_url").MustString(o.StorageOptions.BlobStoreURL)
|
||||
|
||||
@@ -17,9 +17,11 @@ type StorageType string
|
||||
const (
|
||||
StorageTypeFile StorageType = "file"
|
||||
StorageTypeEtcd StorageType = "etcd"
|
||||
StorageTypeLegacy StorageType = "legacy"
|
||||
StorageTypeUnified StorageType = "unified"
|
||||
StorageTypeUnifiedGrpc StorageType = "unified-grpc"
|
||||
|
||||
// Deprecated: legacy is a shim that is no longer necessary
|
||||
StorageTypeLegacy StorageType = "legacy"
|
||||
)
|
||||
|
||||
type StorageOptions struct {
|
||||
@@ -45,7 +47,7 @@ type StorageOptions struct {
|
||||
|
||||
func NewStorageOptions() *StorageOptions {
|
||||
return &StorageOptions{
|
||||
StorageType: StorageTypeLegacy,
|
||||
StorageType: StorageTypeUnified,
|
||||
Address: "localhost:10000",
|
||||
}
|
||||
}
|
||||
@@ -59,9 +61,13 @@ func (o *StorageOptions) AddFlags(fs *pflag.FlagSet) {
|
||||
func (o *StorageOptions) Validate() []error {
|
||||
errs := []error{}
|
||||
switch o.StorageType {
|
||||
case StorageTypeFile, StorageTypeEtcd, StorageTypeLegacy, StorageTypeUnified, StorageTypeUnifiedGrpc:
|
||||
// nolint:staticcheck
|
||||
case StorageTypeLegacy:
|
||||
// no-op
|
||||
case StorageTypeFile, StorageTypeEtcd, StorageTypeUnified, StorageTypeUnifiedGrpc:
|
||||
// no-op
|
||||
default:
|
||||
// nolint:staticcheck
|
||||
errs = append(errs, fmt.Errorf("--grafana-apiserver-storage-type must be one of %s, %s, %s, %s, %s", StorageTypeFile, StorageTypeEtcd, StorageTypeLegacy, StorageTypeUnified, StorageTypeUnifiedGrpc))
|
||||
}
|
||||
|
||||
@@ -84,6 +90,7 @@ func (o *StorageOptions) ApplyTo(serverConfig *genericapiserver.RecommendedConfi
|
||||
// EnforceFeatureToggleAfterMode1 makes sure there is a feature toggle set for resources with DualWriterMode > 1.
|
||||
// This is needed to ensure that we use the K8s client before enabling dual writing.
|
||||
func (o *StorageOptions) EnforceFeatureToggleAfterMode1(features featuremgmt.FeatureToggles) error {
|
||||
// nolint:staticcheck
|
||||
if o.StorageType != StorageTypeLegacy {
|
||||
for rg, s := range o.UnifiedStorageConfig {
|
||||
if s.DualWriterMode > 1 {
|
||||
|
||||
@@ -3,9 +3,10 @@ package options
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestStorageOptions_CheckFeatureToggle(t *testing.T) {
|
||||
@@ -18,7 +19,7 @@ func TestStorageOptions_CheckFeatureToggle(t *testing.T) {
|
||||
}{
|
||||
{
|
||||
name: "with legacy storage",
|
||||
StorageType: StorageTypeLegacy,
|
||||
StorageType: StorageTypeLegacy, // nolint:staticcheck
|
||||
UnifiedStorageConfig: map[string]setting.UnifiedStorageConfig{"playlists.playlist.grafana.app": {DualWriterMode: 2}},
|
||||
features: featuremgmt.WithFeatures(),
|
||||
},
|
||||
|
||||
@@ -41,7 +41,7 @@ func ProvideUnifiedStorageClient(
|
||||
// See: apiserver.ApplyGrafanaConfig(cfg, features, o)
|
||||
apiserverCfg := cfg.SectionWithEnvOverrides("grafana-apiserver")
|
||||
client, err := newClient(options.StorageOptions{
|
||||
StorageType: options.StorageType(apiserverCfg.Key("storage_type").MustString(string(options.StorageTypeLegacy))),
|
||||
StorageType: options.StorageType(apiserverCfg.Key("storage_type").MustString(string(options.StorageTypeUnified))),
|
||||
DataPath: apiserverCfg.Key("storage_path").MustString(filepath.Join(cfg.DataPath, "grafana-apiserver")),
|
||||
Address: apiserverCfg.Key("address").MustString(""), // client address
|
||||
BlobStoreURL: apiserverCfg.Key("blob_url").MustString(""),
|
||||
|
||||
@@ -22,7 +22,6 @@ import (
|
||||
"github.com/grafana/grafana/pkg/expr"
|
||||
"github.com/grafana/grafana/pkg/infra/db"
|
||||
"github.com/grafana/grafana/pkg/infra/tracing"
|
||||
"github.com/grafana/grafana/pkg/services/apiserver/options"
|
||||
apimodels "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions"
|
||||
ngmodels "github.com/grafana/grafana/pkg/services/ngalert/models"
|
||||
ngstore "github.com/grafana/grafana/pkg/services/ngalert/store"
|
||||
@@ -702,7 +701,6 @@ func TestIntegrationDeleteFolderWithRules(t *testing.T) {
|
||||
DisableAnonymous: true,
|
||||
ViewersCanEdit: true,
|
||||
AppModeProduction: true,
|
||||
APIServerStorageType: options.StorageTypeLegacy,
|
||||
}
|
||||
|
||||
// Setup Grafana and its Database
|
||||
|
||||
Reference in New Issue
Block a user