Skip to content

Commit 3e52e29

Browse files
committed
Fix bug in export named manifest option
When providing multiple names, the shared annotation map was causing the names to get overridden. Combined the WithManifest options which had compatible interfaces. Signed-off-by: Derek McGowan <[email protected]>
1 parent 053853f commit 3e52e29

1 file changed

Lines changed: 15 additions & 17 deletions

File tree

images/archive/exporter.go

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -89,31 +89,29 @@ func WithImage(is images.Store, name string) ExportOpt {
8989
}
9090

9191
// WithManifest adds a manifest to the exported archive.
92-
// It is up to caller to put name annotation to on the manifest
93-
// descriptor if needed.
94-
func WithManifest(manifest ocispec.Descriptor) ExportOpt {
92+
// When names are given they will be set on the manifest in the
93+
// exported archive, creating an index record for each name.
94+
// When no names are provided, it is up to caller to put name annotation to
95+
// on the manifest descriptor if needed.
96+
func WithManifest(manifest ocispec.Descriptor, names ...string) ExportOpt {
9597
return func(ctx context.Context, o *exportOptions) error {
96-
o.manifests = append(o.manifests, manifest)
97-
return nil
98-
}
99-
}
100-
101-
// WithNamedManifest adds a manifest to the exported archive
102-
// with the provided names.
103-
func WithNamedManifest(manifest ocispec.Descriptor, names ...string) ExportOpt {
104-
return func(ctx context.Context, o *exportOptions) error {
105-
for _, name := range names {
106-
manifest.Annotations = addNameAnnotation(name, manifest.Annotations)
98+
if len(names) == 0 {
10799
o.manifests = append(o.manifests, manifest)
108100
}
101+
for _, name := range names {
102+
mc := manifest
103+
mc.Annotations = addNameAnnotation(name, manifest.Annotations)
104+
o.manifests = append(o.manifests, mc)
105+
}
109106

110107
return nil
111108
}
112109
}
113110

114-
func addNameAnnotation(name string, annotations map[string]string) map[string]string {
115-
if annotations == nil {
116-
annotations = map[string]string{}
111+
func addNameAnnotation(name string, base map[string]string) map[string]string {
112+
annotations := map[string]string{}
113+
for k, v := range base {
114+
annotations[k] = v
117115
}
118116

119117
annotations[images.AnnotationImageName] = name

0 commit comments

Comments
 (0)