Skip to content

Commit

Permalink
Recognize "manifest unknown" errors reported by Harbor
Browse files Browse the repository at this point in the history
... per data in containers#2203 .

Signed-off-by: Miloslav Trmač <[email protected]>
  • Loading branch information
mtrmac committed May 16, 2024
1 parent 4f07d28 commit 23d7e70
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
5 changes: 5 additions & 0 deletions docker/docker_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1097,6 +1097,11 @@ func isManifestUnknownError(err error) bool {
if errors.As(err, &e) && e.ErrorCode() == errcode.ErrorCodeUnknown && e.Message == "Not Found" {
return true
}
// Harbor v2.10.2
if errors.As(err, &e) && e.ErrorCode() == errcode.ErrorCodeUnknown && strings.Contains(strings.ToLower(e.Message), "not found") {
return true
}

// opencontainers/distribution-spec does not require the errcode.Error payloads to be used,
// but specifies that the HTTP status must be 404.
var unexpected *unexpectedHTTPResponseError
Expand Down
15 changes: 14 additions & 1 deletion docker/docker_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,13 +392,26 @@ func TestIsManifestUnknownError(t *testing.T) {
"\r\n" +
"Not found\r\n",
},
{
name: "Harbor v2.10.2",
response: "HTTP/1.1 404 Not Found\r\n" +
"Content-Length: 153\r\n" +
"Connection: keep-alive\r\n" +
"Content-Type: application/json; charset=utf-8\r\n" +
"Date: Wed, 08 May 2024 08:14:59 GMT\r\n" +
"Server: nginx\r\n" +
"Set-Cookie: sid=f617c257877837614ada2561513d6827; Path=/; HttpOnly\r\n" +
"X-Request-Id: 1b151fb1-c943-4190-a9ce-5156ed5e3200\r\n" +
"\r\n" +
"{\"errors\":[{\"code\":\"NOT_FOUND\",\"message\":\"artifact test/alpine:sha256-443205b0cfcc78444321d56a2fe273f06e27b2c72b5058f8d7e975997d45b015.sig not found\"}]}\n",
},
} {
resp, err := http.ReadResponse(bufio.NewReader(bytes.NewReader([]byte(c.response))), nil)
require.NoError(t, err, c.name)
defer resp.Body.Close()
err = fmt.Errorf("wrapped: %w", registryHTTPResponseToError(resp))

res := isManifestUnknownError(err)
assert.True(t, res, "%#v", err, c.name)
assert.True(t, res, "%s: %#v", c.name, err)
}
}
28 changes: 28 additions & 0 deletions docker/errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,34 @@ func TestRegistryHTTPResponseToError(t *testing.T) {
assert.Equal(t, []byte("Not found\r"), e.Response)
},
},
{ // Harbor v2.10.2 uses an unspecified NOT_FOUND error code
name: "Harbor v2.10.2 manifest not found",
response: "HTTP/1.1 404 Not Found\r\n" +
"Content-Length: 153\r\n" +
"Connection: keep-alive\r\n" +
"Content-Type: application/json; charset=utf-8\r\n" +
"Date: Wed, 08 May 2024 08:14:59 GMT\r\n" +
"Server: nginx\r\n" +
"Set-Cookie: sid=f617c257877837614ada2561513d6827; Path=/; HttpOnly\r\n" +
"X-Request-Id: 1b151fb1-c943-4190-a9ce-5156ed5e3200\r\n" +
"\r\n" +
"{\"errors\":[{\"code\":\"NOT_FOUND\",\"message\":\"artifact test/alpine:sha256-443205b0cfcc78444321d56a2fe273f06e27b2c72b5058f8d7e975997d45b015.sig not found\"}]}\n",
errorString: "unknown: artifact test/alpine:sha256-443205b0cfcc78444321d56a2fe273f06e27b2c72b5058f8d7e975997d45b015.sig not found",
errorType: errcode.Error{},
unwrappedErrorPtr: &unwrappedErrcodeError,
errorCode: &errcode.ErrorCodeUnknown,
fn: func(t *testing.T, err error) {
var e errcode.Error
ok := errors.As(err, &e)
require.True(t, ok)
// isManifestUnknownError is checking for this
assert.Equal(t, errcode.Error{
Code: errcode.ErrorCodeUnknown, // The NOT_FOUND value is not defined, and turns into Unknown
Message: "artifact test/alpine:sha256-443205b0cfcc78444321d56a2fe273f06e27b2c72b5058f8d7e975997d45b015.sig not found",
Detail: nil,
}, e)
},
},
} {
res, err := http.ReadResponse(bufio.NewReader(bytes.NewReader([]byte(c.response))), nil)
require.NoError(t, err, c.name)
Expand Down

0 comments on commit 23d7e70

Please sign in to comment.