Skip to content

Commit 1810754

Browse files
committed
bundle create: fix issue where manifests/ is expected by the
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
1 parent 7feffb0 commit 1810754

12 files changed

+403
-220
lines changed

CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66
- 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))
77
- 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))
88
- The printout for the compatible Kubernetes Version [#2446](https://github.com/operator-framework/operator-sdk/pull/2446)
9-
- Add the new flag `output-dir` to the command `operator-sdk bundle create`. ([#2662](https://github.com/operator-framework/operator-sdk/pull/2662))
9+
- 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))
1010

1111
### Changed
1212

1313
- 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))
1414
- 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))
15+
- **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))
1516

1617
### Deprecated
1718

cmd/operator-sdk/bundle/cmd.go

+11-49
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,20 @@
1515
package bundle
1616

1717
import (
18-
"os"
19-
"path/filepath"
20-
21-
"github.com/operator-framework/operator-registry/pkg/lib/bundle"
2218
"github.com/spf13/cobra"
2319
)
2420

21+
//nolint:structcheck
22+
type bundleCmd struct {
23+
directory string
24+
packageName string
25+
imageTag string
26+
imageBuilder string
27+
defaultChannel string
28+
channels []string
29+
generateOnly bool
30+
}
31+
2532
func NewCmd() *cobra.Command {
2633
cmd := &cobra.Command{
2734
Use: "bundle",
@@ -39,48 +46,3 @@ https://github.com/openshift/enhancements/blob/master/enhancements/olm/operator-
3946
)
4047
return cmd
4148
}
42-
43-
type bundleCmd struct {
44-
directory string
45-
outputDir string
46-
packageName string
47-
imageTag string
48-
imageBuilder string
49-
defaultChannel string
50-
channels []string
51-
generateOnly bool
52-
}
53-
54-
// cleanupFuncs returns a set of general funcs to clean up after a bundle
55-
// subcommand.
56-
func (c bundleCmd) cleanupFuncs() (fs []func()) {
57-
manifestDir := c.outputDir
58-
if manifestDir == "" {
59-
manifestDir = c.directory
60-
}
61-
absManifestDir, _ := filepath.Abs(manifestDir)
62-
manifestParent := filepath.Dir(absManifestDir)
63-
metaDir := filepath.Join(manifestParent, bundle.MetadataDir)
64-
metaExists := isExist(metaDir)
65-
66-
workingDir, _ := os.Getwd()
67-
dockerFile := filepath.Join(workingDir, bundle.DockerFile)
68-
dockerFileExists := isExist(dockerFile)
69-
fs = append(fs,
70-
func() {
71-
if !metaExists {
72-
_ = os.RemoveAll(metaDir)
73-
}
74-
},
75-
func() {
76-
if !dockerFileExists {
77-
_ = os.RemoveAll(dockerFile)
78-
}
79-
})
80-
return fs
81-
}
82-
83-
func isExist(path string) bool {
84-
_, err := os.Stat(path)
85-
return os.IsExist(err)
86-
}

0 commit comments

Comments
 (0)