Problem
The /livez liveness probe fails when the database is unavailable, defeating its purpose. The LivezView itself has no DB dependency — it just returns Response() with empty authentication_classes and permission_classes. However, DomainMiddleware.process_view() runs Domain.objects.get() on every request, including /livez/, causing the probe to fail with a database error.
Other middleware in the stack (SessionMiddleware, AuthenticationMiddleware) are lazy and don't hit the DB unless request.session or request.user is accessed, which LivezView never does. DomainMiddleware is the only eager DB dependency.
Proposed fix
Add a skip_domain_middleware marker to LivezView and teach DomainMiddleware.process_view() to skip the Domain.objects.get() lookup when the flag is set:
# pulpcore/app/views/status.py
class LivezView(APIView):
authentication_classes = []
permission_classes = []
skip_domain_middleware = True
# pulpcore/middleware.py — DomainMiddleware.process_view()
def process_view(self, request, view_func, view_args, view_kwargs):
view_class = getattr(view_func, "view_class", None) or getattr(view_func, "cls", None)
if view_class and getattr(view_class, "skip_domain_middleware", False):
view_kwargs.pop("pulp_domain", None)
return None
# ... existing Domain.objects.get() logic
Use case
Kubernetes liveness probes should only check that the gunicorn worker is responsive. When the database is temporarily unavailable (maintenance, failover), pods should not be killed and restarted — the workers are still alive and will recover when the DB returns. The current behavior causes cascading pod restarts during DB outages.
Problem
The
/livezliveness probe fails when the database is unavailable, defeating its purpose. TheLivezViewitself has no DB dependency — it just returnsResponse()with emptyauthentication_classesandpermission_classes. However,DomainMiddleware.process_view()runsDomain.objects.get()on every request, including/livez/, causing the probe to fail with a database error.Other middleware in the stack (
SessionMiddleware,AuthenticationMiddleware) are lazy and don't hit the DB unlessrequest.sessionorrequest.useris accessed, whichLivezViewnever does.DomainMiddlewareis the only eager DB dependency.Proposed fix
Add a
skip_domain_middlewaremarker toLivezViewand teachDomainMiddleware.process_view()to skip theDomain.objects.get()lookup when the flag is set:Use case
Kubernetes liveness probes should only check that the gunicorn worker is responsive. When the database is temporarily unavailable (maintenance, failover), pods should not be killed and restarted — the workers are still alive and will recover when the DB returns. The current behavior causes cascading pod restarts during DB outages.