diff --git a/CHANGELOG.md b/CHANGELOG.md index 5bff74d8fd..b02760e5f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 `/bundle.Dockerfile` and copies bundle manifests directly from the argument to `--directory`. ([#2715](https://github.com/operator-framework/operator-sdk/pull/2715)) ### Deprecated diff --git a/cmd/operator-sdk/bundle/cmd.go b/cmd/operator-sdk/bundle/cmd.go index 1b8e452acb..245b55c344 100644 --- a/cmd/operator-sdk/bundle/cmd.go +++ b/cmd/operator-sdk/bundle/cmd.go @@ -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", @@ -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) -} diff --git a/cmd/operator-sdk/bundle/create.go b/cmd/operator-sdk/bundle/create.go index 5d9cd05d88..86fd4f3b60 100644 --- a/cmd/operator-sdk/bundle/create.go +++ b/cmd/operator-sdk/bundle/create.go @@ -17,22 +17,33 @@ package bundle import ( "errors" "fmt" + "io/ioutil" "os" "path/filepath" "strings" - catalog "github.com/operator-framework/operator-sdk/internal/scaffold/olm-catalog" - "github.com/operator-framework/operator-sdk/internal/util/projutil" + "github.com/operator-framework/operator-sdk/internal/util/fileutil" + "github.com/blang/semver" "github.com/operator-framework/operator-registry/pkg/lib/bundle" log "github.com/sirupsen/logrus" "github.com/spf13/cobra" + "github.com/spf13/pflag" ) +type bundleCreateCmd struct { + bundleCmd + + outputDir string + version string + useLatestVersion bool +} + // newCreateCmd returns a command that will build operator bundle image or // generate metadata for them. func newCreateCmd() *cobra.Command { - c := &bundleCmd{} + c := &bundleCreateCmd{} + cmd := &cobra.Command{ Use: "create", Short: "Create an operator bundle image", @@ -41,92 +52,247 @@ bundle image containing operator metadata and manifests, tagged with the provided image tag. To write metadata and a bundle image Dockerfile to disk, set '--generate-only=true'. -Bundle metadata will be generated in /metadata, and the Dockerfile -in . This flag is useful if you want to build an operator's -bundle image manually or modify metadata before building an image. +Bundle metadata will be generated in (dirname )/metadata, and the +Dockerfile the /bundle.Dockerfile. This flag is useful if you want +to build an operator's bundle image manually or modify metadata before building +an image. More information on operator bundle images and metadata: https://github.com/openshift/enhancements/blob/master/enhancements/olm/operator-bundle.md#docker -NOTE: bundle images are not runnable.`, +NOTE: bundle images are not runnable. +`, Example: `The following invocation will build a test-operator bundle image using Docker. This image will contain manifests for package channels 'stable' and 'beta': -$ operator-sdk bundle create quay.io/example/test-operator:v0.1.0 \ - --directory ./deploy/olm-catalog/test-operator \ - --package test-operator \ - --channels stable,beta \ - --default-channel stable + $ operator-sdk bundle create quay.io/example/test-operator:v0.1.0 \ + --directory ./deploy/olm-catalog/test-operator/0.1.0 \ + --package test-operator \ + --channels stable,beta \ + --default-channel stable -Assuming your operator has the same name as your operator and the only channel -is 'stable', the above command can be abbreviated to: +Assuming your operator has the same name as your operator, the tag corresponds to +a bundle directory name, and the only channel is 'stable', the above command can +be abbreviated to: -$ operator-sdk bundle create quay.io/example/test-operator:v0.1.0 + $ operator-sdk bundle create quay.io/example/test-operator:v0.1.0 The following invocation will generate test-operator bundle metadata and Dockerfile without building the image: -$ operator-sdk bundle create \ - --generate-only \ - --directory ./deploy/olm-catalog/test-operator \ - --package test-operator \ - --channels stable,beta \ - --default-channel stable`, + $ operator-sdk bundle create \ + --generate-only \ + --directory ./deploy/olm-catalog/test-operator/0.1.0 \ + --package test-operator \ + --channels stable,beta \ + --default-channel stable +`, RunE: func(cmd *cobra.Command, args []string) error { - channels := strings.Join(c.channels, ",") - if c.generateOnly { - if len(args) != 0 { - return fmt.Errorf("command %s does not accept any arguments", cmd.CommandPath()) - } - err := bundle.GenerateFunc(c.directory, c.outputDir, c.packageName, channels, - c.defaultChannel, true) - if err != nil { - log.Fatalf("Error generating bundle image files: %v", err) - } - return nil + if err := c.validate(args); err != nil { + return fmt.Errorf("error validating args: %v", err) } - // An image tag is required for build only. - if len(args) != 1 { - return errors.New("a bundle image tag is a required argument, ex. example.com/test-operator:v0.1.0") - } - c.imageTag = args[0] - // Clean up transient metadata and Dockerfile once the image is built, - // as they are no longer needed. - for _, cleanup := range c.cleanupFuncs() { - defer cleanup() + + if !c.generateOnly { + c.imageTag = args[0] } - // Build but never overwrite existing metadata/Dockerfile. - err := bundle.BuildFunc(c.directory, c.outputDir, c.imageTag, c.imageBuilder, - c.packageName, channels, c.defaultChannel, false) - if err != nil { - log.Fatalf("Error building bundle image: %v", err) + if err := c.run(); err != nil { + log.Fatal(err) } return nil }, } - // Set up default values. - projectName := filepath.Base(projutil.MustGetwd()) - defaultDir := "" - if _, err := os.Stat(catalog.OLMCatalogDir); err == nil || os.IsExist(err) { - defaultDir = filepath.Join(catalog.OLMCatalogDir, projectName) - } - defaultChannels := []string{"stable"} + c.addToFlagSet(cmd.Flags()) + + return cmd +} + +func (c *bundleCreateCmd) addToFlagSet(fs *pflag.FlagSet) { - cmd.Flags().StringVarP(&c.directory, "directory", "d", defaultDir, - "The directory where bundle manifests are located") - cmd.Flags().StringVarP(&c.outputDir, "output-dir", "o", "", + fs.StringVarP(&c.directory, "directory", "d", "", + "The directory where bundle manifests are located, ex. /deploy/olm-catalog/. "+ + "Set if package name differs from project name") + fs.StringVarP(&c.outputDir, "output-dir", "o", "", "Optional output directory for operator manifests") - cmd.Flags().StringVarP(&c.packageName, "package", "p", projectName, + fs.StringVarP(&c.version, "version", "v", "", + "Version of operator to build an image for. Set this if you do not have a "+ + "'manifests' directory at /deploy/olm-catalog//manifests") + fs.BoolVar(&c.useLatestVersion, "latest", false, + "Use the latest semantically versioned directory in /deploy/olm-catalog/") + fs.StringVarP(&c.imageTag, "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:v0.1.0)") + fs.StringVarP(&c.packageName, "package", "p", "", "The name of the package that bundle image belongs to. Set if package name differs from project name") - cmd.Flags().StringSliceVarP(&c.channels, "channels", "c", defaultChannels, + fs.StringSliceVarP(&c.channels, "channels", "c", []string{"stable"}, "The list of channels that bundle image belongs to") - cmd.Flags().BoolVarP(&c.generateOnly, "generate-only", "g", false, - "Generate metadata and a Dockerfile on disk without building the bundle image") - cmd.Flags().StringVarP(&c.imageBuilder, "image-builder", "b", "docker", + fs.BoolVarP(&c.generateOnly, "generate-only", "g", false, + "Generate metadata/, manifests/ and a Dockerfile on disk without building the bundle image") + fs.StringVarP(&c.imageBuilder, "image-builder", "b", "docker", "Tool to build container images. One of: [docker, podman, buildah]") - cmd.Flags().StringVarP(&c.defaultChannel, "default-channel", "e", "", + fs.StringVarP(&c.defaultChannel, "default-channel", "e", "", "The default channel for the bundle image") +} - return cmd +func (c bundleCreateCmd) validate(args []string) error { + if c.directory == "" { + return fmt.Errorf("--directory must be set") + } + if c.generateOnly { + if len(args) != 0 { + return errors.New("the command does not accept any arguments with --generate-only set") + } + } else { + if len(args) != 1 { + return errors.New("a bundle image tag is a required argument, ex. example.com/test-operator:v0.1.0") + } + } + // Validate semver if not latest + if c.version != "" { + if c.useLatestVersion { + return fmt.Errorf("cannot set both --latest and --version") + } + if _, err := semver.Parse(c.version); err != nil { + return fmt.Errorf("version %s is invalid: %v", c.version, err) + } + } + return nil +} + +func (c bundleCreateCmd) run() (err error) { + channels := strings.Join(c.channels, ",") + manifestsDir := filepath.Join(c.directory, bundle.ManifestsDir) + manifestsDirExisted := isExist(manifestsDir) + // If the latest version is passed, find the highest semver in c.directory. + if c.useLatestVersion { + if c.version, err = findLatestSemverDir(c.directory); err != nil { + return fmt.Errorf("error finding latest operator bundle dir: %v", err) + } + } + + // version will be empty if neither useLatestVersion nor version were set + // by the user, so they want manifests/ left alone. Otherwise update it. + if c.version != "" { + versionedDir := filepath.Join(c.directory, c.version) + if err := copyDirShallow(versionedDir, manifestsDir); err != nil { + return fmt.Errorf("error updating manifests dir: %v", err) + } + } + + if c.generateOnly { + err := bundle.GenerateFunc(manifestsDir, c.outputDir, c.packageName, channels, c.defaultChannel, true) + if err != nil { + return fmt.Errorf("error generating bundle image files: %v", err) + } + return nil + } + + // Clean up transient files once the image is built, as they are no longer + // needed. + if !manifestsDirExisted { + defer func() { + if err := os.RemoveAll(manifestsDir); err != nil { + log.Fatalf("error removing transient manifests dir %s: %v", manifestsDir, err) + } + }() + } + for _, cleanup := range c.cleanupFuncs() { + defer cleanup() + } + + // Build but never overwrite existing metadata/Dockerfile. + err = bundle.BuildFunc(manifestsDir, c.outputDir, c.imageTag, c.imageBuilder, + c.packageName, channels, c.defaultChannel, false) + if err != nil { + return fmt.Errorf("error building bundle image: %v", err) + } + + return nil +} + +func findLatestSemverDir(operatorDir string) (latestVerStr string, err error) { + infos, err := ioutil.ReadDir(operatorDir) + if err != nil { + return "", err + } + versions := semver.Versions{} + for _, info := range infos { + if info.IsDir() { + childDir := filepath.Clean(info.Name()) + ver, err := semver.Parse(childDir) + if err != nil { + log.Debugf("Skipping non-semver dir %s: %v", childDir, err) + continue + } + versions = append(versions, ver) + } + } + if len(versions) == 0 { + return "", fmt.Errorf("no semver dirs found in %s", operatorDir) + } + semver.Sort(versions) + latestVerStr = versions[len(versions)-1].String() + return latestVerStr, nil +} + +func copyDirShallow(from, to string) error { + infos, err := ioutil.ReadDir(from) + if err != nil { + return err + } + if err = os.MkdirAll(to, fileutil.DefaultDirFileMode); err != nil { + return err + } + + for _, info := range infos { + fromPath := filepath.Join(from, info.Name()) + toPath := filepath.Join(to, info.Name()) + if !info.IsDir() { + b, err := ioutil.ReadFile(fromPath) + if err != nil { + return err + } + if err = ioutil.WriteFile(toPath, b, info.Mode()); err != nil { + return err + } + } else { + log.Debugf("Skipping copy %s to %s", fromPath, toPath) + } + } + + return nil +} + +// cleanupFuncs returns a set of funcs to clean up after 'bundle create'. +func (c bundleCreateCmd) cleanupFuncs() (fs []func()) { + metadataAndManifestDir := c.outputDir + if metadataAndManifestDir == "" { + metadataAndManifestDir = c.directory + } + + operatorDir := filepath.Dir(metadataAndManifestDir) + metaDir := filepath.Join(operatorDir, bundle.MetadataDir) + metaExists := isExist(metaDir) + dockerFileExists := isExist(bundle.DockerFile) + fs = append(fs, + func() { + if !metaExists { + if err := os.RemoveAll(metaDir); err != nil { + log.Fatalf("error removing transient metadata dir %s: %v", metaDir, err) + } + } + }, + func() { + if !dockerFileExists { + if err := os.RemoveAll(bundle.DockerFile); err != nil { + log.Fatalf("error removing transient %s: %v", bundle.DockerFile, err) + } + } + }) + return fs +} + +func isExist(path string) bool { + _, err := os.Stat(path) + return err == nil || os.IsExist(err) } diff --git a/cmd/operator-sdk/bundle/validate.go b/cmd/operator-sdk/bundle/validate.go index 1ff87f013d..50651fe8dc 100644 --- a/cmd/operator-sdk/bundle/validate.go +++ b/cmd/operator-sdk/bundle/validate.go @@ -39,22 +39,23 @@ Note: the image being validated must exist in a remote registry, not just locall Example: `The following command flow will generate test-operator bundle image manifests and validate that image: -$ cd ${HOME}/go/test-operator + $ cd ${HOME}/go/test-operator -# Generate manifests locally. -$ operator-sdk bundle create --generate-only + # Generate manifests locally. + $ operator-sdk bundle create --generate-only -# Modify the metadata and Dockerfile. -$ cd ./deploy/olm-catalog/test-operator -$ vim ./metadata/annotations.yaml -$ vim ./Dockerfile + # Modify the metadata and Dockerfile. + $ cd ./deploy/olm-catalog/test-operator + $ vim ./metadata/annotations.yaml + $ vim ./Dockerfile -# Build and push the image using the docker CLI. -$ docker build -t quay.io/example/test-operator:v0.1.0 . -$ docker push quay.io/example/test-operator:v0.1.0 + # Build and push the image using the docker CLI. + $ docker build -t quay.io/example/test-operator:v0.1.0 . + $ docker push quay.io/example/test-operator:v0.1.0 -# Ensure the image with modified metadata/Dockerfile is valid. -$ operator-sdk bundle validate quay.io/example/test-operator:v0.1.0`, + # Ensure the image with modified metadata/Dockerfile is valid. + $ operator-sdk bundle validate quay.io/example/test-operator:v0.1.0 +`, RunE: func(cmd *cobra.Command, args []string) error { if len(args) != 1 { return errors.New("a bundle image tag is a required argument, ex. example.com/test-operator:v0.1.0") @@ -70,11 +71,11 @@ $ operator-sdk bundle validate quay.io/example/test-operator:v0.1.0`, log.Error(err.Error()) } }() + logger := log.WithFields(log.Fields{ "container-tool": c.imageBuilder, "bundle-dir": dir, }) - log.SetLevel(log.DebugLevel) val := bundle.NewImageValidator(c.imageBuilder, logger) if err = val.PullBundleImage(c.imageTag, dir); err != nil { log.Fatalf("Error to unpacking image: %v", err) diff --git a/doc/cli/operator-sdk_bundle_create.md b/doc/cli/operator-sdk_bundle_create.md index b93c980125..b6003b8074 100644 --- a/doc/cli/operator-sdk_bundle_create.md +++ b/doc/cli/operator-sdk_bundle_create.md @@ -9,15 +9,17 @@ bundle image containing operator metadata and manifests, tagged with the provided image tag. To write metadata and a bundle image Dockerfile to disk, set '--generate-only=true'. -Bundle metadata will be generated in /metadata, and the Dockerfile -in . This flag is useful if you want to build an operator's -bundle image manually or modify metadata before building an image. +Bundle metadata will be generated in (dirname )/metadata, and the +Dockerfile the /bundle.Dockerfile. This flag is useful if you want +to build an operator's bundle image manually or modify metadata before building +an image. More information on operator bundle images and metadata: https://github.com/openshift/enhancements/blob/master/enhancements/olm/operator-bundle.md#docker NOTE: bundle images are not runnable. + ``` operator-sdk bundle create [flags] ``` @@ -28,26 +30,28 @@ operator-sdk bundle create [flags] The following invocation will build a test-operator bundle image using Docker. This image will contain manifests for package channels 'stable' and 'beta': -$ operator-sdk bundle create quay.io/example/test-operator:v0.1.0 \ - --directory ./deploy/olm-catalog/test-operator \ - --package test-operator \ - --channels stable,beta \ - --default-channel stable + $ operator-sdk bundle create quay.io/example/test-operator:v0.1.0 \ + --directory ./deploy/olm-catalog/test-operator/0.1.0 \ + --package test-operator \ + --channels stable,beta \ + --default-channel stable -Assuming your operator has the same name as your operator and the only channel -is 'stable', the above command can be abbreviated to: +Assuming your operator has the same name as your operator, the tag corresponds to +a bundle directory name, and the only channel is 'stable', the above command can +be abbreviated to: -$ operator-sdk bundle create quay.io/example/test-operator:v0.1.0 + $ operator-sdk bundle create quay.io/example/test-operator:v0.1.0 The following invocation will generate test-operator bundle metadata and Dockerfile without building the image: -$ operator-sdk bundle create \ - --generate-only \ - --directory ./deploy/olm-catalog/test-operator \ - --package test-operator \ - --channels stable,beta \ - --default-channel stable + $ operator-sdk bundle create \ + --generate-only \ + --directory ./deploy/olm-catalog/test-operator/0.1.0 \ + --package test-operator \ + --channels stable,beta \ + --default-channel stable + ``` ### Options diff --git a/doc/cli/operator-sdk_bundle_validate.md b/doc/cli/operator-sdk_bundle_validate.md index a883f4193f..1d7cf45cc4 100644 --- a/doc/cli/operator-sdk_bundle_validate.md +++ b/doc/cli/operator-sdk_bundle_validate.md @@ -20,22 +20,23 @@ operator-sdk bundle validate [flags] The following command flow will generate test-operator bundle image manifests and validate that image: -$ cd ${HOME}/go/test-operator + $ cd ${HOME}/go/test-operator -# Generate manifests locally. -$ operator-sdk bundle create --generate-only + # Generate manifests locally. + $ operator-sdk bundle create --generate-only -# Modify the metadata and Dockerfile. -$ cd ./deploy/olm-catalog/test-operator -$ vim ./metadata/annotations.yaml -$ vim ./Dockerfile + # Modify the metadata and Dockerfile. + $ cd ./deploy/olm-catalog/test-operator + $ vim ./metadata/annotations.yaml + $ vim ./Dockerfile -# Build and push the image using the docker CLI. -$ docker build -t quay.io/example/test-operator:v0.1.0 . -$ docker push quay.io/example/test-operator:v0.1.0 + # Build and push the image using the docker CLI. + $ docker build -t quay.io/example/test-operator:v0.1.0 . + $ docker push quay.io/example/test-operator:v0.1.0 + + # Ensure the image with modified metadata/Dockerfile is valid. + $ operator-sdk bundle validate quay.io/example/test-operator:v0.1.0 -# Ensure the image with modified metadata/Dockerfile is valid. -$ operator-sdk bundle validate quay.io/example/test-operator:v0.1.0 ``` ### Options diff --git a/doc/migration/version-upgrade-guide.md b/doc/migration/version-upgrade-guide.md index 6f942c045e..551db60205 100644 --- a/doc/migration/version-upgrade-guide.md +++ b/doc/migration/version-upgrade-guide.md @@ -984,21 +984,21 @@ func serveCRMetrics(cfg *rest.Config, operatorNs string) error { ### Breaking changes #### `TestCtx` in `pkg/test` has been deprecated - + The type name `TestCtx` in `pkg/test` has been deprecated and renamed to `Context`. Users of the e2e framework should do the following: - + - Replace `TestCtx` with `Context` - Replace `NewTestCtx` with `NewContext` #### Scorecard only supports YAML config files - + The scorecard feature now only supports YAML config files. Config files with other extensions are no longer supported and should be changed to the YAML format. For further information see [`scorecard config file`](https://github.com/operator-framework/operator-sdk/blob/v0.16.x/doc/test-framework/scorecard.md#config-file) - -### Breaking Changes for Ansible -#### Remove Ansible container sidecar +### Breaking Changes for Ansible + +#### Remove Ansible container sidecar -The Ansible logs are now output in the operator container, so there is no longer a need for the Ansible container sidecar. To reflect this change, update the `deploy/operator.yaml` file as follows. +The Ansible logs are now output in the operator container, so there is no longer a need for the Ansible container sidecar. To reflect this change, update the `deploy/operator.yaml` file as follows. Remove: @@ -1068,13 +1068,13 @@ The methods `ctx.GetOperatorNamespace()` and `ctx.GetWatchNamespace()` was added This release contains breaking changes in some commands. -- The --namespace flag from `operator-sdk run --local` command, `operator-sdk test --local` command and `operator-sdk cleanup` command was deprecated and was replaced by --watch-namespace and --operator-namespace . +- The --namespace flag from `operator-sdk run --local` command, `operator-sdk test --local` command and `operator-sdk cleanup` command was deprecated and was replaced by --watch-namespace and --operator-namespace. [#2617](https://github.com/operator-framework/operator-sdk/pull/2617) Note that --watch-namespace can be used to set the namespace(s) which the operator will watch for changes. It will set the environment variable WATCH_NAMESPACE. Use explicitly an empty string to watch all namespaces or inform a List of namespaces such as "ns1,ns2" when the operator is cluster-scoped. If you use a List, then it needs contains the namespace where the operator is "deployed" in since the default metrics implementation will manage resources in the Operator's namespace. By default, it will be the Operator Namespace. Then, use the flag --operator-namespace to inform the namespace where the Operator will be "deployed" in and then, it will set the environment variable OPERATOR_NAMESPACE. If this value is not set, then it will be the namespace defined as default in the Kubeconfig. -NOTE: For more information check the PRs which are responsible for the above changes [#2617](https://github.com/operator-framework/operator-sdk/pull/2617). +- If you've run `operator-sdk bundle create --generate-only`, move your bundle Dockerfile at `/deploy/olm-catalog//Dockerfile` to `/bundle.Dockerfile` and update the first `COPY` from `COPY /*.yaml manifests/` to `COPY deploy/olm-catalog// manifests/`. [#2715](https://github.com/operator-framework/operator-sdk/pull/2715) [legacy-kubebuilder-doc-crd]: https://book-v1.book.kubebuilder.io/beyond_basics/generating_crd.html [v0.8.2-go-mod]: https://github.com/operator-framework/operator-sdk/blob/28bd2b0d4fd25aa68e15d928ae09d3c18c3b51da/internal/pkg/scaffold/go_mod.go#L40-L94 diff --git a/website/content/en/docs/cli/operator-sdk.md b/website/content/en/docs/cli/operator-sdk.md index 89025490a7..dbb7d98659 100644 --- a/website/content/en/docs/cli/operator-sdk.md +++ b/website/content/en/docs/cli/operator-sdk.md @@ -16,7 +16,7 @@ An SDK for building operators with ease * [operator-sdk add](operator-sdk_add.md) - Adds a controller or resource to the project * [operator-sdk build](operator-sdk_build.md) - Compiles code and builds artifacts -* [operator-sdk bundle](operator-sdk_bundle.md) - Work with operator bundle metadata and bundle images +* [operator-sdk bundle](operator-sdk_bundle.md) - Work with operator bundle metadata and operator bundle and index images * [operator-sdk cleanup](operator-sdk_cleanup.md) - Delete and clean up after a running Operator * [operator-sdk completion](operator-sdk_completion.md) - Generators for shell completions * [operator-sdk generate](operator-sdk_generate.md) - Invokes a specific generator diff --git a/website/content/en/docs/cli/operator-sdk_bundle.md b/website/content/en/docs/cli/operator-sdk_bundle.md index 0b65dac2d5..cc081c2314 100644 --- a/website/content/en/docs/cli/operator-sdk_bundle.md +++ b/website/content/en/docs/cli/operator-sdk_bundle.md @@ -1,11 +1,12 @@ ## operator-sdk bundle -Work with operator bundle metadata and bundle images +Work with operator bundle metadata and operator bundle and index images ### Synopsis -Generate operator bundle metadata and build operator bundle images, which -are used to manage operators in the Operator Lifecycle Manager. +Generate operator bundle metadata, and build operator bundle and index images. +These image formats are used to manage operators in the Operator Lifecycle Manager +and beyond. More information on operator bundle images and metadata: https://github.com/openshift/enhancements/blob/master/enhancements/olm/operator-bundle.md#docker diff --git a/website/content/en/docs/cli/operator-sdk_bundle_create.md b/website/content/en/docs/cli/operator-sdk_bundle_create.md index a1bd6e7a55..face22ca40 100644 --- a/website/content/en/docs/cli/operator-sdk_bundle_create.md +++ b/website/content/en/docs/cli/operator-sdk_bundle_create.md @@ -9,15 +9,17 @@ bundle image containing operator metadata and manifests, tagged with the provided image tag. To write metadata and a bundle image Dockerfile to disk, set '--generate-only=true'. -Bundle metadata will be generated in /metadata, and the Dockerfile -in . This flag is useful if you want to build an operator's -bundle image manually or modify metadata before building an image. +Bundle metadata will be generated in (dirname )/metadata, and the +Dockerfile the /bundle.Dockerfile. This flag is useful if you want +to build an operator's bundle image manually or modify metadata before building +an image. More information on operator bundle images and metadata: https://github.com/openshift/enhancements/blob/master/enhancements/olm/operator-bundle.md#docker NOTE: bundle images are not runnable. + ``` operator-sdk bundle create [flags] ``` @@ -28,26 +30,28 @@ operator-sdk bundle create [flags] The following invocation will build a test-operator bundle image using Docker. This image will contain manifests for package channels 'stable' and 'beta': -$ operator-sdk bundle create quay.io/example/test-operator:v0.1.0 \ - --directory ./deploy/olm-catalog/test-operator \ - --package test-operator \ - --channels stable,beta \ - --default-channel stable + $ operator-sdk bundle create quay.io/example/test-operator:v0.1.0 \ + --directory ./deploy/olm-catalog/test-operator/0.1.0 \ + --package test-operator \ + --channels stable,beta \ + --default-channel stable -Assuming your operator has the same name as your operator and the only channel -is 'stable', the above command can be abbreviated to: +Assuming your operator has the same name as your operator, the tag corresponds to +a bundle directory name, and the only channel is 'stable', the above command can +be abbreviated to: -$ operator-sdk bundle create quay.io/example/test-operator:v0.1.0 + $ operator-sdk bundle create quay.io/example/test-operator:v0.1.0 The following invocation will generate test-operator bundle metadata and Dockerfile without building the image: -$ operator-sdk bundle create \ - --generate-only \ - --directory ./deploy/olm-catalog/test-operator \ - --package test-operator \ - --channels stable,beta \ - --default-channel stable + $ operator-sdk bundle create \ + --generate-only \ + --directory ./deploy/olm-catalog/test-operator/0.1.0 \ + --package test-operator \ + --channels stable,beta \ + --default-channel stable + ``` ### Options @@ -59,10 +63,11 @@ $ operator-sdk bundle create \ -g, --generate-only Generate metadata and a Dockerfile on disk without building the bundle image -h, --help help for create -b, --image-builder string Tool to build container images. One of: [docker, podman, buildah] (default "docker") + -o, --output-dir string Optional output directory for operator manifests -p, --package string The name of the package that bundle image belongs to. Set if package name differs from project name (default "operator-sdk") ``` ### SEE ALSO -* [operator-sdk bundle](operator-sdk_bundle.md) - Work with operator bundle metadata and bundle images +* [operator-sdk bundle](operator-sdk_bundle.md) - Work with operator bundle metadata and operator bundle and index images diff --git a/website/content/en/docs/cli/operator-sdk_bundle_validate.md b/website/content/en/docs/cli/operator-sdk_bundle_validate.md index a883f4193f..b0a3092d0a 100644 --- a/website/content/en/docs/cli/operator-sdk_bundle_validate.md +++ b/website/content/en/docs/cli/operator-sdk_bundle_validate.md @@ -20,22 +20,23 @@ operator-sdk bundle validate [flags] The following command flow will generate test-operator bundle image manifests and validate that image: -$ cd ${HOME}/go/test-operator + $ cd ${HOME}/go/test-operator -# Generate manifests locally. -$ operator-sdk bundle create --generate-only + # Generate manifests locally. + $ operator-sdk bundle create --generate-only -# Modify the metadata and Dockerfile. -$ cd ./deploy/olm-catalog/test-operator -$ vim ./metadata/annotations.yaml -$ vim ./Dockerfile + # Modify the metadata and Dockerfile. + $ cd ./deploy/olm-catalog/test-operator + $ vim ./metadata/annotations.yaml + $ vim ./Dockerfile -# Build and push the image using the docker CLI. -$ docker build -t quay.io/example/test-operator:v0.1.0 . -$ docker push quay.io/example/test-operator:v0.1.0 + # Build and push the image using the docker CLI. + $ docker build -t quay.io/example/test-operator:v0.1.0 . + $ docker push quay.io/example/test-operator:v0.1.0 + + # Ensure the image with modified metadata/Dockerfile is valid. + $ operator-sdk bundle validate quay.io/example/test-operator:v0.1.0 -# Ensure the image with modified metadata/Dockerfile is valid. -$ operator-sdk bundle validate quay.io/example/test-operator:v0.1.0 ``` ### Options @@ -47,5 +48,5 @@ $ operator-sdk bundle validate quay.io/example/test-operator:v0.1.0 ### SEE ALSO -* [operator-sdk bundle](operator-sdk_bundle.md) - Work with operator bundle metadata and bundle images +* [operator-sdk bundle](operator-sdk_bundle.md) - Work with operator bundle metadata and operator bundle and index images diff --git a/website/content/en/docs/migration/version-upgrade-guide.md b/website/content/en/docs/migration/version-upgrade-guide.md index 6f942c045e..551db60205 100644 --- a/website/content/en/docs/migration/version-upgrade-guide.md +++ b/website/content/en/docs/migration/version-upgrade-guide.md @@ -984,21 +984,21 @@ func serveCRMetrics(cfg *rest.Config, operatorNs string) error { ### Breaking changes #### `TestCtx` in `pkg/test` has been deprecated - + The type name `TestCtx` in `pkg/test` has been deprecated and renamed to `Context`. Users of the e2e framework should do the following: - + - Replace `TestCtx` with `Context` - Replace `NewTestCtx` with `NewContext` #### Scorecard only supports YAML config files - + The scorecard feature now only supports YAML config files. Config files with other extensions are no longer supported and should be changed to the YAML format. For further information see [`scorecard config file`](https://github.com/operator-framework/operator-sdk/blob/v0.16.x/doc/test-framework/scorecard.md#config-file) - -### Breaking Changes for Ansible -#### Remove Ansible container sidecar +### Breaking Changes for Ansible + +#### Remove Ansible container sidecar -The Ansible logs are now output in the operator container, so there is no longer a need for the Ansible container sidecar. To reflect this change, update the `deploy/operator.yaml` file as follows. +The Ansible logs are now output in the operator container, so there is no longer a need for the Ansible container sidecar. To reflect this change, update the `deploy/operator.yaml` file as follows. Remove: @@ -1068,13 +1068,13 @@ The methods `ctx.GetOperatorNamespace()` and `ctx.GetWatchNamespace()` was added This release contains breaking changes in some commands. -- The --namespace flag from `operator-sdk run --local` command, `operator-sdk test --local` command and `operator-sdk cleanup` command was deprecated and was replaced by --watch-namespace and --operator-namespace . +- The --namespace flag from `operator-sdk run --local` command, `operator-sdk test --local` command and `operator-sdk cleanup` command was deprecated and was replaced by --watch-namespace and --operator-namespace. [#2617](https://github.com/operator-framework/operator-sdk/pull/2617) Note that --watch-namespace can be used to set the namespace(s) which the operator will watch for changes. It will set the environment variable WATCH_NAMESPACE. Use explicitly an empty string to watch all namespaces or inform a List of namespaces such as "ns1,ns2" when the operator is cluster-scoped. If you use a List, then it needs contains the namespace where the operator is "deployed" in since the default metrics implementation will manage resources in the Operator's namespace. By default, it will be the Operator Namespace. Then, use the flag --operator-namespace to inform the namespace where the Operator will be "deployed" in and then, it will set the environment variable OPERATOR_NAMESPACE. If this value is not set, then it will be the namespace defined as default in the Kubeconfig. -NOTE: For more information check the PRs which are responsible for the above changes [#2617](https://github.com/operator-framework/operator-sdk/pull/2617). +- If you've run `operator-sdk bundle create --generate-only`, move your bundle Dockerfile at `/deploy/olm-catalog//Dockerfile` to `/bundle.Dockerfile` and update the first `COPY` from `COPY /*.yaml manifests/` to `COPY deploy/olm-catalog// manifests/`. [#2715](https://github.com/operator-framework/operator-sdk/pull/2715) [legacy-kubebuilder-doc-crd]: https://book-v1.book.kubebuilder.io/beyond_basics/generating_crd.html [v0.8.2-go-mod]: https://github.com/operator-framework/operator-sdk/blob/28bd2b0d4fd25aa68e15d928ae09d3c18c3b51da/internal/pkg/scaffold/go_mod.go#L40-L94