Skip to content

Commit

Permalink
Update kvstore key
Browse files Browse the repository at this point in the history
  • Loading branch information
suntala committed May 31, 2024
1 parent d822240 commit 0ae476a
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 20 deletions.
10 changes: 6 additions & 4 deletions pkg/apis/playlist/v0alpha1/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ import (
)

const (
GROUP = "playlist.grafana.app"
VERSION = "v0alpha1"
APIVERSION = GROUP + "/" + VERSION
GROUP = "playlist.grafana.app"
VERSION = "v0alpha1"
APIVERSION = GROUP + "/" + VERSION
RESOURCE = "playlists"
GROUPRESOURCE = GROUP + "/" + RESOURCE
)

var PlaylistResourceInfo = common.NewResourceInfo(GROUP, VERSION,
"playlists", "playlist", "Playlist",
RESOURCE, "playlist", "Playlist",
func() runtime.Object { return &Playlist{} },
func() runtime.Object { return &PlaylistList{} },
)
Expand Down
7 changes: 3 additions & 4 deletions pkg/apiserver/rest/dualwriter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"testing"

playlist "github.com/grafana/grafana/pkg/apis/playlist/v0alpha1"
"github.com/grafana/grafana/pkg/infra/kvstore"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
Expand Down Expand Up @@ -44,14 +45,12 @@ func TestSetDualWritingMode(t *testing.T) {

kvStore := kvstore.WithNamespace(kvstore.NewFakeKVStore(), 0, "storage.dualwriting."+tt.stackID)

key := "playlist"

dw, err := SetDualWritingMode(context.Background(), kvStore, ls, us, key, tt.desiredMode)
dw, err := SetDualWritingMode(context.Background(), kvStore, ls, us, playlist.GROUPRESOURCE, tt.desiredMode)
assert.NoError(t, err)
assert.Equal(t, tt.expectedMode, dw.Mode())

// check kv store
val, ok, err := kvStore.Get(context.Background(), key)
val, ok, err := kvStore.Get(context.Background(), playlist.GROUPRESOURCE)
assert.True(t, ok)
assert.NoError(t, err)
assert.Equal(t, val, fmt.Sprint(tt.expectedMode))
Expand Down
4 changes: 2 additions & 2 deletions pkg/registry/apis/playlist/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (b *PlaylistAPIBuilder) GetGroupVersion() schema.GroupVersion {
}

func (b *PlaylistAPIBuilder) GetDesiredDualWriterMode(dualWrite bool, modeMap map[string]grafanarest.DualWriterMode) grafanarest.DualWriterMode {
m, ok := modeMap["playlist"]
m, ok := modeMap[playlist.GROUPRESOURCE]
if !dualWrite || !ok {
return grafanarest.Mode0
}
Expand Down Expand Up @@ -133,7 +133,7 @@ func (b *PlaylistAPIBuilder) GetAPIGroupInfo(
return nil, err
}

dualWriter, err := grafanarest.SetDualWritingMode(context.Background(), b.kvStore, legacyStore, store, "playlist", desiredMode)
dualWriter, err := grafanarest.SetDualWritingMode(context.Background(), b.kvStore, legacyStore, store, playlist.GROUPRESOURCE, desiredMode)
if err != nil {
return nil, err
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/services/apiserver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"path/filepath"
"strconv"

playlist "github.com/grafana/grafana/pkg/apis/playlist/v0alpha1"
grafanarest "github.com/grafana/grafana/pkg/apiserver/rest"
"github.com/grafana/grafana/pkg/services/apiserver/options"
"github.com/grafana/grafana/pkg/services/featuremgmt"
Expand Down Expand Up @@ -56,7 +57,7 @@ func applyGrafanaConfig(cfg *setting.Cfg, features featuremgmt.FeatureToggles, o
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.DualWriterDesiredModes = map[string]grafanarest.DualWriterMode{
"playlist": grafanarest.DualWriterMode(unifiedStorageModeCfg.Key("playlist").MustInt(0)),
playlist.GROUPRESOURCE: grafanarest.DualWriterMode(unifiedStorageModeCfg.Key(playlist.GROUPRESOURCE).MustInt(0)),
}
o.ExtraOptions.DevMode = features.IsEnabledGlobally(featuremgmt.FlagGrafanaAPIServerEnsureKubectlAccess)
o.ExtraOptions.ExternalAddress = host
Expand Down
19 changes: 10 additions & 9 deletions pkg/tests/apis/playlist/playlist_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime/schema"

playlistv0alpha1 "github.com/grafana/grafana/pkg/apis/playlist/v0alpha1"
grafanarest "github.com/grafana/grafana/pkg/apiserver/rest"
"github.com/grafana/grafana/pkg/services/featuremgmt"
"github.com/grafana/grafana/pkg/services/playlist"
Expand Down Expand Up @@ -95,7 +96,7 @@ func TestIntegrationPlaylist(t *testing.T) {
featuremgmt.FlagKubernetesPlaylists, // Required so that legacy calls are also written
},
DualWriterDesiredModes: map[string]grafanarest.DualWriterMode{
"playlist": grafanarest.Mode0,
playlistv0alpha1.GROUPRESOURCE: grafanarest.Mode0,
},
}))
})
Expand All @@ -111,7 +112,7 @@ func TestIntegrationPlaylist(t *testing.T) {
// featuremgmt.FlagKubernetesPlaylists, // Required so that legacy calls are also written
// },
// DualWriterDesiredModes: map[string]grafanarest.DualWriterMode{
// "playlist": grafanarest.Mode1,
// playlistv0alpha1.GROUPRESOURCE: grafanarest.Mode1,
// },
// }))
// })
Expand All @@ -125,7 +126,7 @@ func TestIntegrationPlaylist(t *testing.T) {
featuremgmt.FlagKubernetesPlaylists, // Required so that legacy calls are also written
},
DualWriterDesiredModes: map[string]grafanarest.DualWriterMode{
"playlist": grafanarest.Mode2,
playlistv0alpha1.GROUPRESOURCE: grafanarest.Mode2,
},
}))
})
Expand All @@ -140,7 +141,7 @@ func TestIntegrationPlaylist(t *testing.T) {
featuremgmt.FlagKubernetesPlaylists, // Required so that legacy calls are also written
},
DualWriterDesiredModes: map[string]grafanarest.DualWriterMode{
"playlist": grafanarest.Mode0,
playlistv0alpha1.GROUPRESOURCE: grafanarest.Mode0,
},
}))
})
Expand All @@ -157,7 +158,7 @@ func TestIntegrationPlaylist(t *testing.T) {
// featuremgmt.FlagKubernetesPlaylists, // Required so that legacy calls are also written
// },
// DualWriterDesiredModes: map[string]grafanarest.DualWriterMode{
// "playlist": grafanarest.Mode1,
// playlistv0alpha1.GROUPRESOURCE: grafanarest.Mode1,
// },
// }))
// })
Expand All @@ -172,7 +173,7 @@ func TestIntegrationPlaylist(t *testing.T) {
featuremgmt.FlagKubernetesPlaylists, // Required so that legacy calls are also written
},
DualWriterDesiredModes: map[string]grafanarest.DualWriterMode{
"playlist": grafanarest.Mode2,
playlistv0alpha1.GROUPRESOURCE: grafanarest.Mode2,
},
}))
})
Expand All @@ -189,7 +190,7 @@ func TestIntegrationPlaylist(t *testing.T) {
featuremgmt.FlagKubernetesPlaylists, // Required so that legacy calls are also written
},
DualWriterDesiredModes: map[string]grafanarest.DualWriterMode{
"playlist": grafanarest.Mode0,
playlistv0alpha1.GROUPRESOURCE: grafanarest.Mode0,
},
})

Expand All @@ -216,7 +217,7 @@ func TestIntegrationPlaylist(t *testing.T) {
featuremgmt.FlagKubernetesPlaylists, // Required so that legacy calls are also written
},
DualWriterDesiredModes: map[string]grafanarest.DualWriterMode{
"playlist": grafanarest.Mode1,
playlistv0alpha1.GROUPRESOURCE: grafanarest.Mode1,
},
})

Expand All @@ -243,7 +244,7 @@ func TestIntegrationPlaylist(t *testing.T) {
featuremgmt.FlagKubernetesPlaylists, // Required so that legacy calls are also written
},
DualWriterDesiredModes: map[string]grafanarest.DualWriterMode{
"playlist": grafanarest.Mode2,
playlistv0alpha1.GROUPRESOURCE: grafanarest.Mode2,
},
})

Expand Down

0 comments on commit 0ae476a

Please sign in to comment.