Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug 1841178: fix(images): use docker/podman create and cp for exec unpacking #351

Merged
merged 1 commit into from
Jun 9, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix(images): use docker/podman create and cp for exec unpacking
Use docker/podman create and cp commands to unpack bundle and index
images instead of a custom unpacking scheme. This fixes an issue where
whiteout files present in an image cause `opm alpha bundle validate` to
fail.
njhale committed Jun 9, 2020
commit 8515e8c4a25f1d1ebb11bd35c34f5ef10d2f311f
51 changes: 27 additions & 24 deletions cmd/opm/alpha/bundle/build.go
Original file line number Diff line number Diff line change
@@ -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.
@@ -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
Original file line number Diff line number Diff line change
@@ -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
@@ -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,
)
}
36 changes: 30 additions & 6 deletions cmd/opm/alpha/bundle/validate.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
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/containerdregistry"
"github.com/operator-framework/operator-registry/pkg/image/execregistry"
"github.com/operator-framework/operator-registry/pkg/lib/bundle"
)

func newBundleValidateCmd() *cobra.Command {
@@ -21,22 +27,40 @@ 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: [none, 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.NoneTool)
switch tool {
case containertools.PodmanTool, containertools.DockerTool:
registry, err = execregistry.NewRegistry(tool, logger)
case containertools.NoneTool:
registry, err = containerdregistry.NewRegistry(containerdregistry.WithLog(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)
@@ -50,7 +74,7 @@ func validateFunc(cmd *cobra.Command, args []string) error {
}
}()

err = imageValidator.PullBundleImage(tagBuildArgs, dir)
err = imageValidator.PullBundleImage(tag, dir)
if err != nil {
return err
}
Original file line number Diff line number Diff line change
@@ -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
114 changes: 0 additions & 114 deletions pkg/containertools/containertoolsfakes/fake_image_reader.go

This file was deleted.

Loading