Skip to content

Commit

Permalink
bundle create: fix issue where manifests/ is expected by the
Browse files Browse the repository at this point in the history
operator-registry image builder but not generated by the SDK.
In case deploy/olm-catalog/<operator-name>/manifests doesn't
exist, create one and delete it after the image is done
building. If --generate-only is set, do not remove manifests/.
--version lets a user specify which operator version they want
to build an image for, and --latest uses the highest semver'd
operator in the bundle parent dir.

doc,website: update generated CLI docs

CHANGELOG.md: --output-dir addition and breaking change for bundle.Dockerfile location

doc/migration: add breaking change to migration guide
  • Loading branch information
estroz committed Mar 28, 2020
1 parent 7feffb0 commit b0d9d75
Show file tree
Hide file tree
Showing 12 changed files with 350 additions and 208 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
- The methods `ctx.GetOperatorNamespace()` and `ctx.GetWatchNamespace()` was added `pkg/test` in order to replace `ctx.GetNamespace()` which is deprecated. ([#2617](https://github.com/operator-framework/operator-sdk/pull/2617))
- The `--crd-version` flag was added to the `new`, `add api`, `add crd`, and `generate crds` commands so that users can opt-in to `v1` CRDs. ([#2684](https://github.com/operator-framework/operator-sdk/pull/2684))
- The printout for the compatible Kubernetes Version [#2446](https://github.com/operator-framework/operator-sdk/pull/2446)
- Add the new flag `output-dir` to the command `operator-sdk bundle create`. ([#2662](https://github.com/operator-framework/operator-sdk/pull/2662))
- Add the new flag `--output-dir` to the command [`operator-sdk bundle create`](./doc/cli/operator-sdk_bundle_create.md). ([#2715](https://github.com/operator-framework/operator-sdk/pull/2715))

### Changed

- The scorecard when creating a Custom Resource, will produce a message to the user if that CR already exists. ([#2683](https://github.com/operator-framework/operator-sdk/pull/2683))
- Upgrade the `operator-registry` dependency version from `v1.5.7`to `v1.6.0` to update `bundle create` behaviour. ([#2662](https://github.com/operator-framework/operator-sdk/pull/2662))
- **Breaking Change:** [`operator-sdk bundle create --generate-only`](./doc/cli/operator-sdk_bundle_create.md) now writes a Dockerfile to `<project-root>/bundle.Dockerfile` and copies bundle manifests directly from the argument to `--directory`. ([#2715](https://github.com/operator-framework/operator-sdk/pull/2715))

### Deprecated

Expand Down
60 changes: 11 additions & 49 deletions cmd/operator-sdk/bundle/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,20 @@
package bundle

import (
"os"
"path/filepath"

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

//nolint:structcheck
type bundleCmd struct {
directory string
packageName string
imageTag string
imageBuilder string
defaultChannel string
channels []string
generateOnly bool
}

func NewCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "bundle",
Expand All @@ -39,48 +46,3 @@ https://github.com/openshift/enhancements/blob/master/enhancements/olm/operator-
)
return cmd
}

type bundleCmd struct {
directory string
outputDir string
packageName string
imageTag string
imageBuilder string
defaultChannel string
channels []string
generateOnly bool
}

// cleanupFuncs returns a set of general funcs to clean up after a bundle
// subcommand.
func (c bundleCmd) cleanupFuncs() (fs []func()) {
manifestDir := c.outputDir
if manifestDir == "" {
manifestDir = c.directory
}
absManifestDir, _ := filepath.Abs(manifestDir)
manifestParent := filepath.Dir(absManifestDir)
metaDir := filepath.Join(manifestParent, bundle.MetadataDir)
metaExists := isExist(metaDir)

workingDir, _ := os.Getwd()
dockerFile := filepath.Join(workingDir, bundle.DockerFile)
dockerFileExists := isExist(dockerFile)
fs = append(fs,
func() {
if !metaExists {
_ = os.RemoveAll(metaDir)
}
},
func() {
if !dockerFileExists {
_ = os.RemoveAll(dockerFile)
}
})
return fs
}

func isExist(path string) bool {
_, err := os.Stat(path)
return os.IsExist(err)
}
Loading

0 comments on commit b0d9d75

Please sign in to comment.