From e22abf0fab74cb0949db3d95e97de0179c9d1fe9 Mon Sep 17 00:00:00 2001 From: Stephen J Day Date: Tue, 6 Feb 2018 15:25:51 -0800 Subject: [PATCH 1/3] registry/storage: ignore missing tag on delete Signed-off-by: Stephen J Day (cherry picked from commit 1ba5b3b5538912ba239a376c0c84ea54a062103a) --- registry/storage/tagstore.go | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/registry/storage/tagstore.go b/registry/storage/tagstore.go index 4386ffca..96eb1c8d 100644 --- a/registry/storage/tagstore.go +++ b/registry/storage/tagstore.go @@ -122,17 +122,20 @@ func (ts *tagStore) Untag(ctx context.Context, tag string) error { name: ts.repository.Named().Name(), tag: tag, }) - - switch err.(type) { - case storagedriver.PathNotFoundError: - return distribution.ErrTagUnknown{Tag: tag} - case nil: - break - default: + if err != nil { return err } - return ts.blobStore.driver.Delete(ctx, tagPath) + if err := ts.blobStore.driver.Delete(ctx, tagPath); err != nil { + switch err.(type) { + case storagedriver.PathNotFoundError: + return nil // Untag is idempotent, we don't care if it didn't exist + default: + return err + } + } + + return nil } // linkedBlobStore returns the linkedBlobStore for the named tag, allowing one From 9b36527ddd08a0aa819610ebafd3612da83c5b14 Mon Sep 17 00:00:00 2001 From: Wenkai Yin Date: Thu, 8 Feb 2018 17:28:22 +0800 Subject: [PATCH 2/3] ignore path not found error when look up tags Signed-off-by: Wenkai Yin (cherry picked from commit 005c6e0236c98544d35197a17947c02e23bc9223) --- registry/storage/tagstore.go | 4 ++++ registry/storage/tagstore_test.go | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/registry/storage/tagstore.go b/registry/storage/tagstore.go index 96eb1c8d..be7baf87 100644 --- a/registry/storage/tagstore.go +++ b/registry/storage/tagstore.go @@ -182,6 +182,10 @@ func (ts *tagStore) Lookup(ctx context.Context, desc distribution.Descriptor) ([ tagLinkPath, err := pathFor(tagLinkPathSpec) tagDigest, err := ts.blobStore.readlink(ctx, tagLinkPath) if err != nil { + switch err.(type) { + case storagedriver.PathNotFoundError: + continue + } return nil, err } diff --git a/registry/storage/tagstore_test.go b/registry/storage/tagstore_test.go index 554a46bf..0c8e3611 100644 --- a/registry/storage/tagstore_test.go +++ b/registry/storage/tagstore_test.go @@ -84,8 +84,8 @@ func TestTagStoreUnTag(t *testing.T) { desc := distribution.Descriptor{Digest: "sha256:bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"} err := tags.Untag(ctx, "latest") - if err == nil { - t.Errorf("Expected error untagging non-existant tag") + if err != nil { + t.Error(err) } err = tags.Tag(ctx, "latest", desc) From 376cbc0cc183c0da46c92afb5ec6455b67ea0df6 Mon Sep 17 00:00:00 2001 From: Noah Treuhaft Date: Wed, 8 Feb 2017 11:38:44 -0800 Subject: [PATCH 3/3] notifications: fix expvar for Go 1.7 Remove EndpointConfig.Transport from the return value of the registry.notifications.endpoints expvar.Func. It results in an empty value for that expvar variable under Go 1.7 because it is a non-nil *http.Transport, which Go 1.7 can no longer encode as JSON. Signed-off-by: Noah Treuhaft (cherry picked from commit 9a58c91051e03b46f1461e371a7bf527c1284612) --- notifications/endpoint.go | 2 +- notifications/metrics_test.go | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 notifications/metrics_test.go diff --git a/notifications/endpoint.go b/notifications/endpoint.go index 29a9e27b..44d0f6d7 100644 --- a/notifications/endpoint.go +++ b/notifications/endpoint.go @@ -13,7 +13,7 @@ type EndpointConfig struct { Threshold int Backoff time.Duration IgnoredMediaTypes []string - Transport *http.Transport + Transport *http.Transport `json:"-"` } // defaults set any zero-valued fields to a reasonable default. diff --git a/notifications/metrics_test.go b/notifications/metrics_test.go new file mode 100644 index 00000000..03a08e2c --- /dev/null +++ b/notifications/metrics_test.go @@ -0,0 +1,28 @@ +package notifications + +import ( + "encoding/json" + "expvar" + "testing" +) + +func TestMetricsExpvar(t *testing.T) { + endpointsVar := expvar.Get("registry").(*expvar.Map).Get("notifications").(*expvar.Map).Get("endpoints") + + var v interface{} + if err := json.Unmarshal([]byte(endpointsVar.String()), &v); err != nil { + t.Fatalf("unexpected error unmarshaling endpoints: %v", err) + } + if v != nil { + t.Fatalf("expected nil, got %#v", v) + } + + NewEndpoint("x", "y", EndpointConfig{}) + + if err := json.Unmarshal([]byte(endpointsVar.String()), &v); err != nil { + t.Fatalf("unexpected error unmarshaling endpoints: %v", err) + } + if slice, ok := v.([]interface{}); !ok || len(slice) != 1 { + t.Logf("expected one-element []interface{}, got %#v", v) + } +}