Skip to content

Commit b4a2bcd

Browse files
committed
Pass Runtime.systemContext whenever possible
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
1 parent 134d1b4 commit b4a2bcd

3 files changed

Lines changed: 12 additions & 8 deletions

File tree

common/libimage/image.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ func (i *Image) isCorrupted(ctx context.Context, name string) error {
9797
return err
9898
}
9999

100-
img, err := ref.NewImage(ctx, nil)
100+
img, err := ref.NewImage(ctx, &i.runtime.systemContext)
101101
if err != nil {
102102
if name == "" {
103103
name = i.ID()[:12]

common/libimage/manifest_list.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,9 @@ func (i *Image) ConvertToManifestList(ctx context.Context) (*ManifestList, error
235235
// Copy from the OCI layout into the same image record, so that it gets
236236
// both its own manifest and the image index.
237237
copyOptions := imageCopy.Options{
238+
SourceCtx: &i.runtime.systemContext,
239+
DestinationCtx: &i.runtime.systemContext,
240+
238241
ForceManifestMIMEType: imageManifestType,
239242
}
240243
if _, err := imageCopy.Image(ctx, policyContext, i.storageReference, bundle, &copyOptions); err != nil {
@@ -561,6 +564,9 @@ func (m *ManifestList) AddArtifact(ctx context.Context, options *ManifestListAdd
561564
if options == nil {
562565
options = &ManifestListAddArtifactOptions{}
563566
}
567+
568+
systemContext := m.image.runtime.systemContextCopy()
569+
564570
opts := manifests.AddArtifactOptions{
565571
ManifestArtifactType: options.Type,
566572
Annotations: maps.Clone(options.Annotations),
@@ -592,7 +598,7 @@ func (m *ManifestList) AddArtifact(ctx context.Context, options *ManifestListAdd
592598
opts.LayerMediaType = &options.LayerType
593599
}
594600
if options.Subject != "" {
595-
ref, err := m.parseNameToExtantReference(ctx, nil, options.Subject, true, "subject for artifact manifest")
601+
ref, err := m.parseNameToExtantReference(ctx, systemContext, options.Subject, true, "subject for artifact manifest")
596602
if err != nil {
597603
return "", err
598604
}
@@ -607,8 +613,6 @@ func (m *ManifestList) AddArtifact(ctx context.Context, options *ManifestListAdd
607613
locker.Lock()
608614
defer locker.Unlock()
609615

610-
systemContext := m.image.runtime.systemContextCopy()
611-
612616
// Make sure to reload the image from the containers storage to fetch
613617
// the latest data (e.g., new or delete digests).
614618
if err := m.reload(); err != nil {
@@ -709,7 +713,7 @@ func (m *ManifestList) AnnotateInstance(d digest.Digest, options *ManifestListAn
709713
}
710714
}
711715
if options.Subject != "" {
712-
ref, err := m.parseNameToExtantReference(ctx, nil, options.Subject, true, "subject for image index")
716+
ref, err := m.parseNameToExtantReference(ctx, &m.image.runtime.systemContext, options.Subject, true, "subject for image index")
713717
if err != nil {
714718
return err
715719
}

common/libimage/pull.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ func (r *Runtime) copyFromDefault(ctx context.Context, ref types.ImageReference,
257257
if !ok || refName == "" {
258258
// Same trick as for the dir transport: we cannot use
259259
// the path to a directory as the name.
260-
storageName, err = getImageID(ctx, ref, nil)
260+
storageName, err = getImageID(ctx, ref, &r.systemContext)
261261
if err != nil {
262262
return nil, nil, err
263263
}
@@ -276,7 +276,7 @@ func (r *Runtime) copyFromDefault(ctx context.Context, ref types.ImageReference,
276276
switch len(storageName) {
277277
case 0:
278278
// If there's no reference name in the annotations, compute an ID.
279-
storageName, err = getImageID(ctx, ref, nil)
279+
storageName, err = getImageID(ctx, ref, &r.systemContext)
280280
if err != nil {
281281
return nil, nil, err
282282
}
@@ -302,7 +302,7 @@ func (r *Runtime) copyFromDefault(ctx context.Context, ref types.ImageReference,
302302
// Path-based transports (e.g., dir) may include invalid
303303
// characters, so we should pessimistically generate an ID
304304
// instead of looking at the StringWithinTransport().
305-
storageName, err = getImageID(ctx, ref, nil)
305+
storageName, err = getImageID(ctx, ref, &r.systemContext)
306306
if err != nil {
307307
return nil, nil, err
308308
}

0 commit comments

Comments
 (0)