Skip to content

Commit b8292cc

Browse files
authoredJun 9, 2020
Merge pull request #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.

0 commit comments

Comments
 (0)