diff --git a/cmd/opm/index/add.go b/cmd/opm/index/add.go index f6c8caad99..3d0fdcccef 100644 --- a/cmd/opm/index/add.go +++ b/cmd/opm/index/add.go @@ -55,10 +55,12 @@ func addIndexAddCmd(parent *cobra.Command) { } indexCmd.Flags().Bool("skip-tls", false, "skip TLS certificate verification for container image registries while pulling bundles") indexCmd.Flags().StringP("binary-image", "i", "", "container image for on-image `opm` command") - indexCmd.Flags().StringP("container-tool", "c", "podman", "tool to interact with container images (save, build, etc.). One of: [docker, podman]") + indexCmd.Flags().StringP("build-tool", "c", "podman", "tool to build container images (build). One of: [docker, podman]") + indexCmd.Flags().StringP("pull-tool", "p", "none", "tool to pull container images (save, pull, etc.). One of: [none, docker, podman]") indexCmd.Flags().StringP("tag", "t", "", "custom tag for container image being built") indexCmd.Flags().Bool("permissive", false, "allow registry load errors") indexCmd.Flags().StringP("mode", "", "replaces", "graph update mode that defines how channel graphs are updated. One of: [replaces, semver, semver-skippatch]") + indexCmd.Flags().String("container-tool", "", "container-tool has been deprecated. Please select a build and pull tool separately.") if err := indexCmd.Flags().MarkHidden("debug"); err != nil { logrus.Panic(err.Error()) @@ -96,15 +98,29 @@ func runIndexAddCmdFunc(cmd *cobra.Command, args []string) error { return err } - containerTool, err := cmd.Flags().GetString("container-tool") + buildTool, err := cmd.Flags().GetString("build-tool") if err != nil { return err } - if containerTool == "none" { + if buildTool == "none" { return fmt.Errorf("none is not a valid container-tool for index add") } + pullTool, err := cmd.Flags().GetString("pull-tool") + if err != nil { + return err + } + + containerTool, err := cmd.Flags().GetString("container-tool") + if err != nil { + return err + } + + if containerTool != "" { + return fmt.Errorf("container-tool has been deprecated. Please select a build and push tool separately") + } + tag, err := cmd.Flags().GetString("tag") if err != nil { return err @@ -134,7 +150,10 @@ func runIndexAddCmdFunc(cmd *cobra.Command, args []string) error { logger.Info("building the index") - indexAdder := indexer.NewIndexAdder(containertools.NewContainerTool(containerTool, containertools.PodmanTool), logger) + indexAdder := indexer.NewIndexAdder( + containertools.NewContainerTool(buildTool, containertools.PodmanTool), + containertools.NewContainerTool(pullTool, containertools.NoneTool), + logger) request := indexer.AddToIndexRequest{ Generate: generate, diff --git a/pkg/lib/indexer/indexer.go b/pkg/lib/indexer/indexer.go index 8f4deb80b0..dcfae450e2 100644 --- a/pkg/lib/indexer/indexer.go +++ b/pkg/lib/indexer/indexer.go @@ -42,7 +42,8 @@ type ImageIndexer struct { RegistryAdder registry.RegistryAdder RegistryDeleter registry.RegistryDeleter RegistryPruner registry.RegistryPruner - ContainerTool containertools.ContainerTool + BuildTool containertools.ContainerTool + PullTool containertools.ContainerTool Logger *logrus.Entry } @@ -99,7 +100,7 @@ func (i ImageIndexer) AddToIndex(request AddToIndexRequest) error { Permissive: request.Permissive, Mode: request.Mode, SkipTLS: request.SkipTLS, - ContainerTool: i.ContainerTool, + ContainerTool: i.PullTool, } // Add the bundles to the registry @@ -292,13 +293,13 @@ func (i ImageIndexer) getDatabaseFile(workingDir, fromIndex string) (string, err var reg image.Registry var rerr error - switch i.ContainerTool { + switch i.PullTool { case containertools.NoneTool: reg, rerr = containerdregistry.NewRegistry(containerdregistry.WithLog(i.Logger)) case containertools.PodmanTool: fallthrough case containertools.DockerTool: - reg, rerr = execregistry.NewRegistry(i.ContainerTool, i.Logger) + reg, rerr = execregistry.NewRegistry(i.PullTool, i.Logger) } if rerr != nil { return "", rerr diff --git a/pkg/lib/indexer/interfaces.go b/pkg/lib/indexer/interfaces.go index 4918eec267..a9017ecc0d 100644 --- a/pkg/lib/indexer/interfaces.go +++ b/pkg/lib/indexer/interfaces.go @@ -15,14 +15,15 @@ type IndexAdder interface { } // NewIndexAdder is a constructor that returns an IndexAdder -func NewIndexAdder(containerTool containertools.ContainerTool, logger *logrus.Entry) IndexAdder { +func NewIndexAdder(buildTool, pullTool containertools.ContainerTool, logger *logrus.Entry) IndexAdder { return ImageIndexer{ DockerfileGenerator: containertools.NewDockerfileGenerator(logger), - CommandRunner: containertools.NewCommandRunner(containerTool, logger), - LabelReader: containertools.NewLabelReader(containerTool, logger), + CommandRunner: containertools.NewCommandRunner(buildTool, logger), + LabelReader: containertools.NewLabelReader(pullTool, logger), RegistryAdder: registry.NewRegistryAdder(logger), - ImageReader: containertools.NewImageReader(containerTool, logger), - ContainerTool: containerTool, + ImageReader: containertools.NewImageReader(pullTool, logger), + BuildTool: buildTool, + PullTool: pullTool, Logger: logger, } } @@ -42,7 +43,8 @@ func NewIndexDeleter(containerTool containertools.ContainerTool, logger *logrus. LabelReader: containertools.NewLabelReader(containerTool, logger), RegistryDeleter: registry.NewRegistryDeleter(logger), ImageReader: containertools.NewImageReader(containerTool, logger), - ContainerTool: containerTool, + BuildTool: containerTool, + PullTool: containerTool, Logger: logger, } } @@ -59,7 +61,8 @@ func NewIndexExporter(containerTool containertools.ContainerTool, logger *logrus CommandRunner: containertools.NewCommandRunner(containerTool, logger), LabelReader: containertools.NewLabelReader(containerTool, logger), ImageReader: containertools.NewImageReader(containerTool, logger), - ContainerTool: containerTool, + BuildTool: containerTool, + PullTool: containerTool, Logger: logger, } } @@ -76,7 +79,8 @@ func NewIndexPruner(containerTool containertools.ContainerTool, logger *logrus.E LabelReader: containertools.NewLabelReader(containerTool, logger), RegistryPruner: registry.NewRegistryPruner(logger), ImageReader: containertools.NewImageReader(containerTool, logger), - ContainerTool: containerTool, + BuildTool: containerTool, + PullTool: containerTool, Logger: logger, } } diff --git a/test/e2e/opm_test.go b/test/e2e/opm_test.go index 7296609138..453c5dde88 100644 --- a/test/e2e/opm_test.go +++ b/test/e2e/opm_test.go @@ -89,7 +89,7 @@ func buildIndexWith(containerTool string) error { bundleImage + ":" + bundleTag2, } logger := logrus.WithFields(logrus.Fields{"bundles": bundles}) - indexAdder := indexer.NewIndexAdder(containertools.NewContainerTool(containerTool, containertools.NoneTool), logger) + indexAdder := indexer.NewIndexAdder(containertools.NewContainerTool(containerTool, containertools.NoneTool), containertools.NewContainerTool(containerTool, containertools.NoneTool), logger) request := indexer.AddToIndexRequest{ Generate: false, @@ -109,7 +109,7 @@ func buildFromIndexWith(containerTool string) error { bundleImage + ":" + bundleTag3, } logger := logrus.WithFields(logrus.Fields{"bundles": bundles}) - indexAdder := indexer.NewIndexAdder(containertools.NewContainerTool(containerTool, containertools.NoneTool), logger) + indexAdder := indexer.NewIndexAdder(containertools.NewContainerTool(containerTool, containertools.NoneTool), containertools.NewContainerTool(containerTool, containertools.NoneTool), logger) request := indexer.AddToIndexRequest{ Generate: false,