kvstore: merge the metadata store into the datastore (#110334)

* migrate eventstore to datastore

* Add folder to event key

* lint

* lint

* lint

* lint

* remove foundkye

* refactor the Keys methods to move the Sort outside the ListKey method

* remove bad import

* fix missing params

* lint

* fix test

* perf improvement
This commit is contained in:
Georges Chaudy
2025-09-16 12:16:29 +02:00
committed by GitHub
parent 8a352cc352
commit c251ebf4d5
8 changed files with 1943 additions and 2158 deletions
+10 -4
View File
@@ -28,10 +28,11 @@ type EventKey struct {
Name string
ResourceVersion int64
Action DataAction
Folder string
}
func (k EventKey) String() string {
return fmt.Sprintf("%d~%s~%s~%s~%s~%s", k.ResourceVersion, k.Namespace, k.Group, k.Resource, k.Name, k.Action)
return fmt.Sprintf("%d~%s~%s~%s~%s~%s~%s", k.ResourceVersion, k.Namespace, k.Group, k.Resource, k.Name, k.Action, k.Folder)
}
func (k EventKey) Validate() error {
@@ -53,7 +54,9 @@ func (k EventKey) Validate() error {
if k.Action == "" {
return fmt.Errorf("action cannot be empty")
}
if k.Folder != "" && !validNameRegex.MatchString(k.Folder) {
return fmt.Errorf("folder '%s' is invalid", k.Folder)
}
// Validate each field against the naming rules (reusing the regex from datastore.go)
if !validNameRegex.MatchString(k.Namespace) {
return fmt.Errorf("namespace '%s' is invalid", k.Namespace)
@@ -67,7 +70,9 @@ func (k EventKey) Validate() error {
if !validNameRegex.MatchString(k.Name) {
return fmt.Errorf("name '%s' is invalid", k.Name)
}
if k.Folder != "" && !validNameRegex.MatchString(k.Folder) {
return fmt.Errorf("folder '%s' is invalid", k.Folder)
}
switch k.Action {
case DataActionCreated, DataActionUpdated, DataActionDeleted:
default:
@@ -97,7 +102,7 @@ func newEventStore(kv KV) *eventStore {
// ParseEventKey parses a key string back into an EventKey struct
func ParseEventKey(key string) (EventKey, error) {
parts := strings.Split(key, "~")
if len(parts) != 6 {
if len(parts) != 7 {
return EventKey{}, fmt.Errorf("invalid key format: expected 6 parts, got %d", len(parts))
}
@@ -113,6 +118,7 @@ func ParseEventKey(key string) (EventKey, error) {
Resource: parts[3],
Name: parts[4],
Action: DataAction(parts[5]),
Folder: parts[6],
}, nil
}