Skip to content

Commit

Permalink
Merge pull request #400 from njhale/fix-unpack-4.5
Browse files Browse the repository at this point in the history
[release-4.5] Bug 1845588: fix(images): use docker/podman create and cp for exec unpacking
  • Loading branch information
openshift-merge-robot committed Sep 18, 2020
2 parents ff05bb7 + 1163573 commit 7416454
Show file tree
Hide file tree
Showing 17 changed files with 216 additions and 612 deletions.
51 changes: 27 additions & 24 deletions cmd/opm/alpha/bundle/build.go
Expand Up @@ -7,14 +7,14 @@ import (
)

var (
dirBuildArgs string
tagBuildArgs string
imageBuilderArgs string
packageNameArgs string
channelsArgs string
channelDefaultArgs string
outputDirArgs string
overwriteArgs bool
buildDir string
tag string
containerTool string
pkg string
channels string
defaultChannel string
outputDir string
overwrite bool
)

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

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

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

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

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

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

bundleBuildCmd.Flags().StringVarP(&channelDefaultArgs, "default", "e", "",
bundleBuildCmd.Flags().StringVarP(&defaultChannel, "default", "e", "",
"The default channel for the bundle image")

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

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

return bundleBuildCmd
}

func buildFunc(cmd *cobra.Command, args []string) error {
err := bundle.BuildFunc(dirBuildArgs, outputDirArgs, tagBuildArgs, imageBuilderArgs,
packageNameArgs, channelsArgs, channelDefaultArgs, overwriteArgs)
if err != nil {
return err
}

return nil
return bundle.BuildFunc(
buildDir,
outputDir,
tag,
containerTool,
pkg,
channels,
defaultChannel,
overwrite,
)
}
27 changes: 15 additions & 12 deletions cmd/opm/alpha/bundle/generate.go
@@ -1,9 +1,10 @@
package bundle

import (
"github.com/operator-framework/operator-registry/pkg/lib/bundle"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"

"github.com/operator-framework/operator-registry/pkg/lib/bundle"
)

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

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

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

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

bundleGenerateCmd.Flags().StringVarP(&channelDefaultArgs, "default", "e", "",
bundleGenerateCmd.Flags().StringVarP(&defaultChannel, "default", "e", "",
"The default channel for the bundle image")

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

return bundleGenerateCmd
}

func generateFunc(cmd *cobra.Command, args []string) error {
err := bundle.GenerateFunc(dirBuildArgs, outputDirArgs, packageNameArgs, channelsArgs, channelDefaultArgs, true)
if err != nil {
return err
}

return nil
return bundle.GenerateFunc(
buildDir,
outputDir,
pkg,
channels,
defaultChannel,
true,
)
}
33 changes: 27 additions & 6 deletions cmd/opm/alpha/bundle/validate.go
@@ -1,13 +1,18 @@
package bundle

import (
"fmt"
"io/ioutil"
"os"
"path/filepath"

"github.com/operator-framework/operator-registry/pkg/lib/bundle"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"

"github.com/operator-framework/operator-registry/pkg/containertools"
"github.com/operator-framework/operator-registry/pkg/image"
"github.com/operator-framework/operator-registry/pkg/image/execregistry"
"github.com/operator-framework/operator-registry/pkg/lib/bundle"
)

func newBundleValidateCmd() *cobra.Command {
Expand All @@ -21,22 +26,38 @@ accurate.`,
RunE: validateFunc,
}

bundleValidateCmd.Flags().StringVarP(&tagBuildArgs, "tag", "t", "",
bundleValidateCmd.Flags().StringVarP(&tag, "tag", "t", "",
"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)")
if err := bundleValidateCmd.MarkFlagRequired("tag"); err != nil {
log.Fatalf("Failed to mark `tag` flag for `validate` subcommand as required")
}

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

return bundleValidateCmd
}

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

imageValidator := bundle.NewImageValidator(imageBuilderArgs, logger)
var (
registry image.Registry
err error
)

tool := containertools.NewContainerTool(containerTool, containertools.PodmanTool)
switch tool {
case containertools.PodmanTool, containertools.DockerTool:
registry, err = execregistry.NewRegistry(tool, logger)
default:
err = fmt.Errorf("unrecognized container-tool option: %s", containerTool)
}

if err != nil {
return err
}
imageValidator := bundle.NewImageValidator(registry, logger)

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

err = imageValidator.PullBundleImage(tagBuildArgs, dir)
err = imageValidator.PullBundleImage(tag, dir)
if err != nil {
return err
}
Expand Down
Expand Up @@ -186,6 +186,15 @@ spec:
beta.kubernetes.io/os: linux
maturity: beta
version: 0.22.2
installModes:
- supported: true
type: OwnNamespace
- supported: true
type: SingleNamespace
- supported: true
type: MultiNamespace
- supported: false
type: AllNamespaces
customresourcedefinitions:
owned:
- name: prometheuses.monitoring.coreos.com
Expand Down
114 changes: 0 additions & 114 deletions pkg/containertools/containertoolsfakes/fake_image_reader.go

This file was deleted.

0 comments on commit 7416454

Please sign in to comment.