Skip to content

Commit b8292cc

Browse files
authoredJun 9, 2020
Merge pull request operator-framework#351 from njhale/fix-unpack
fix(images): use docker/podman create and cp for exec unpacking
2 parents f17ca15 + 8515e8c commit b8292cc

File tree

16 files changed

+205
-610
lines changed

16 files changed

+205
-610
lines changed
 

‎cmd/opm/alpha/bundle/build.go

+27-24
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ import (
77
)
88

99
var (
10-
dirBuildArgs string
11-
tagBuildArgs string
12-
imageBuilderArgs string
13-
packageNameArgs string
14-
channelsArgs string
15-
channelDefaultArgs string
16-
outputDirArgs string
17-
overwriteArgs bool
10+
buildDir string
11+
tag string
12+
containerTool string
13+
pkg string
14+
channels string
15+
defaultChannel string
16+
outputDir string
17+
overwrite bool
1818
)
1919

2020
// newBundleBuildCmd returns a command that will build operator bundle image.
@@ -44,47 +44,50 @@ func newBundleBuildCmd() *cobra.Command {
4444
RunE: buildFunc,
4545
}
4646

47-
bundleBuildCmd.Flags().StringVarP(&dirBuildArgs, "directory", "d", "",
47+
bundleBuildCmd.Flags().StringVarP(&buildDir, "directory", "d", "",
4848
"The directory where bundle manifests and metadata for a specific version are located")
4949
if err := bundleBuildCmd.MarkFlagRequired("directory"); err != nil {
5050
log.Fatalf("Failed to mark `directory` flag for `build` subcommand as required")
5151
}
5252

53-
bundleBuildCmd.Flags().StringVarP(&tagBuildArgs, "tag", "t", "",
53+
bundleBuildCmd.Flags().StringVarP(&tag, "tag", "t", "",
5454
"The image tag applied to the bundle image")
5555
if err := bundleBuildCmd.MarkFlagRequired("tag"); err != nil {
5656
log.Fatalf("Failed to mark `tag` flag for `build` subcommand as required")
5757
}
5858

59-
bundleBuildCmd.Flags().StringVarP(&packageNameArgs, "package", "p", "",
59+
bundleBuildCmd.Flags().StringVarP(&pkg, "package", "p", "",
6060
"The name of the package that bundle image belongs to "+
6161
"(Required if `directory` is not pointing to a bundle in the nested bundle format)")
6262

63-
bundleBuildCmd.Flags().StringVarP(&channelsArgs, "channels", "c", "",
63+
bundleBuildCmd.Flags().StringVarP(&channels, "channels", "c", "",
6464
"The list of channels that bundle image belongs to"+
6565
"(Required if `directory` is not pointing to a bundle in the nested bundle format)")
6666

67-
bundleBuildCmd.Flags().StringVarP(&imageBuilderArgs, "image-builder", "b", "docker",
68-
"Tool to build container images. One of: [docker, podman, buildah]")
67+
bundleBuildCmd.Flags().StringVarP(&containerTool, "image-builder", "b", "docker",
68+
"Tool used to manage container images. One of: [docker, podman, buildah]")
6969

70-
bundleBuildCmd.Flags().StringVarP(&channelDefaultArgs, "default", "e", "",
70+
bundleBuildCmd.Flags().StringVarP(&defaultChannel, "default", "e", "",
7171
"The default channel for the bundle image")
7272

73-
bundleBuildCmd.Flags().BoolVarP(&overwriteArgs, "overwrite", "o", false,
73+
bundleBuildCmd.Flags().BoolVarP(&overwrite, "overwrite", "o", false,
7474
"To overwrite annotations.yaml locally if existed. By default, overwrite is set to `false`.")
7575

76-
bundleBuildCmd.Flags().StringVarP(&outputDirArgs, "output-dir", "u", "",
76+
bundleBuildCmd.Flags().StringVarP(&outputDir, "output-dir", "u", "",
7777
"Optional output directory for operator manifests")
7878

7979
return bundleBuildCmd
8080
}
8181

8282
func buildFunc(cmd *cobra.Command, args []string) error {
83-
err := bundle.BuildFunc(dirBuildArgs, outputDirArgs, tagBuildArgs, imageBuilderArgs,
84-
packageNameArgs, channelsArgs, channelDefaultArgs, overwriteArgs)
85-
if err != nil {
86-
return err
87-
}
88-
89-
return nil
83+
return bundle.BuildFunc(
84+
buildDir,
85+
outputDir,
86+
tag,
87+
containerTool,
88+
pkg,
89+
channels,
90+
defaultChannel,
91+
overwrite,
92+
)
9093
}

‎cmd/opm/alpha/bundle/generate.go

+15-12
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
package bundle
22

33
import (
4-
"github.com/operator-framework/operator-registry/pkg/lib/bundle"
54
log "github.com/sirupsen/logrus"
65
"github.com/spf13/cobra"
6+
7+
"github.com/operator-framework/operator-registry/pkg/lib/bundle"
78
)
89

910
// newBundleGenerateCmd returns a command that will generate operator bundle
@@ -24,34 +25,36 @@ func newBundleGenerateCmd() *cobra.Command {
2425
RunE: generateFunc,
2526
}
2627

27-
bundleGenerateCmd.Flags().StringVarP(&dirBuildArgs, "directory", "d", "",
28+
bundleGenerateCmd.Flags().StringVarP(&buildDir, "directory", "d", "",
2829
"The directory where bundle manifests for a specific version are located.")
2930
if err := bundleGenerateCmd.MarkFlagRequired("directory"); err != nil {
3031
log.Fatalf("Failed to mark `directory` flag for `generate` subcommand as required")
3132
}
3233

33-
bundleGenerateCmd.Flags().StringVarP(&packageNameArgs, "package", "p", "",
34+
bundleGenerateCmd.Flags().StringVarP(&pkg, "package", "p", "",
3435
"The name of the package that bundle image belongs to "+
3536
"(Required if `directory` is not pointing to a bundle in the nested bundle format)")
3637

37-
bundleGenerateCmd.Flags().StringVarP(&channelsArgs, "channels", "c", "",
38+
bundleGenerateCmd.Flags().StringVarP(&channels, "channels", "c", "",
3839
"The list of channels that bundle image belongs to"+
3940
"(Required if `directory` is not pointing to a bundle in the nested bundle format)")
4041

41-
bundleGenerateCmd.Flags().StringVarP(&channelDefaultArgs, "default", "e", "",
42+
bundleGenerateCmd.Flags().StringVarP(&defaultChannel, "default", "e", "",
4243
"The default channel for the bundle image")
4344

44-
bundleGenerateCmd.Flags().StringVarP(&outputDirArgs, "output-dir", "u", "",
45+
bundleGenerateCmd.Flags().StringVarP(&outputDir, "output-dir", "u", "",
4546
"Optional output directory for operator manifests")
4647

4748
return bundleGenerateCmd
4849
}
4950

5051
func generateFunc(cmd *cobra.Command, args []string) error {
51-
err := bundle.GenerateFunc(dirBuildArgs, outputDirArgs, packageNameArgs, channelsArgs, channelDefaultArgs, true)
52-
if err != nil {
53-
return err
54-
}
55-
56-
return nil
52+
return bundle.GenerateFunc(
53+
buildDir,
54+
outputDir,
55+
pkg,
56+
channels,
57+
defaultChannel,
58+
true,
59+
)
5760
}

‎cmd/opm/alpha/bundle/validate.go

+30-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
package bundle
22

33
import (
4+
"fmt"
45
"io/ioutil"
56
"os"
67
"path/filepath"
78

8-
"github.com/operator-framework/operator-registry/pkg/lib/bundle"
99
log "github.com/sirupsen/logrus"
1010
"github.com/spf13/cobra"
11+
12+
"github.com/operator-framework/operator-registry/pkg/containertools"
13+
"github.com/operator-framework/operator-registry/pkg/image"
14+
"github.com/operator-framework/operator-registry/pkg/image/containerdregistry"
15+
"github.com/operator-framework/operator-registry/pkg/image/execregistry"
16+
"github.com/operator-framework/operator-registry/pkg/lib/bundle"
1117
)
1218

1319
func newBundleValidateCmd() *cobra.Command {
@@ -21,22 +27,40 @@ accurate.`,
2127
RunE: validateFunc,
2228
}
2329

24-
bundleValidateCmd.Flags().StringVarP(&tagBuildArgs, "tag", "t", "",
30+
bundleValidateCmd.Flags().StringVarP(&tag, "tag", "t", "",
2531
"The path of a registry to pull from, image name and its tag that present the bundle image (e.g. quay.io/test/test-operator:latest)")
2632
if err := bundleValidateCmd.MarkFlagRequired("tag"); err != nil {
2733
log.Fatalf("Failed to mark `tag` flag for `validate` subcommand as required")
2834
}
2935

30-
bundleValidateCmd.Flags().StringVarP(&imageBuilderArgs, "image-builder", "b", "docker", "Tool to build container images. One of: [docker, podman]")
36+
bundleValidateCmd.Flags().StringVarP(&containerTool, "image-builder", "b", "docker", "Tool used to pull and unpack bundle images. One of: [none, docker, podman]")
3137

3238
return bundleValidateCmd
3339
}
3440

3541
func validateFunc(cmd *cobra.Command, args []string) error {
36-
logger := log.WithFields(log.Fields{"container-tool": imageBuilderArgs})
42+
logger := log.WithFields(log.Fields{"container-tool": containerTool})
3743
log.SetLevel(log.DebugLevel)
3844

39-
imageValidator := bundle.NewImageValidator(imageBuilderArgs, logger)
45+
var (
46+
registry image.Registry
47+
err error
48+
)
49+
50+
tool := containertools.NewContainerTool(containerTool, containertools.NoneTool)
51+
switch tool {
52+
case containertools.PodmanTool, containertools.DockerTool:
53+
registry, err = execregistry.NewRegistry(tool, logger)
54+
case containertools.NoneTool:
55+
registry, err = containerdregistry.NewRegistry(containerdregistry.WithLog(logger))
56+
default:
57+
err = fmt.Errorf("unrecognized container-tool option: %s", containerTool)
58+
}
59+
60+
if err != nil {
61+
return err
62+
}
63+
imageValidator := bundle.NewImageValidator(registry, logger)
4064

4165
dir, err := ioutil.TempDir("", "bundle-")
4266
logger.Infof("Create a temp directory at %s", dir)
@@ -50,7 +74,7 @@ func validateFunc(cmd *cobra.Command, args []string) error {
5074
}
5175
}()
5276

53-
err = imageValidator.PullBundleImage(tagBuildArgs, dir)
77+
err = imageValidator.PullBundleImage(tag, dir)
5478
if err != nil {
5579
return err
5680
}

‎manifests/prometheus/0.22.2/prometheusoperator.0.22.2.clusterserviceversion.yaml

+9
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,15 @@ spec:
186186
beta.kubernetes.io/os: linux
187187
maturity: beta
188188
version: 0.22.2
189+
installModes:
190+
- supported: true
191+
type: OwnNamespace
192+
- supported: true
193+
type: SingleNamespace
194+
- supported: true
195+
type: MultiNamespace
196+
- supported: false
197+
type: AllNamespaces
189198
customresourcedefinitions:
190199
owned:
191200
- name: prometheuses.monitoring.coreos.com

‎pkg/containertools/containertoolsfakes/fake_image_reader.go

-114
This file was deleted.

‎pkg/containertools/imagereader.go

-201
This file was deleted.

‎pkg/containertools/imagereader_test.go

-145
This file was deleted.

‎pkg/containertools/runner.go

+34-10
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package containertools
44
import (
55
"fmt"
66
"os/exec"
7+
"strings"
78

89
"github.com/sirupsen/logrus"
910
)
@@ -13,7 +14,6 @@ type CommandRunner interface {
1314
GetToolName() string
1415
Pull(image string) error
1516
Build(dockerfile, tag string) error
16-
Save(image, tarFile string) error
1717
Inspect(image string) ([]byte, error)
1818
}
1919

@@ -26,12 +26,12 @@ type ContainerCommandRunner struct {
2626

2727
// NewCommandRunner takes the containerTool as an input string and returns a
2828
// CommandRunner to run commands with that cli tool
29-
func NewCommandRunner(containerTool ContainerTool, logger *logrus.Entry) CommandRunner {
30-
r := ContainerCommandRunner{
29+
func NewCommandRunner(containerTool ContainerTool, logger *logrus.Entry) *ContainerCommandRunner {
30+
r := &ContainerCommandRunner{
3131
logger: logger,
3232
containerTool: containerTool,
3333
}
34-
return &r
34+
return r
3535
}
3636

3737
// GetToolName returns the container tool this command runner is using
@@ -82,20 +82,44 @@ func (r *ContainerCommandRunner) Build(dockerfile, tag string) error {
8282
return nil
8383
}
8484

85-
// Save takes a local container image and runs the save commmand to convert the
86-
// image into a specified tarball and push it to the local directory
87-
func (r *ContainerCommandRunner) Save(image, tarFile string) error {
88-
args := []string{"save", image, "-o", tarFile}
85+
// Unpack copies a directory from a local container image to a directory in the local filesystem.
86+
func (r *ContainerCommandRunner) Unpack(image, src, dst string) error {
87+
args := []string{"create", image, ""}
8988

9089
command := exec.Command(r.containerTool.String(), args...)
9190

92-
r.logger.Infof("running %s save", r.containerTool)
91+
r.logger.Infof("running %s create", r.containerTool)
9392
r.logger.Debugf("%s", command.Args)
9493

9594
out, err := command.CombinedOutput()
9695
if err != nil {
9796
r.logger.Errorf(string(out))
98-
return fmt.Errorf("error saving image: %s. %v", string(out), err)
97+
return fmt.Errorf("error creating container %s: %v", string(out), err)
98+
}
99+
100+
id := strings.TrimSuffix(string(out), "\n")
101+
args = []string{"cp", id + ":" + src, dst}
102+
command = exec.Command(r.containerTool.String(), args...)
103+
104+
r.logger.Infof("running %s cp", r.containerTool)
105+
r.logger.Debugf("%s", command.Args)
106+
107+
out, err = command.CombinedOutput()
108+
if err != nil {
109+
r.logger.Errorf(string(out))
110+
return fmt.Errorf("error copying container directory %s: %v", string(out), err)
111+
}
112+
113+
args = []string{"rm", id}
114+
command = exec.Command(r.containerTool.String(), args...)
115+
116+
r.logger.Infof("running %s rm", r.containerTool)
117+
r.logger.Debugf("%s", command.Args)
118+
119+
out, err = command.CombinedOutput()
120+
if err != nil {
121+
r.logger.Errorf(string(out))
122+
return fmt.Errorf("error removing container %s: %v", string(out), err)
99123
}
100124

101125
return nil

‎pkg/image/execregistry/registry.go

+15-9
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,30 @@ package execregistry
22

33
import (
44
"context"
5-
"github.com/operator-framework/operator-registry/pkg/containertools"
5+
66
"github.com/sirupsen/logrus"
77

8+
"github.com/operator-framework/operator-registry/pkg/containertools"
89
"github.com/operator-framework/operator-registry/pkg/image"
910
)
1011

12+
// CommandRunner provides some basic methods for manipulating images via an external container tool.
13+
type CommandRunner interface {
14+
containertools.CommandRunner
15+
16+
Unpack(image, src, dst string) error
17+
}
18+
1119
// Registry enables manipulation of images via exec podman/docker commands.
1220
type Registry struct {
13-
log *logrus.Entry
14-
cmd containertools.CommandRunner
21+
log *logrus.Entry
22+
cmd CommandRunner
1523
}
1624

1725
// Adapt the cmd interface to the registry interface
1826
var _ image.Registry = &Registry{}
1927

28+
// NewRegistry instantiates and returns a new registry which manipulates images via exec podman/docker commands.
2029
func NewRegistry(tool containertools.ContainerTool, logger *logrus.Entry) (registry *Registry, err error) {
2130
return &Registry{
2231
log: logger,
@@ -32,21 +41,18 @@ func (r *Registry) Pull(ctx context.Context, ref image.Reference) error {
3241
// Unpack writes the unpackaged content of an image to a directory.
3342
// If the referenced image does not exist in the registry, an error is returned.
3443
func (r *Registry) Unpack(ctx context.Context, ref image.Reference, dir string) error {
35-
return containertools.ImageLayerReader{
36-
Cmd: r.cmd,
37-
Logger: r.log,
38-
}.GetImageData(ref.String(), dir)
44+
return r.cmd.Unpack(ref.String(), "/", dir)
3945
}
4046

4147
// Labels gets the labels for an image reference.
4248
func (r *Registry) Labels(ctx context.Context, ref image.Reference) (map[string]string, error) {
4349
return containertools.ImageLabelReader{
44-
Cmd: r.cmd,
50+
Cmd: r.cmd,
4551
Logger: r.log,
4652
}.GetLabelsFromImage(ref.String())
4753
}
4854

4955
// Destroy is no-op for exec tools
5056
func (r *Registry) Destroy() error {
5157
return nil
52-
}
58+
}

‎pkg/image/registry_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import (
1818
libimage "github.com/operator-framework/operator-registry/pkg/lib/image"
1919
)
2020

21-
2221
// cleanupFunc is a function that cleans up after some test infra.
2322
type cleanupFunc func()
2423

‎pkg/lib/bundle/interfaces.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package bundle
22

33
import (
4-
"github.com/operator-framework/operator-registry/pkg/containertools"
5-
64
"github.com/sirupsen/logrus"
5+
6+
"github.com/operator-framework/operator-registry/pkg/image"
77
)
88

99
// BundleImageValidator provides a toolset for pulling and then validating
@@ -21,9 +21,9 @@ type BundleImageValidator interface {
2121
}
2222

2323
// NewImageValidator is a constructor that returns an ImageValidator
24-
func NewImageValidator(containerTool string, logger *logrus.Entry) BundleImageValidator {
24+
func NewImageValidator(registry image.Registry, logger *logrus.Entry) BundleImageValidator {
2525
return imageValidator{
26-
imageReader: containertools.NewImageReader(containertools.NewContainerTool(containerTool, containertools.NoneTool), logger),
27-
logger: logger,
26+
registry: registry,
27+
logger: logger,
2828
}
2929
}

‎pkg/lib/bundle/validate.go

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
package bundle
22

33
import (
4+
"context"
45
"encoding/json"
56
"fmt"
67
"io/ioutil"
78
"path/filepath"
89
"strings"
910

10-
v1 "github.com/operator-framework/api/pkg/operators/v1alpha1"
11-
v "github.com/operator-framework/api/pkg/validation"
12-
"github.com/operator-framework/operator-registry/pkg/containertools"
13-
validation "github.com/operator-framework/operator-registry/pkg/lib/validation"
14-
"github.com/operator-framework/operator-registry/pkg/registry"
15-
11+
y "github.com/ghodss/yaml"
12+
log "github.com/sirupsen/logrus"
1613
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
1714
apiextensionsv1beta1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
1815
apiValidation "k8s.io/apimachinery/pkg/api/validation"
@@ -22,8 +19,11 @@ import (
2219
"k8s.io/apimachinery/pkg/util/validation/field"
2320
k8syaml "k8s.io/apimachinery/pkg/util/yaml"
2421

25-
y "github.com/ghodss/yaml"
26-
log "github.com/sirupsen/logrus"
22+
v1 "github.com/operator-framework/api/pkg/operators/v1alpha1"
23+
v "github.com/operator-framework/api/pkg/validation"
24+
"github.com/operator-framework/operator-registry/pkg/image"
25+
validation "github.com/operator-framework/operator-registry/pkg/lib/validation"
26+
"github.com/operator-framework/operator-registry/pkg/registry"
2727
)
2828

2929
const (
@@ -38,8 +38,8 @@ type Meta struct {
3838

3939
// imageValidator is a struct implementation of the Indexer interface
4040
type imageValidator struct {
41-
imageReader containertools.ImageReader
42-
logger *log.Entry
41+
registry image.Registry
42+
logger *log.Entry
4343
}
4444

4545
// PullBundleImage shells out to a container tool and pulls a given image tag
@@ -48,7 +48,7 @@ type imageValidator struct {
4848
func (i imageValidator) PullBundleImage(imageTag, directory string) error {
4949
i.logger.Debug("Pulling and unpacking container image")
5050

51-
return i.imageReader.GetImageData(imageTag, directory)
51+
return i.registry.Unpack(context.Background(), image.SimpleReference(imageTag), directory)
5252
}
5353

5454
// ValidateBundle takes a directory containing the contents of a bundle and validates

‎pkg/lib/bundle/validate_test.go

-42
Original file line numberDiff line numberDiff line change
@@ -5,52 +5,10 @@ import (
55
"fmt"
66
"testing"
77

8-
"github.com/operator-framework/operator-registry/pkg/containertools/containertoolsfakes"
9-
108
"github.com/sirupsen/logrus"
11-
"github.com/stretchr/testify/assert"
129
"github.com/stretchr/testify/require"
1310
)
1411

15-
func TestPullBundle(t *testing.T) {
16-
tag := "quay.io/example/bundle:0.0.1"
17-
dir := "/tmp/dir"
18-
19-
logger := logrus.NewEntry(logrus.New())
20-
21-
mockImgReader := containertoolsfakes.FakeImageReader{}
22-
mockImgReader.GetImageDataReturns(nil)
23-
24-
validator := imageValidator{
25-
imageReader: &mockImgReader,
26-
logger: logger,
27-
}
28-
29-
err := validator.PullBundleImage(tag, dir)
30-
require.NoError(t, err)
31-
}
32-
33-
func TestPullBundle_Error(t *testing.T) {
34-
tag := "quay.io/example/bundle:0.0.1"
35-
dir := "/tmp/dir"
36-
37-
expectedErr := fmt.Errorf("Unable to unpack image")
38-
39-
logger := logrus.NewEntry(logrus.New())
40-
41-
mockImgReader := containertoolsfakes.FakeImageReader{}
42-
mockImgReader.GetImageDataReturns(expectedErr)
43-
44-
validator := imageValidator{
45-
imageReader: &mockImgReader,
46-
logger: logger,
47-
}
48-
49-
err := validator.PullBundleImage(tag, dir)
50-
require.Error(t, err)
51-
assert.Equal(t, expectedErr, err)
52-
}
53-
5412
func TestValidateBundleFormat(t *testing.T) {
5513
dir := "./testdata/validate/valid_bundle/"
5614

‎pkg/lib/indexer/indexer.go

+7-8
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,24 @@ import (
44
"context"
55
"database/sql"
66
"fmt"
7-
"github.com/operator-framework/operator-registry/pkg/image"
8-
"github.com/operator-framework/operator-registry/pkg/image/containerdregistry"
9-
"github.com/operator-framework/operator-registry/pkg/image/execregistry"
107
"io"
118
"io/ioutil"
129
"os"
1310
"path"
1411
"path/filepath"
1512

13+
"github.com/sirupsen/logrus"
14+
"gopkg.in/yaml.v2"
15+
utilerrors "k8s.io/apimachinery/pkg/util/errors"
16+
1617
"github.com/operator-framework/operator-registry/pkg/containertools"
18+
"github.com/operator-framework/operator-registry/pkg/image"
19+
"github.com/operator-framework/operator-registry/pkg/image/containerdregistry"
20+
"github.com/operator-framework/operator-registry/pkg/image/execregistry"
1721
"github.com/operator-framework/operator-registry/pkg/lib/bundle"
1822
"github.com/operator-framework/operator-registry/pkg/lib/registry"
1923
pregistry "github.com/operator-framework/operator-registry/pkg/registry"
2024
"github.com/operator-framework/operator-registry/pkg/sqlite"
21-
22-
"github.com/sirupsen/logrus"
23-
"gopkg.in/yaml.v2"
24-
utilerrors "k8s.io/apimachinery/pkg/util/errors"
2525
)
2626

2727
const (
@@ -38,7 +38,6 @@ type ImageIndexer struct {
3838
DockerfileGenerator containertools.DockerfileGenerator
3939
CommandRunner containertools.CommandRunner
4040
LabelReader containertools.LabelReader
41-
ImageReader containertools.ImageReader
4241
RegistryAdder registry.RegistryAdder
4342
RegistryDeleter registry.RegistryDeleter
4443
RegistryPruner registry.RegistryPruner

‎pkg/lib/indexer/interfaces.go

-4
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ func NewIndexAdder(buildTool, pullTool containertools.ContainerTool, logger *log
2121
CommandRunner: containertools.NewCommandRunner(buildTool, logger),
2222
LabelReader: containertools.NewLabelReader(pullTool, logger),
2323
RegistryAdder: registry.NewRegistryAdder(logger),
24-
ImageReader: containertools.NewImageReader(pullTool, logger),
2524
BuildTool: buildTool,
2625
PullTool: pullTool,
2726
Logger: logger,
@@ -42,7 +41,6 @@ func NewIndexDeleter(containerTool containertools.ContainerTool, logger *logrus.
4241
CommandRunner: containertools.NewCommandRunner(containerTool, logger),
4342
LabelReader: containertools.NewLabelReader(containerTool, logger),
4443
RegistryDeleter: registry.NewRegistryDeleter(logger),
45-
ImageReader: containertools.NewImageReader(containerTool, logger),
4644
BuildTool: containerTool,
4745
PullTool: containerTool,
4846
Logger: logger,
@@ -60,7 +58,6 @@ func NewIndexExporter(containerTool containertools.ContainerTool, logger *logrus
6058
DockerfileGenerator: containertools.NewDockerfileGenerator(logger),
6159
CommandRunner: containertools.NewCommandRunner(containerTool, logger),
6260
LabelReader: containertools.NewLabelReader(containerTool, logger),
63-
ImageReader: containertools.NewImageReader(containerTool, logger),
6461
BuildTool: containerTool,
6562
PullTool: containerTool,
6663
Logger: logger,
@@ -78,7 +75,6 @@ func NewIndexPruner(containerTool containertools.ContainerTool, logger *logrus.E
7875
CommandRunner: containertools.NewCommandRunner(containerTool, logger),
7976
LabelReader: containertools.NewLabelReader(containerTool, logger),
8077
RegistryPruner: registry.NewRegistryPruner(logger),
81-
ImageReader: containertools.NewImageReader(containerTool, logger),
8278
BuildTool: containerTool,
8379
PullTool: containerTool,
8480
Logger: logger,

‎test/e2e/opm_test.go

+52-18
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package e2e_test
33
import (
44
"context"
55
"database/sql"
6+
"fmt"
67
"io/ioutil"
78
"os"
89
"os/exec"
@@ -15,6 +16,9 @@ import (
1516
"k8s.io/apimachinery/pkg/util/rand"
1617

1718
"github.com/operator-framework/operator-registry/pkg/containertools"
19+
"github.com/operator-framework/operator-registry/pkg/image"
20+
"github.com/operator-framework/operator-registry/pkg/image/containerdregistry"
21+
"github.com/operator-framework/operator-registry/pkg/image/execregistry"
1822
"github.com/operator-framework/operator-registry/pkg/lib/bundle"
1923
"github.com/operator-framework/operator-registry/pkg/lib/indexer"
2024
"github.com/operator-framework/operator-registry/pkg/sqlite"
@@ -133,19 +137,6 @@ func pushWith(containerTool, image string) error {
133137
return dockerpush.Run()
134138
}
135139

136-
func pushBundles(containerTool string) error {
137-
err := pushWith(containerTool, bundleImage+":"+bundleTag1)
138-
if err != nil {
139-
return err
140-
}
141-
err = pushWith(containerTool, bundleImage+":"+bundleTag2)
142-
if err != nil {
143-
return err
144-
}
145-
err = pushWith(containerTool, bundleImage+":"+bundleTag3)
146-
return err
147-
}
148-
149140
func exportWith(containerTool string) error {
150141
logger := logrus.WithFields(logrus.Fields{"package": packageName})
151142
indexExporter := indexer.NewIndexExporter(containertools.NewContainerTool(containerTool, containertools.NoneTool), logger)
@@ -197,22 +188,65 @@ var _ = Describe("opm", func() {
197188
Expect(err).NotTo(HaveOccurred(), "Error logging into quay.io")
198189
})
199190

191+
It("builds and validates a bundle image", func() {
192+
By("building bundle")
193+
img := bundleImage + ":" + bundleTag3
194+
err := inTemporaryBuildContext(func() error {
195+
return bundle.BuildFunc(bundlePath3, "", img, containerTool, packageName, channels, defaultChannel, false)
196+
})
197+
Expect(err).NotTo(HaveOccurred())
198+
199+
By("pushing bundle")
200+
Expect(pushWith(containerTool, img)).To(Succeed())
201+
202+
By("pulling bundle")
203+
logger := logrus.WithFields(logrus.Fields{"image": img})
204+
tool := containertools.NewContainerTool(containerTool, containertools.NoneTool)
205+
var registry image.Registry
206+
switch tool {
207+
case containertools.PodmanTool, containertools.DockerTool:
208+
registry, err = execregistry.NewRegistry(tool, logger)
209+
case containertools.NoneTool:
210+
registry, err = containerdregistry.NewRegistry(containerdregistry.WithLog(logger))
211+
default:
212+
err = fmt.Errorf("unrecognized container-tool option: %s", containerTool)
213+
}
214+
Expect(err).NotTo(HaveOccurred())
215+
216+
unpackDir, err := ioutil.TempDir(".", bundleTag3)
217+
Expect(err).NotTo(HaveOccurred())
218+
validator := bundle.NewImageValidator(registry, logger)
219+
Expect(validator.PullBundleImage(img, unpackDir)).To(Succeed())
220+
221+
By("validating bundle format")
222+
Expect(validator.ValidateBundleFormat(unpackDir)).To(Succeed())
223+
224+
By("validating bundle content")
225+
manifestsDir := filepath.Join(unpackDir, bundle.ManifestsDir)
226+
Expect(validator.ValidateBundleContent(manifestsDir)).To(Succeed())
227+
Expect(os.RemoveAll(unpackDir)).To(Succeed())
228+
})
229+
200230
It("builds and manipulates bundle and index images", func() {
201231
By("building bundles")
202-
for tag, path := range map[string]string{
232+
tagPaths := map[string]string{
203233
bundleTag1: bundlePath1,
204234
bundleTag2: bundlePath2,
205235
bundleTag3: bundlePath3,
206-
} {
207-
err := inTemporaryBuildContext(func() error {
236+
}
237+
var err error
238+
for tag, path := range tagPaths {
239+
err = inTemporaryBuildContext(func() error {
208240
return bundle.BuildFunc(path, "", bundleImage+":"+tag, containerTool, packageName, channels, defaultChannel, false)
209241
})
210242
Expect(err).NotTo(HaveOccurred())
211243
}
212244

213245
By("pushing bundles")
214-
err := pushBundles(containerTool)
215-
Expect(err).NotTo(HaveOccurred())
246+
for tag, _ := range tagPaths {
247+
err = pushWith(containerTool, bundleImage+":"+tag)
248+
Expect(err).NotTo(HaveOccurred())
249+
}
216250

217251
By("building an index")
218252
err = buildIndexWith(containerTool, indexImage1, bundleImage, []string{bundleTag1, bundleTag2})

0 commit comments

Comments
 (0)
Please sign in to comment.