1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

registry: EndPointV1.Ping() remove redundant "Standalone" and cleanup logs

Standalone is a boolean, so false by default; also cleanup some debug logs
(probably more logs can be removed)

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2021-10-07 16:26:39 +02:00
parent 37dc2582d1
commit 9dbec13362
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C

View file

@ -131,29 +131,28 @@ func (e *V1Endpoint) Path(path string) string {
// Ping returns a PingResult which indicates whether the registry is standalone or not. // Ping returns a PingResult which indicates whether the registry is standalone or not.
func (e *V1Endpoint) Ping() (PingResult, error) { func (e *V1Endpoint) Ping() (PingResult, error) {
logrus.Debugf("attempting v1 ping for registry endpoint %s", e)
if e.String() == IndexServer { if e.String() == IndexServer {
// Skip the check, we know this one is valid // Skip the check, we know this one is valid
// (and we never want to fallback to http in case of error) // (and we never want to fallback to http in case of error)
return PingResult{Standalone: false}, nil return PingResult{}, nil
} }
logrus.Debugf("attempting v1 ping for registry endpoint %s", e)
req, err := http.NewRequest(http.MethodGet, e.Path("_ping"), nil) req, err := http.NewRequest(http.MethodGet, e.Path("_ping"), nil)
if err != nil { if err != nil {
return PingResult{Standalone: false}, err return PingResult{}, err
} }
resp, err := e.client.Do(req) resp, err := e.client.Do(req)
if err != nil { if err != nil {
return PingResult{Standalone: false}, err return PingResult{}, err
} }
defer resp.Body.Close() defer resp.Body.Close()
jsonString, err := io.ReadAll(resp.Body) jsonString, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
return PingResult{Standalone: false}, fmt.Errorf("error while reading the http response: %s", err) return PingResult{}, fmt.Errorf("error while reading the http response: %s", err)
} }
// If the header is absent, we assume true for compatibility with earlier // If the header is absent, we assume true for compatibility with earlier
@ -166,13 +165,12 @@ func (e *V1Endpoint) Ping() (PingResult, error) {
// don't stop here. Just assume sane defaults // don't stop here. Just assume sane defaults
} }
if hdr := resp.Header.Get("X-Docker-Registry-Version"); hdr != "" { if hdr := resp.Header.Get("X-Docker-Registry-Version"); hdr != "" {
logrus.Debugf("Registry version header: '%s'", hdr)
info.Version = hdr info.Version = hdr
} }
logrus.Debugf("PingResult.Version: %q", info.Version) logrus.Debugf("PingResult.Version: %q", info.Version)
standalone := resp.Header.Get("X-Docker-Registry-Standalone") standalone := resp.Header.Get("X-Docker-Registry-Standalone")
logrus.Debugf("Registry standalone header: '%s'", standalone)
// Accepted values are "true" (case-insensitive) and "1". // Accepted values are "true" (case-insensitive) and "1".
if strings.EqualFold(standalone, "true") || standalone == "1" { if strings.EqualFold(standalone, "true") || standalone == "1" {
info.Standalone = true info.Standalone = true