@@ -3,8 +3,10 @@ package containerd
3
3
import (
4
4
"context"
5
5
"fmt"
6
+ "github.com/sirupsen/logrus"
6
7
"strings"
7
8
9
+ "github.com/containerd/containerd/v2/client"
8
10
"github.com/containerd/containerd/v2/core/images"
9
11
"github.com/containerd/errdefs"
10
12
"github.com/distribution/distribution/v3"
@@ -14,20 +16,21 @@ import (
14
16
15
17
// tagService implements distribution.TagService backed by containerd image store.
16
18
type tagService struct {
17
- client * Client
19
+ client * client. Client
18
20
repo reference.Named
19
21
}
20
22
21
23
// Get retrieves an image descriptor by its tag from the containerd image store.
24
+ // TODO:
22
25
func (t * tagService ) Get (ctx context.Context , tag string ) (distribution.Descriptor , error ) {
23
- // Construct the full reference
24
- ref := fmt .Sprintf ("%s:%s" , t .repo .String (), tag )
26
+ ref , err := reference .WithTag (t .repo , tag )
27
+ if err != nil {
28
+ return distribution.Descriptor {}, err
29
+ }
25
30
26
- // Get the image from containerd
27
- img , err := t .client .ImageStore ().Get (ctx , ref )
31
+ img , err := t .client .ImageService ().Get (ctx , ref .String ())
28
32
if err != nil {
29
- // Log for debugging
30
- fmt .Printf ("DEBUG: tagService.Get failed for ref %s: %v\n " , ref , err )
33
+ logrus .WithField ("image" , ref .String ()).WithError (err ).Debug ("Failed to get image from containerd image store." )
31
34
if errdefs .IsNotFound (err ) {
32
35
return distribution.Descriptor {}, distribution.ErrTagUnknown {Tag : tag }
33
36
@@ -43,9 +46,8 @@ func (t *tagService) Get(ctx context.Context, tag string) (distribution.Descript
43
46
}
44
47
45
48
// Tag associates a tag with a descriptor.
49
+ // TODO:
46
50
func (t * tagService ) Tag (ctx context.Context , tag string , desc distribution.Descriptor ) error {
47
- ctx = t .client .Context (ctx )
48
-
49
51
// Construct the full reference
50
52
ref := fmt .Sprintf ("%s:%s" , t .repo .String (), tag )
51
53
@@ -60,10 +62,10 @@ func (t *tagService) Tag(ctx context.Context, tag string, desc distribution.Desc
60
62
}
61
63
62
64
// Try to update first
63
- _ , err := t .client .ImageStore ().Update (ctx , img )
65
+ _ , err := t .client .ImageService ().Update (ctx , img )
64
66
if err != nil {
65
67
// If update fails, try to create
66
- _ , err = t .client .ImageStore ().Create (ctx , img )
68
+ _ , err = t .client .ImageService ().Create (ctx , img )
67
69
if err != nil {
68
70
return err
69
71
}
@@ -73,27 +75,26 @@ func (t *tagService) Tag(ctx context.Context, tag string, desc distribution.Desc
73
75
}
74
76
75
77
// Untag removes a tag.
78
+ // TODO:
76
79
func (t * tagService ) Untag (ctx context.Context , tag string ) error {
77
- ctx = t .client .Context (ctx )
78
-
79
80
// Construct the full reference
80
81
ref := fmt .Sprintf ("%s:%s" , t .repo .String (), tag )
81
82
82
83
// Delete the image reference
83
- err := t .client .ImageStore ().Delete (ctx , ref )
84
+ err := t .client .ImageService ().Delete (ctx , ref )
84
85
if err != nil {
85
- return convertError (err )
86
+ // TODO: convert error if possible
87
+ return err
86
88
}
87
89
88
90
return nil
89
91
}
90
92
91
93
// All returns all tags for the repository.
94
+ // TODO:
92
95
func (t * tagService ) All (ctx context.Context ) ([]string , error ) {
93
- ctx = t .client .Context (ctx )
94
-
95
96
// List all images
96
- images , err := t .client .ImageStore ().List (ctx )
97
+ images , err := t .client .ImageService ().List (ctx )
97
98
if err != nil {
98
99
return nil , err
99
100
}
@@ -114,11 +115,10 @@ func (t *tagService) All(ctx context.Context) ([]string, error) {
114
115
}
115
116
116
117
// Lookup finds tags associated with a descriptor.
118
+ // TODO
117
119
func (t * tagService ) Lookup (ctx context.Context , desc distribution.Descriptor ) ([]string , error ) {
118
- ctx = t .client .Context (ctx )
119
-
120
120
// List all images
121
- images , err := t .client .ImageStore ().List (ctx )
121
+ images , err := t .client .ImageService ().List (ctx )
122
122
if err != nil {
123
123
return nil , err
124
124
}
0 commit comments