1
0
mirror of https://github.com/rancher/steve.git synced 2025-09-25 14:49:38 +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

@@ -35,14 +35,14 @@ var newInformer = cache.NewSharedIndexInformer
// NewInformer returns a new SQLite-backed Informer for the type specified by schema in unstructured.Unstructured form
// using the specified client
func NewInformer(client dynamic.ResourceInterface, fields [][]string, transform cache.TransformFunc, gvk schema.GroupVersionKind, db db.Client, shouldEncrypt bool, namespaced bool) (*Informer, error) {
func NewInformer(ctx context.Context, client dynamic.ResourceInterface, fields [][]string, transform cache.TransformFunc, gvk schema.GroupVersionKind, db db.Client, shouldEncrypt bool, namespaced bool) (*Informer, error) {
listWatcher := &cache.ListWatch{
ListFunc: func(options metav1.ListOptions) (runtime.Object, error) {
a, err := client.List(context.Background(), options)
a, err := client.List(ctx, options)
return a, err
},
WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) {
return client.Watch(context.Background(), options)
return client.Watch(ctx, options)
},
}
@@ -69,11 +69,11 @@ func NewInformer(client dynamic.ResourceInterface, fields [][]string, transform
name := informerNameFromGVK(gvk)
s, err := sqlStore.NewStore(example, cache.DeletionHandlingMetaNamespaceKeyFunc, db, shouldEncrypt, name)
s, err := sqlStore.NewStore(ctx, example, cache.DeletionHandlingMetaNamespaceKeyFunc, db, shouldEncrypt, name)
if err != nil {
return nil, err
}
loi, err := NewListOptionIndexer(fields, s, namespaced)
loi, err := NewListOptionIndexer(ctx, fields, s, namespaced)
if err != nil {
return nil, err
}