Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recognize "manifest unknown" errors reported by Harbor #2413

Merged
merged 1 commit into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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