Skip to content

Commit 53aece1

Browse files
authored
Merge pull request #273 from zong-zhe/fix-push-harbor
fix: fix the failure during push to harbor
2 parents b197e0b + 7db26cc commit 53aece1

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

pkg/oci/oci.go

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ import (
2929

3030
const OCI_SCHEME = "oci"
3131
const DEFAULT_OCI_ARTIFACT_TYPE = "application/vnd.oci.image.layer.v1.tar"
32+
const (
33+
OciErrorCodeNameUnknown = "NAME_UNKNOWN"
34+
OciErrorCodeRepoNotFound = "NOT_FOUND"
35+
)
3236

3337
// Login will login 'hostname' by 'username' and 'password'.
3438
func Login(hostname, username, password string, setting *settings.Settings) error {
@@ -180,6 +184,21 @@ func (ociClient *OciClient) TheLatestTag() (string, error) {
180184
return tagSelected, nil
181185
}
182186

187+
// RepoIsNotExist will check if the error is caused by the repo not found.
188+
func RepoIsNotExist(err error) bool {
189+
errRes, ok := err.(*errcode.ErrorResponse)
190+
if ok {
191+
if len(errRes.Errors) == 1 &&
192+
// docker.io and gchr.io will return NAME_UNKNOWN
193+
(errRes.Errors[0].Code == OciErrorCodeNameUnknown ||
194+
// harbor will return NOT_FOUND
195+
errRes.Errors[0].Code == OciErrorCodeRepoNotFound) {
196+
return true
197+
}
198+
}
199+
return false
200+
}
201+
183202
// ContainsTag will check if the tag exists in the repo.
184203
func (ociClient *OciClient) ContainsTag(tag string) (bool, *reporter.KpmEvent) {
185204
var exists bool
@@ -191,11 +210,8 @@ func (ociClient *OciClient) ContainsTag(tag string) (bool, *reporter.KpmEvent) {
191210

192211
if err != nil {
193212
// If the repo with tag is not found, return false.
194-
errRes, ok := err.(*errcode.ErrorResponse)
195-
if ok {
196-
if len(errRes.Errors) == 1 && errRes.Errors[0].Code == errcode.ErrorCodeNameUnknown {
197-
return false, nil
198-
}
213+
if RepoIsNotExist(err) {
214+
return false, nil
199215
}
200216
// If the user not login, return error.
201217
return false, reporter.NewErrorEvent(

0 commit comments

Comments
 (0)