Registry health check never marks a registry unhealthy when adapter creation fails
Version: v2.15.2 (helm chart 1.19.2)
What happened
If creating the adapter fails during the periodic health check, the registry keeps whatever status it had last. For proxy cache projects, that means Harbor never switches to serving from local during an upstream outage.
In controller/registry/controller.go, StartRegularHealthCheck does:
if err != nil {
log.Errorf("failed to check health of registry %d: %v", registry.ID, err)
continue
}Adapters that make network calls in their constructor hit this path whenever the upstream is unreachable:
docker-hublogs in duringNewClientharborcalls/api/version
Steps to reproduce
- Create proxy cache projects for a
docker-hubendpoint (with credentials), aharborendpoint, and anydocker-registryendpoint. - Pull an image through each so it's cached.
- Block egress from harbor-core, for example with a NetworkPolicy that only allows in-namespace traffic and DNS.
- Wait a couple of health check cycles and look at
GET /api/v2.0/registries.
Expected: all three endpoints go unhealthy, and cached pulls are served locally without contacting upstream.
Actual: only the docker-registry endpoint goes unhealthy. The docker-hub and harbor endpoints stay
healthy, and their update_time doesn't change. Every pull through them keeps trying upstream and waits out the
connect timeout before falling back, about 90s per pull in our test.
failed to check health of registry 1: login to dockerhub error: Post "https://hub.docker.com/v2/auth/token": dial
tcp 104.18.43.187:443: i/o timeout
failed to check health of registry 221: Get "https://reg.mini.dev/api/version": dial tcp 34.8.39.64:443: i/o
timeoutSuggested fix: treat an error from IsHealthy as unhealthy instead of skipping the update.
Related: #21673 (the same problem for harbor endpoints, closed as not planned) and #16242 (the same log line
for Docker Hub, closed as stale). #23867 removes the eager Docker Hub login, which should fix that adapter, but the
controller will still skip any adapter that fails on creation.
Source: goharbor/harbor