Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ func main() {
if err = (&controller.CachedImageReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
PacingEngine: pacing.NewEngine(mgr.GetClient(), podNamespace),
PacingEngine: pacing.NewEngine(mgr.GetAPIReader(), podNamespace),
Recorder: mgr.GetEventRecorder("cachedimage-controller"),
PodNamespace: podNamespace,
}).SetupWithManager(mgr); err != nil {
Expand Down
2 changes: 0 additions & 2 deletions docs/go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
module github.com/corewire/drop/docs

go 1.26.0

require github.com/imfing/hextra v0.12.3 // indirect
2 changes: 0 additions & 2 deletions docs/go.sum
Original file line number Diff line number Diff line change
@@ -1,2 +0,0 @@
github.com/imfing/hextra v0.12.3 h1:DZHY2rUWYteyzjlHi9r4n7Bb5e2Q+6LXe4C1Dqn0ZjM=
github.com/imfing/hextra v0.12.3/go.mod h1:vi+yhpq8YPp/aghvJlNKVnJKcPJ/VyAEcfC1BSV9ARo=
14 changes: 9 additions & 5 deletions internal/pacing/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,17 @@ type Decision struct {

// Engine evaluates pacing constraints before creating new drop Pods.
type Engine struct {
Client client.Client
// Reader is used to list active pull Pods. It must bypass the informer cache
// (e.g. mgr.GetAPIReader()) so that pods created in the current reconcile
// cycle are visible to subsequent reconciles before the cache is updated.
Reader client.Reader
PodNamespace string
}

// NewEngine creates a new pacing engine.
func NewEngine(c client.Client, podNamespace string) *Engine {
return &Engine{Client: c, PodNamespace: podNamespace}
// NewEngine creates a new pacing engine. reader should be a direct API-server
// reader (mgr.GetAPIReader()) to avoid stale cache reads when counting active pods.
func NewEngine(reader client.Reader, podNamespace string) *Engine {
return &Engine{Reader: reader, PodNamespace: podNamespace}
}

const (
Expand Down Expand Up @@ -74,7 +78,7 @@ func (e *Engine) PullSlots(ctx context.Context, policy *v1alpha1.PullPolicy, cac
client.InNamespace(ns),
client.MatchingLabels{podbuilder.LabelManagedBy: podbuilder.LabelManagedByValue},
}
if err := e.Client.List(ctx, podList, listOpts...); err != nil {
if err := e.Reader.List(ctx, podList, listOpts...); err != nil {
return Decision{}, err
}

Expand Down