@@ -19,19 +19,20 @@ package manifest
19
19
import (
20
20
"context"
21
21
"encoding/json"
22
- "errors"
23
22
"fmt"
24
23
"regexp"
25
24
"strings"
26
25
26
+ ocispec "github.com/opencontainers/image-spec/specs-go/v1"
27
+
27
28
containerd "github.com/containerd/containerd/v2/client"
28
29
"github.com/containerd/containerd/v2/core/images"
30
+
29
31
"github.com/containerd/nerdctl/v2/pkg/api/types"
30
32
"github.com/containerd/nerdctl/v2/pkg/containerdutil"
31
33
"github.com/containerd/nerdctl/v2/pkg/inspecttypes/native"
32
34
"github.com/containerd/nerdctl/v2/pkg/manifestinspector"
33
35
"github.com/containerd/nerdctl/v2/pkg/referenceutil"
34
- ocispec "github.com/opencontainers/image-spec/specs-go/v1"
35
36
)
36
37
37
38
func Inspect (ctx context.Context , client * containerd.Client , rawRef string , options types.ManifestInspectOptions ) ([]any , error ) {
@@ -88,32 +89,24 @@ func inspectIdentifier(ctx context.Context, client *containerd.Client, identifie
88
89
}
89
90
90
91
func getManifest (ctx context.Context , client * containerd.Client , rawRef string , options types.ManifestInspectOptions ) ([]any , error ) {
91
- var errs []error
92
92
var entries []interface {}
93
93
94
94
candidateImageList , _ , _ , err := inspectIdentifier (ctx , client , rawRef )
95
95
if err != nil {
96
- errs = append (errs , fmt .Errorf ("%w: %s" , err , rawRef ))
97
96
return nil , err
98
97
}
99
98
for _ , candidateImage := range candidateImageList {
100
99
entry , err := manifestinspector .Inspect (ctx , client , candidateImage )
101
100
if err != nil {
102
- errs = append (errs , fmt .Errorf ("%w: %s" , err , candidateImage .Name ))
103
101
continue
104
102
}
105
103
// Process entry based on rawRef and verbose options
106
104
processedEntry := processManifestEntry (entry , rawRef , options .Verbose )
107
105
entries = append (entries , processedEntry )
108
106
}
109
- if len (errs ) > 0 {
110
- return []any {}, fmt .Errorf ("%d errors:\n %w" , len (errs ), errors .Join (errs ... ))
111
- }
112
-
113
107
if len (entries ) == 0 {
114
108
return []any {}, fmt .Errorf ("no manifest found for %s" , rawRef )
115
109
}
116
-
117
110
return entries , nil
118
111
}
119
112
@@ -143,52 +136,41 @@ func processManifestEntry(entry *native.Manifest, rawRef string, verbose bool) *
143
136
// index is empty, only output Manifest field from Manifests
144
137
if len (entry .Manifests ) == 1 {
145
138
// If there's only one manifest, output it directly without the Manifests wrapper
146
- result .Manifests = []native.ManifestEntry {
147
- {
148
- Manifest : entry .Manifests [0 ].Manifest ,
149
- },
150
- }
139
+ result .Manifests = []native.ManifestEntry {{Manifest : entry .Manifests [0 ].Manifest }}
151
140
} else {
152
141
for _ , manifestEntry := range entry .Manifests {
153
- result .Manifests = append (result .Manifests , native.ManifestEntry {
154
- Manifest : manifestEntry .Manifest ,
155
- })
142
+ result .Manifests = append (result .Manifests , native.ManifestEntry {Manifest : manifestEntry .Manifest })
156
143
}
157
144
}
158
145
}
159
146
return result
160
- } else {
161
- // If rawRef has digest, find matching content
162
-
163
- // Check if digest matches index digest
164
- if entry .IndexDesc != nil && entry .IndexDesc .Digest .String () == digest {
147
+ }
148
+ // If rawRef has digest, find matching content
149
+ // Check if digest matches index digest
150
+ if entry .IndexDesc != nil && entry .IndexDesc .Digest .String () == digest {
151
+ if verbose {
152
+ // verbose is true, output complete entry but clear manifests field
153
+ result .Index = entry .Index
154
+ result .IndexDesc = entry .IndexDesc
155
+ return result
156
+ }
157
+ // verbose is false, only output Index if index is not empty
158
+ result .Index = entry .Index
159
+ return result
160
+ }
161
+ // Check if digest matches manifest digest
162
+ for _ , manifestEntry := range entry .Manifests {
163
+ if manifestEntry .ManifestDesc != nil && manifestEntry .ManifestDesc .Digest .String () == digest {
164
+ // Only keep matching manifestEntry
165
165
if verbose {
166
- // verbose is true, output complete entry but clear manifests field
167
- result .Index = entry .Index
168
- result .IndexDesc = entry .IndexDesc
166
+ result .Manifests = append (result .Manifests , manifestEntry )
169
167
} else {
170
- // verbose is false, only output Index if index is not empty
171
- result .Index = entry .Index
172
- }
173
- } else {
174
- // Check if digest matches manifest digest
175
- for _ , manifestEntry := range entry .Manifests {
176
- if manifestEntry .ManifestDesc != nil && manifestEntry .ManifestDesc .Digest .String () == digest {
177
- // Only keep matching manifestEntry
178
- if verbose {
179
- result .Manifests = append (result .Manifests , manifestEntry )
180
- } else {
181
- result .Manifests = append (result .Manifests , native.ManifestEntry {
182
- Manifest : manifestEntry .Manifest ,
183
- })
184
- }
185
- break
186
- }
168
+ result .Manifests = append (result .Manifests , native.ManifestEntry {Manifest : manifestEntry .Manifest })
187
169
}
170
+ break
188
171
}
189
- return result
190
172
}
191
-
173
+ return result
192
174
}
193
175
194
176
func findImageByManifestDigest (
0 commit comments