Merge pull request #1522 from RichardScothern/tag-events
Send tag events to notification listeners
This commit is contained in:
commit
0ef5587b76
@ -402,9 +402,9 @@ func (ms *manifests) Get(ctx context.Context, dgst digest.Digest, options ...dis
|
|||||||
)
|
)
|
||||||
|
|
||||||
for _, option := range options {
|
for _, option := range options {
|
||||||
if opt, ok := option.(withTagOption); ok {
|
if opt, ok := option.(distribution.WithTagOption); ok {
|
||||||
digestOrTag = opt.tag
|
digestOrTag = opt.Tag
|
||||||
ref, err = reference.WithTag(ms.name, opt.tag)
|
ref, err = reference.WithTag(ms.name, opt.Tag)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -465,21 +465,6 @@ func (ms *manifests) Get(ctx context.Context, dgst digest.Digest, options ...dis
|
|||||||
return nil, HandleErrorResponse(resp)
|
return nil, HandleErrorResponse(resp)
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithTag allows a tag to be passed into Put which enables the client
|
|
||||||
// to build a correct URL.
|
|
||||||
func WithTag(tag string) distribution.ManifestServiceOption {
|
|
||||||
return withTagOption{tag}
|
|
||||||
}
|
|
||||||
|
|
||||||
type withTagOption struct{ tag string }
|
|
||||||
|
|
||||||
func (o withTagOption) Apply(m distribution.ManifestService) error {
|
|
||||||
if _, ok := m.(*manifests); ok {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return fmt.Errorf("withTagOption is a client-only option")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Put puts a manifest. A tag can be specified using an options parameter which uses some shared state to hold the
|
// Put puts a manifest. A tag can be specified using an options parameter which uses some shared state to hold the
|
||||||
// tag name in order to build the correct upload URL.
|
// tag name in order to build the correct upload URL.
|
||||||
func (ms *manifests) Put(ctx context.Context, m distribution.Manifest, options ...distribution.ManifestServiceOption) (digest.Digest, error) {
|
func (ms *manifests) Put(ctx context.Context, m distribution.Manifest, options ...distribution.ManifestServiceOption) (digest.Digest, error) {
|
||||||
@ -487,9 +472,9 @@ func (ms *manifests) Put(ctx context.Context, m distribution.Manifest, options .
|
|||||||
var tagged bool
|
var tagged bool
|
||||||
|
|
||||||
for _, option := range options {
|
for _, option := range options {
|
||||||
if opt, ok := option.(withTagOption); ok {
|
if opt, ok := option.(distribution.WithTagOption); ok {
|
||||||
var err error
|
var err error
|
||||||
ref, err = reference.WithTag(ref, opt.tag)
|
ref, err = reference.WithTag(ref, opt.Tag)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
@ -710,7 +710,7 @@ func TestV1ManifestFetch(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
manifest, err = ms.Get(ctx, dgst, WithTag("latest"))
|
manifest, err = ms.Get(ctx, dgst, distribution.WithTag("latest"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -723,7 +723,7 @@ func TestV1ManifestFetch(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
manifest, err = ms.Get(ctx, dgst, WithTag("badcontenttype"))
|
manifest, err = ms.Get(ctx, dgst, distribution.WithTag("badcontenttype"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -761,7 +761,7 @@ func TestManifestFetchWithEtag(t *testing.T) {
|
|||||||
if !ok {
|
if !ok {
|
||||||
panic("wrong type for client manifest service")
|
panic("wrong type for client manifest service")
|
||||||
}
|
}
|
||||||
_, err = clientManifestService.Get(ctx, d1, WithTag("latest"), AddEtagToTag("latest", d1.String()))
|
_, err = clientManifestService.Get(ctx, d1, distribution.WithTag("latest"), AddEtagToTag("latest", d1.String()))
|
||||||
if err != distribution.ErrManifestNotModified {
|
if err != distribution.ErrManifestNotModified {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -861,7 +861,7 @@ func TestManifestPut(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := ms.Put(ctx, m1, WithTag(m1.Tag)); err != nil {
|
if _, err := ms.Put(ctx, m1, distribution.WithTag(m1.Tag)); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,7 +86,11 @@ func (imh *imageManifestHandler) GetImageManifest(w http.ResponseWriter, r *http
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
manifest, err = manifests.Get(imh, imh.Digest)
|
var options []distribution.ManifestServiceOption
|
||||||
|
if imh.Tag != "" {
|
||||||
|
options = append(options, distribution.WithTag(imh.Tag))
|
||||||
|
}
|
||||||
|
manifest, err = manifests.Get(imh, imh.Digest, options...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
imh.Errors = append(imh.Errors, v2.ErrorCodeManifestUnknown.WithDetail(err))
|
imh.Errors = append(imh.Errors, v2.ErrorCodeManifestUnknown.WithDetail(err))
|
||||||
return
|
return
|
||||||
@ -245,7 +249,11 @@ func (imh *imageManifestHandler) PutImageManifest(w http.ResponseWriter, r *http
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = manifests.Put(imh, manifest)
|
var options []distribution.ManifestServiceOption
|
||||||
|
if imh.Tag != "" {
|
||||||
|
options = append(options, distribution.WithTag(imh.Tag))
|
||||||
|
}
|
||||||
|
_, err = manifests.Put(imh, manifest, options...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// TODO(stevvooe): These error handling switches really need to be
|
// TODO(stevvooe): These error handling switches really need to be
|
||||||
// handled by an app global mapper.
|
// handled by an app global mapper.
|
||||||
|
Loading…
Reference in New Issue
Block a user