1
0
mirror of https://github.com/rancher/steve.git synced 2025-09-01 23:47:50 +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

@@ -221,6 +221,7 @@ type TransformBuilder interface {
}
type Store struct {
ctx context.Context
clientGetter ClientGetter
notifier RelationshipNotifier
cacheFactory CacheFactory
@@ -234,13 +235,14 @@ type Store struct {
type CacheFactoryInitializer func() (CacheFactory, error)
type CacheFactory interface {
CacheFor(fields [][]string, transform cache.TransformFunc, client dynamic.ResourceInterface, gvk schema.GroupVersionKind, namespaced bool, watchable bool) (factory.Cache, error)
CacheFor(ctx context.Context, fields [][]string, transform cache.TransformFunc, client dynamic.ResourceInterface, gvk schema.GroupVersionKind, namespaced bool, watchable bool) (factory.Cache, error)
Reset() error
}
// NewProxyStore returns a Store implemented directly on top of kubernetes.
func NewProxyStore(c SchemaColumnSetter, clientGetter ClientGetter, notifier RelationshipNotifier, scache virtualCommon.SummaryCache, factory CacheFactory) (*Store, error) {
func NewProxyStore(ctx context.Context, c SchemaColumnSetter, clientGetter ClientGetter, notifier RelationshipNotifier, scache virtualCommon.SummaryCache, factory CacheFactory) (*Store, error) {
store := &Store{
ctx: ctx,
clientGetter: clientGetter,
notifier: notifier,
columnSetter: c,
@@ -291,7 +293,7 @@ func (s *Store) initializeNamespaceCache() error {
nsSchema := baseNSSchema
// make sure any relevant columns are set to the ns schema
if err := s.columnSetter.SetColumns(context.Background(), &nsSchema); err != nil {
if err := s.columnSetter.SetColumns(s.ctx, &nsSchema); err != nil {
return fmt.Errorf("failed to set columns for proxy stores namespace informer: %w", err)
}
@@ -314,7 +316,7 @@ func (s *Store) initializeNamespaceCache() error {
// get the ns informer
tableClient := &tablelistconvert.Client{ResourceInterface: client}
attrs := attributes.GVK(&nsSchema)
nsInformer, err := s.cacheFactory.CacheFor(fields, transformFunc, tableClient, attrs, false, true)
nsInformer, err := s.cacheFactory.CacheFor(s.ctx, fields, transformFunc, tableClient, attrs, false, true)
if err != nil {
return err
}
@@ -756,7 +758,7 @@ func (s *Store) ListByPartitions(apiOp *types.APIRequest, schema *types.APISchem
tableClient := &tablelistconvert.Client{ResourceInterface: client}
attrs := attributes.GVK(schema)
ns := attributes.Namespaced(schema)
inf, err := s.cacheFactory.CacheFor(fields, transformFunc, tableClient, attrs, ns, controllerschema.IsListWatchable(schema))
inf, err := s.cacheFactory.CacheFor(s.ctx, fields, transformFunc, tableClient, attrs, ns, controllerschema.IsListWatchable(schema))
if err != nil {
return nil, 0, "", err
}