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

Revert "[feature] Understanding packages from directory" #239

Merged
merged 1 commit into from
Mar 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
36 changes: 16 additions & 20 deletions cmd/opm/alpha/bundle/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,44 +44,40 @@ func newBundleBuildCmd() *cobra.Command {
RunE: buildFunc,
}

bundleBuildCmd.Flags().StringVarP(&dirBuildArgs, "directory", "d", "",
"The directory where bundle manifests and metadata for a specific version are located")
bundleBuildCmd.Flags().StringVarP(&dirBuildArgs, "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", "",
"The image tag applied to the bundle image")
bundleBuildCmd.Flags().StringVarP(&tagBuildArgs, "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", "",
"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(&packageNameArgs, "package", "p", "", "The name of the package that bundle image belongs to")
if err := bundleBuildCmd.MarkFlagRequired("package"); err != nil {
log.Fatalf("Failed to mark `package` flag for `build` subcommand as required")
}

bundleBuildCmd.Flags().StringVarP(&channelsArgs, "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(&channelsArgs, "channels", "c", "", "The list of channels that bundle image belongs to")
if err := bundleBuildCmd.MarkFlagRequired("channels"); err != nil {
log.Fatalf("Failed to mark `channels` flag for `build` subcommand as required")
}

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

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

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

bundleBuildCmd.Flags().StringVarP(&outputDirArgs, "output-dir", "u", "",
"Optional output directory for operator manifests")
bundleBuildCmd.Flags().StringVarP(&outputDirArgs, "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)
err := bundle.BuildFunc(dirBuildArgs, outputDirArgs, tagBuildArgs, imageBuilderArgs,
packageNameArgs, channelsArgs, channelDefaultArgs, overwriteArgs)
if err != nil {
return err
}
Expand Down
23 changes: 11 additions & 12 deletions cmd/opm/alpha/bundle/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,24 @@ func newBundleGenerateCmd() *cobra.Command {
RunE: generateFunc,
}

bundleGenerateCmd.Flags().StringVarP(&dirBuildArgs, "directory", "d", "",
"The directory where bundle manifests for a specific version are located.")
bundleGenerateCmd.Flags().StringVarP(&dirBuildArgs, "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", "",
"The name of the package that bundle image belongs to")
bundleGenerateCmd.Flags().StringVarP(&packageNameArgs, "package", "p", "", "The name of the package that bundle image belongs to")
if err := bundleGenerateCmd.MarkFlagRequired("package"); err != nil {
log.Fatalf("Failed to mark `package` flag for `generate` subcommand as required")
}

bundleGenerateCmd.Flags().StringVarP(&packageNameArgs, "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", "", "The list of channels that bundle image belongs to")
if err := bundleGenerateCmd.MarkFlagRequired("channels"); err != nil {
log.Fatalf("Failed to mark `channels` flag for `generate` subcommand as required")
}

bundleGenerateCmd.Flags().StringVarP(&channelsArgs, "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", "", "The default channel for the bundle image")

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

return bundleGenerateCmd
}
Expand Down
4 changes: 0 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdko
github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWXgklEdEo=
github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI=
github.com/agnivade/levenshtein v1.0.1/go.mod h1:CURSv5d9Uaml+FovSIICkLbAUZ9S4RqaHDIsdSBg7lM=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc h1:cAKDfWh5VpdgMhJosfJnn5/FoN2SRZ4p7fJNX58YPaU=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf h1:qet1QNfXsQxTZqLG4oE62mJzwPIB8+Tee4RNCL9ulrY=
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883/go.mod h1:rCTlJbsFo29Kk6CurOXKm700vrz8f0KW0JNfpkRJY/8=
github.com/antihax/optional v0.0.0-20180407024304-ca021399b1a6 h1:uZuxRZCz65cG1o6K/xUqImNcYKtmk9ylqaH0itMSvzA=
Expand Down Expand Up @@ -391,7 +389,6 @@ github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:
github.com/prometheus/common v0.0.0-20181126121408-4724e9255275 h1:PnBWHBf+6L0jOqq0gIVUe6Yk0/QMZ640k6NvkxcBf+8=
github.com/prometheus/common v0.0.0-20181126121408-4724e9255275/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro=
github.com/prometheus/common v0.2.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4=
github.com/prometheus/common v0.4.1 h1:K0MGApIoQvMw27RTdJkPbr3JZ7DNbtxQNyi5STVM6Kw=
github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4=
github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
github.com/prometheus/procfs v0.0.0-20181204211112-1dc9a6cbc91a/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
Expand Down Expand Up @@ -601,7 +598,6 @@ google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyac
google.golang.org/grpc v1.23.1/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
google.golang.org/grpc v1.24.0 h1:vb/1TCsVn3DcJlQ0Gs1yB1pKI6Do2/QNwxdKqmc/b0s=
google.golang.org/grpc v1.24.0/go.mod h1:XDChyiUovWa60DnaeDeZmSW86xtLtjtZbwvSiRnRtcA=
gopkg.in/alecthomas/kingpin.v2 v2.2.6 h1:jMFz6MfLP0/4fUyZle81rXUoxOBFi19VUFKVDOQfozc=
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
Expand Down
3 changes: 1 addition & 2 deletions pkg/lib/bundle/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ func ExecuteCommand(cmd *exec.Cmd) error {
// @channels: The list of channels that bundle image belongs to
// @channelDefault: The default channel for the bundle image
// @overwrite: Boolean flag to enable overwriting annotations.yaml locally if existed
func BuildFunc(directory, outputDir, imageTag, imageBuilder, packageName, channels, channelDefault string,
overwrite bool) error {
func BuildFunc(directory, outputDir, imageTag, imageBuilder, packageName, channels, channelDefault string, overwrite bool) error {
_, err := os.Stat(directory)
if os.IsNotExist(err) {
return err
Expand Down
22 changes: 0 additions & 22 deletions pkg/lib/bundle/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,28 +76,6 @@ func GenerateFunc(directory, outputDir, packageName, channels, channelDefault st
return err
}

// Channels and packageName are required fields where as default channel is automatically filled if unspecified
// and that either of the required field is missing. We are interpreting the bundle information through
// bundle directory embedded in the package folder.
if channels == "" || packageName == "" {
i, err := NewBundleDirInterperter(filepath.Join(directory, ".."))
if err != nil {
return fmt.Errorf("please manually input channels and packageName, "+
"error interpreting bundle from directory %s, %v", directory, err)
}
if channels == "" {
channels = strings.Join(i.GetBundleChannels(), ",")
}

if packageName == "" {
packageName = i.GetPackageName()
}

if channelDefault == "" {
channelDefault = i.GetDefaultChannel()
}
}

log.Info("Building annotations.yaml")

// Generate annotations.yaml
Expand Down
54 changes: 0 additions & 54 deletions pkg/lib/bundle/interpreter.go

This file was deleted.

68 changes: 0 additions & 68 deletions pkg/lib/bundle/interpreter_test.go

This file was deleted.

53 changes: 0 additions & 53 deletions pkg/registry/csv.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,9 @@ package registry

import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"path"

v1 "k8s.io/api/apps/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/yaml"

"github.com/operator-framework/api/pkg/operators"
)

const (
Expand Down Expand Up @@ -62,50 +53,6 @@ type ClusterServiceVersion struct {
Spec json.RawMessage `json:"spec"`
}

// ReadCSVFromBundleDirectory tries to parse every YAML file in the directory and see if they are CSV.
// According to the strict one CSV rule for every bundle, we return the first file that is considered a CSV type.
func ReadCSVFromBundleDirectory(bundleDir string) (*ClusterServiceVersion, error) {
dirContent, err := ioutil.ReadDir(bundleDir)
if err != nil {
return nil, fmt.Errorf("error reading bundle directory %s, %v", bundleDir, err)
}

files := []string{}
for _, f := range dirContent {
if !f.IsDir() {
files = append(files, f.Name())
}
}

for _, file := range files {
yamlReader, err := os.Open(path.Join(bundleDir, file))
if err != nil {
continue
}

unstructuredCSV := unstructured.Unstructured{}
csv := ClusterServiceVersion{}

decoder := yaml.NewYAMLOrJSONDecoder(yamlReader, 30)
if err = decoder.Decode(&unstructuredCSV); err != nil {
return nil, fmt.Errorf("error unmarshalling CSV, %v", err)
}

if unstructuredCSV.GetKind() != operators.ClusterServiceVersionKind {
continue
}

if err := runtime.DefaultUnstructuredConverter.FromUnstructured(unstructuredCSV.UnstructuredContent(),
&csv); err != nil {
return nil, err
}

return &csv, nil
}
return nil, fmt.Errorf("csv typed YAML file not found in %s", bundleDir)

}

// GetReplaces returns the name of the older ClusterServiceVersion object that
// is replaced by this ClusterServiceVersion object.
//
Expand Down