Browse code

Use diff ids from image configuration

The diff id resolution currently relies on a stored mapping for
archive digest to diff id. This mapping could be derived from
the image configuration if the image configuration is available.
On linux the image config is pulled in parallel and may not be
available. On windows, however, it is always pulled first and can
be used to supplement the stored mapping for images which may not
have this mapping from being side loaded. This becomes useful when
combined with side loaded foreign layers.

Signed-off-by: Derek McGowan <derek@mcgstyle.net>

Derek McGowan authored on 2017/05/06 02:56:40
Showing 1 changed files
... ...
@@ -131,6 +131,7 @@ func (p *v2Puller) pullV2Repository(ctx context.Context, ref reference.Named) (e
131 131
 
132 132
 type v2LayerDescriptor struct {
133 133
 	digest            digest.Digest
134
+	diffID            layer.DiffID
134 135
 	repoInfo          *registry.RepositoryInfo
135 136
 	repo              distribution.Repository
136 137
 	V2MetadataService metadata.V2MetadataService
... ...
@@ -148,6 +149,9 @@ func (ld *v2LayerDescriptor) ID() string {
148 148
 }
149 149
 
150 150
 func (ld *v2LayerDescriptor) DiffID() (layer.DiffID, error) {
151
+	if ld.diffID != "" {
152
+		return ld.diffID, nil
153
+	}
151 154
 	return ld.V2MetadataService.GetDiffID(ld.digest)
152 155
 }
153 156
 
... ...
@@ -575,6 +579,16 @@ func (p *v2Puller) pullSchema2(ctx context.Context, ref reference.Named, mfst *s
575 575
 		if configRootFS == nil {
576 576
 			return "", "", errRootFSInvalid
577 577
 		}
578
+
579
+		if len(descriptors) != len(configRootFS.DiffIDs) {
580
+			return "", "", errRootFSMismatch
581
+		}
582
+
583
+		// Populate diff ids in descriptors to avoid downloading foreign layers
584
+		// which have been side loaded
585
+		for i := range descriptors {
586
+			descriptors[i].(*v2LayerDescriptor).diffID = configRootFS.DiffIDs[i]
587
+		}
578 588
 	}
579 589
 
580 590
 	if p.config.DownloadManager != nil {