Skip to content

Commit 0b674dc

Browse files
Merge pull request operator-framework#3 from kevinrizza/use-multiple-layers
read all bundle image layers
2 parents a04dc1b + 2f290f8 commit 0b674dc

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

pkg/containertools/bundlereader.go

+19-19
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ func (b *BundleReader) GetBundle(image, outputDir string) error {
4747
}
4848
defer os.RemoveAll(workingDir)
4949

50-
//TODO: Use filepath package here
5150
rootTarfile := filepath.Join(workingDir, "bundle.tar")
5251

5352
err = r.Save(image, rootTarfile)
@@ -62,34 +61,35 @@ func (b *BundleReader) GetBundle(image, outputDir string) error {
6261
defer f.Close()
6362

6463
// Read the manifest.json file to find the right embedded tarball
65-
layerTarball, err := getManifestLayer(tar.NewReader(f))
64+
layerTarballs, err := getManifestLayers(tar.NewReader(f))
6665
if err != nil {
6766
return err
6867
}
68+
// Untar theimage layer tarballs and push the bundle manifests to the output directory
69+
for _, tarball := range layerTarballs {
70+
f, err = os.Open(rootTarfile)
71+
if err != nil {
72+
return err
73+
}
74+
defer f.Close()
6975

70-
f, err = os.Open(rootTarfile)
71-
if err != nil {
72-
return err
73-
}
74-
defer f.Close()
75-
76-
// Untar the top image layer tarball and push the bundle manifests to the output directory
77-
err = extractBundleManifests(layerTarball, outputDir, tar.NewReader(f))
78-
if err != nil {
79-
return err
76+
err = extractBundleManifests(tarball, outputDir, tar.NewReader(f))
77+
if err != nil {
78+
return err
79+
}
8080
}
8181

8282
return nil
8383
}
8484

85-
func getManifestLayer(tarReader *tar.Reader) (string, error) {
85+
func getManifestLayers(tarReader *tar.Reader) ([]string, error) {
8686
for {
8787
header, err := tarReader.Next()
8888
if err != nil {
8989
if err == io.EOF {
90-
return "", fmt.Errorf("invalid bundle image: unable to find manifest.json")
90+
return nil, fmt.Errorf("invalid bundle image: unable to find manifest.json")
9191
}
92-
return "", err
92+
return nil, err
9393
}
9494

9595
if header.Name == imageManifestName {
@@ -100,20 +100,20 @@ func getManifestLayer(tarReader *tar.Reader) (string, error) {
100100
manifests := make([]imageManifest, 0)
101101
err := json.Unmarshal(b, &manifests)
102102
if err != nil {
103-
return "", err
103+
return nil, err
104104
}
105105

106106
if len(manifests) == 0 {
107-
return "", fmt.Errorf("invalid bundle image: manifest.json missing manifest data")
107+
return nil, fmt.Errorf("invalid bundle image: manifest.json missing manifest data")
108108
}
109109

110110
topManifest := manifests[0]
111111

112112
if len(topManifest.Layers) == 0 {
113-
return "", fmt.Errorf("invalid bundle image: manifest has no layers")
113+
return nil, fmt.Errorf("invalid bundle image: manifest has no layers")
114114
}
115115

116-
return topManifest.Layers[0], nil
116+
return topManifest.Layers, nil
117117
}
118118
}
119119
}

0 commit comments

Comments
 (0)