[Feature]: Operator readiness probe should reflect informer cache sync, not healthz.Ping
Motivation
cmd/gpu-operator/main.go:255 registers mgr.AddReadyzCheck("check", healthz.Ping), so the operator pod reports Ready as soon as the HTTP server starts, before its informer caches have synced. Rollouts, PodDisruptionBudgets and monitoring treat a new operator replica as serving while it cannot yet reconcile.
Proposal
Register a readiness checker that fails until the manager's cache has synced, e.g. a closure calling mgr.GetCache().WaitForCacheSync with a short timeout, and keep healthz.Ping for liveness only.
@CloneOfAlex
Could you provide more details about the problem you encountered and your proposed solution?
Thanks @francisguillier, here's the detail, including one correction to my own proposal.
The problem
cmd/gpu-operator/main.go:255 registers mgr.AddReadyzCheck("check", healthz.Ping). /readyz (the chart's readinessProbe, operator.yaml:92) returns 200 as soon as the probe server starts, which in controllerManager.Start happens before caches start, before leader election, and before any controller runs. So "Ready" says nothing about whether the operator can reconcile.
Where that matters is upgrades. The chart runs 1 replica with the default RollingUpdate (so maxSurge 1 / maxUnavailable 0) and --leader-elect. The sequence on helm upgrade is:
- New pod starts,
/readyzpasses immediately → Deployment terminates the old pod;helm upgrade --wait/kubectl rollout statusreport success. - New pod waits for the lease (no
LeaderElectionReleaseOnCancel, so up to the lease duration), then starts controllers, which start their informers. - If an informer can't sync (most commonly an RBAC regression, e.g. a new watched kind whose
list/watchpermission didn't make it into the ClusterRole), controllers hitCacheSyncTimeout(2 min), the manager exits, and the pod crash-loops.
At that point the old, working pod is already gone and the rollout was reported successful. A readiness gate that actually depends on the informers would have stalled the rollout at step 1 and left the old pod running.
Correction to my original proposal
I proposed gating readiness on mgr.GetCache().WaitForCacheSync. On its own, that doesn't fix the rollout case. Before a replica holds the lease, only informers created during setup exist: the IndexField calls for Pods and DaemonSets (clusterpolicy_controller.go:523, nvidiadriver_controller.go:463, nodelabeling_controller.go:683). Controller watches are started in Kind.Start when the controller starts, which is leader-only. So on the incoming pod, WaitForCacheSync would pass almost immediately.
The fix needs controller warmup as well. controller-runtime v0.25 (vendored here) has config.Controller.EnableWarmup, which starts controller sources before leader election. With it, the incoming replica creates and syncs every watched informer while still a follower, and the readiness check covers them.
Proposed change
@@ ctrl.Options
Cache: cacheOptions,
+ Controller: ctrlconfig.Controller{EnableWarmup: ptr.To(true)},
}
@@
- if err := mgr.AddReadyzCheck("check", healthz.Ping); err != nil {
+ if err := mgr.AddReadyzCheck("cache-sync", cacheSyncedCheck(mgr.GetCache(), 500*time.Millisecond)); err != nil {
Checker + unit test (cmd/gpu-operator/readyz.go, readyz_test.go)
package main
import (
"context"
"errors"
"net/http"
"time"
"sigs.k8s.io/controller-runtime/pkg/cache"
"sigs.k8s.io/controller-runtime/pkg/healthz"
)
// cacheSyncedCheck reports ready only once every informer started so far has
// synced. It never blocks longer than timeout, so a slow sync shows up as a
// failed probe rather than a hung one.
func cacheSyncedCheck(c cache.Cache, timeout time.Duration) healthz.Checker {
return func(req *http.Request) error {
ctx, cancel := context.WithTimeout(req.Context(), timeout)
defer cancel()
if !c.WaitForCacheSync(ctx) {
return errors.New("informer caches not synced")
}
return nil
}
}
package main
import (
"context"
"net/http/httptest"
"sync/atomic"
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"sigs.k8s.io/controller-runtime/pkg/cache"
)
// syncCache is a cache.Cache whose sync state the test controls. Only
// WaitForCacheSync is used by the checker; the embedded interface is nil.
type syncCache struct {
cache.Cache
synced atomic.Bool
}
func (s *syncCache) WaitForCacheSync(ctx context.Context) bool {
for {
if s.synced.Load() {
return true
}
select {
case <-ctx.Done():
return false
case <-time.After(5 * time.Millisecond):
}
}
}
func TestCacheSyncedCheck(t *testing.T) {
c := &syncCache{}
check := cacheSyncedCheck(c, 50*time.Millisecond)
req := httptest.NewRequest("GET", "/readyz", nil)
start := time.Now()
err := check(req)
require.Error(t, err, "must not report ready before caches sync")
assert.Less(t, time.Since(start), time.Second, "must respect the timeout, not hang the probe")
c.synced.Store(true)
assert.NoError(t, check(req), "must report ready once caches sync")
}
I applied this to current main: it builds, go vet is clean, and go test ./cmd/gpu-operator/ passes (the test covers not-ready before sync, the timeout not hanging the probe, and ready after sync). controller.New inherits EnableWarmup from the manager's controller config, so SetupWithManager needs no per-controller changes. Liveness stays on healthz.Ping.
Trade-offs
EnableWarmupis beta in controller-runtime. The default is off, and it's a one-line revert if needed.- Warm followers hold full informers. With 1 replica that only applies during a rollout, but it also means watch/list load and memory for the incoming pod before it leads. As a side effect, failover gets faster because caches are pre-populated.
- Slower Ready on cold start. By design, Ready now waits for the initial list of every watched kind. The chart's
readinessProbe(5s initial delay, 10s period, default 1stimeoutSeconds) is fine: the checker gives up after 500ms so it always answers before kubelet's timeout, but on very large clusters the probe will simply report not-ready for longer.
To be transparent: this comes from code review, not an observed incident. I don't have an envtest-based end-to-end repro of the rollout scenario. The leader-election behavior above is from reading the vendored controller-runtime (manager/internal.go, internal/source/kind.go, internal/controller/controller.go). I'm happy to open a PR with the change and the test.
@CloneOfAlex
I’m not sure I understand the deployment problem you’re trying to solve. Could you please provide:
- Issue summary: What is happening, and what behavior do you expect?
- Steps to reproduce: Include the relevant environment details and configuration.
- Proposed fix: Explain how the fix addresses the problem. Without these details, we won’t be able to assess the issue and will close it. Thanks
@francisguillier here it is in that format.
Issue summary
The operator's readiness probe (/readyz) is healthz.Ping, so a new operator pod reports Ready as soon as its HTTP server starts, before it holds the leader lease or has synced any informer. During a helm upgrade, the Deployment then terminates the old, working pod and the rollout is reported successful. If the new pod can't sync its caches (for example an RBAC regression in the new ClusterRole), it crash-loops about 2 minutes later, and nothing is reconciling. Expected: the new pod isn't Ready until it can reconcile, so the rollout stalls and the old pod keeps running.
Steps to reproduce
- Install the operator (1 replica, default RollingUpdate,
--leader-elect). - Remove
list/watchon one watched kind (e.g.nvidiadrivers) from thegpu-operatorClusterRole to simulate an RBAC regression. kubectl -n gpu-operator rollout restart deploy/gpu-operator && kubectl -n gpu-operator rollout status deploy/gpu-operator- The rollout reports success and the old pod is terminated. Once the new pod takes the lease, the controller times out waiting for its cache to sync (2 min
CacheSyncTimeout) and the pod restarts in a loop.
I haven't run this on a cluster yet; the sequence comes from the vendored controller-runtime code. The readiness checker itself has a unit test (previous comment).
Proposed fix
Enable controller warmup (config.Controller.EnableWarmup) so a follower starts and syncs its informers before leading. Replace the readyz check with one that fails until the cache has synced, bounded by a 500 ms timeout. Keep healthz.Ping for liveness. It's a one-file change plus a test, which I'm happy to send.