1
0
mirror of https://github.com/rancher/steve.git synced 2025-09-03 16:35:25 +00:00

sql: propagate and use contexts (#465)

Previous SQLite-related code used context.Background() and context.TODO() because it was not developed with context awareness.

This commit propagates the main Steve context so that it can be used when interacting with SQL context-aware functions.

This PR removes all production-code use of context.Background() and context.TODO() and replaces test-code use of TODO with Background.

Contributes to rancher/rancher#47825
This commit is contained in:
Silvio Moioli
2025-02-12 09:46:10 +01:00
committed by GitHub
parent e71f8c455d
commit 3350323f91
16 changed files with 160 additions and 121 deletions

View File

@@ -73,12 +73,12 @@ const (
// NewListOptionIndexer returns a SQLite-backed cache.Indexer of unstructured.Unstructured Kubernetes resources of a certain GVK
// ListOptionIndexer is also able to satisfy ListOption queries on indexed (sub)fields.
// Fields are specified as slices (e.g. "metadata.resourceVersion" is ["metadata", "resourceVersion"])
func NewListOptionIndexer(fields [][]string, s Store, namespaced bool) (*ListOptionIndexer, error) {
func NewListOptionIndexer(ctx context.Context, fields [][]string, s Store, namespaced bool) (*ListOptionIndexer, error) {
// necessary in order to gob/ungob unstructured.Unstructured objects
gob.Register(map[string]interface{}{})
gob.Register([]interface{}{})
i, err := NewIndexer(cache.Indexers{}, s)
i, err := NewIndexer(ctx, cache.Indexers{}, s)
if err != nil {
return nil, err
}
@@ -114,7 +114,7 @@ func NewListOptionIndexer(fields [][]string, s Store, namespaced bool) (*ListOpt
qmarks := make([]string, len(indexedFields))
setStatements := make([]string, len(indexedFields))
err = l.WithTransaction(context.Background(), true, func(tx transaction.Client) error {
err = l.WithTransaction(ctx, true, func(tx transaction.Client) error {
_, err = tx.Exec(fmt.Sprintf(createFieldsTableFmt, dbName, strings.Join(columnDefs, ", ")))
if err != nil {
return err