Skip to content

Commit 070d1bc

Browse files
author
Andrey Klimentyev
authored
Merge pull request deckhouse#46 from sboschman/absent_check
Use HEAD response statuscode for error checks
2 parents b1589b4 + 15b1339 commit 070d1bc

File tree

1 file changed

+4
-21
lines changed

1 file changed

+4
-21
lines changed

pkg/registry_checker/image_pull.go

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package registry_checker
22

33
import (
44
"errors"
5+
"net/http"
56

67
"github.com/google/go-containerregistry/pkg/v1/remote"
78
"github.com/google/go-containerregistry/pkg/v1/remote/transport"
@@ -15,13 +16,7 @@ func IsAbsent(err error) bool {
1516
return false
1617
}
1718

18-
for _, transportError := range transpErr.Errors {
19-
if transportError.Code == transport.ManifestUnknownErrorCode {
20-
return true
21-
}
22-
}
23-
24-
return false
19+
return transpErr.StatusCode == http.StatusNotFound
2520
}
2621

2722
func IsAuthnFail(err error) bool {
@@ -32,13 +27,7 @@ func IsAuthnFail(err error) bool {
3227
return false
3328
}
3429

35-
for _, transportError := range transpErr.Errors {
36-
if transportError.Code == transport.UnauthorizedErrorCode {
37-
return true
38-
}
39-
}
40-
41-
return false
30+
return transpErr.StatusCode == http.StatusUnauthorized
4231
}
4332

4433
func IsAuthzFail(err error) bool {
@@ -49,13 +38,7 @@ func IsAuthzFail(err error) bool {
4938
return false
5039
}
5140

52-
for _, transportError := range transpErr.Errors {
53-
if transportError.Code == transport.DeniedErrorCode {
54-
return true
55-
}
56-
}
57-
58-
return false
41+
return transpErr.StatusCode == http.StatusForbidden
5942
}
6043

6144
func IsOldRegistry(err error) bool {

0 commit comments

Comments
 (0)