From eadf808a27a711b71cdb0b7d5c2530abd2ed3fb5 Mon Sep 17 00:00:00 2001 From: Eric Stroczynski Date: Wed, 17 Jun 2020 15:48:21 -0700 Subject: [PATCH 1/2] `generate ` will no longer write kustomize-related files; instead, `generate kustomize manifests` will do so. `bundle` will write manifests/metadata to the top-level `bundle/` directory, and `packagemanifests` will write manifests and the package manifest to the top-level `packagemanifests/`; these are deployable files that do not require further kustomization, so should not reside in `config/`. *: remove `config/` prefix for generated manifests/metadata, change `config/{bundle,packagemanifests}` to `config/manifests` in `--kustomize` logic --- .../fragments/rename-generate-defaults.yaml | 14 ++ cmd/operator-sdk/generate/bundle/bundle.go | 120 ++++++--------- .../generate/bundle/bundle_legacy.go | 31 +++- cmd/operator-sdk/generate/bundle/cmd.go | 86 ++++------- .../generate/packagemanifests/cmd.go | 96 ++++-------- .../packagemanifests/packagemanifests.go | 140 +++++++----------- .../packagemanifests_legacy.go | 37 +++-- internal/plugins/golang/v2/init.go | 6 +- test/e2e-new/e2e_suite.go | 27 ++-- .../docs/cli/operator-sdk_generate_bundle.md | 22 +-- .../operator-sdk_generate_packagemanifests.md | 22 +-- .../en/docs/new-cli/operator-sdk_generate.md | 2 +- .../new-cli/operator-sdk_generate_bundle.md | 44 +++--- .../operator-sdk_generate_packagemanifests.md | 46 +++--- 14 files changed, 300 insertions(+), 393 deletions(-) create mode 100644 changelog/fragments/rename-generate-defaults.yaml diff --git a/changelog/fragments/rename-generate-defaults.yaml b/changelog/fragments/rename-generate-defaults.yaml new file mode 100644 index 0000000000..151d49a547 --- /dev/null +++ b/changelog/fragments/rename-generate-defaults.yaml @@ -0,0 +1,14 @@ +entries: + - description: > + `generate ` will no longer write kustomize manifests bases and kustomization.yaml; + instead, `generate kustomize manifests` will do so + kind: change + - description: > + `--kustomize` has been removed from `generate `. Use `generate kustomize manifests` + to write manifests bases and kustomization.yaml instead + kind: removal + - description: > + `bundle` will write manifests/metadata to the top-level `bundle/` directory, + and `packagemanifests` will write manifests and the package manifest to + the top-level `packagemanifests/` directory + kind: change diff --git a/cmd/operator-sdk/generate/bundle/bundle.go b/cmd/operator-sdk/generate/bundle/bundle.go index d060255638..8f25e6bb2e 100644 --- a/cmd/operator-sdk/generate/bundle/bundle.go +++ b/cmd/operator-sdk/generate/bundle/bundle.go @@ -27,11 +27,27 @@ import ( genutil "github.com/operator-framework/operator-sdk/cmd/operator-sdk/generate/internal" gencsv "github.com/operator-framework/operator-sdk/internal/generate/clusterserviceversion" "github.com/operator-framework/operator-sdk/internal/generate/collector" - "github.com/operator-framework/operator-sdk/internal/scaffold/kustomize" + "github.com/operator-framework/operator-sdk/internal/util/projutil" ) -//nolint:lll -const examples = ` +const ( + longHelp = ` +Running 'generate bundle' is the first step to publishing your operator to a catalog and/or deploying it with OLM. +This command generates a set of bundle manifests, metadata, and a bundle.Dockerfile for your operator. +Typically one would run 'generate kustomize manifests' first to (re)generate kustomize bases consumed by this command. + +Set '--version' to supply a semantic version for your bundle if you are creating one +for the first time or upgrading an existing one. + +If '--output-dir' is set and you wish to build bundle images from that directory, +either manually update your bundle.Dockerfile or set '--overwrite'. + +More information on bundles: +https://github.com/operator-framework/operator-registry/#manifest-format +` + + //nolint:lll + examples = ` # Generate bundle files and build your bundle image with these 'make' recipes: $ make bundle $ export USERNAME= @@ -42,22 +58,24 @@ const examples = ` # manifests, metadata, and a bundle.Dockerfile: $ make manifests /home/user/go/bin/controller-gen "crd:trivialVersions=true" rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases - $ operator-sdk generate bundle -q --kustomize + $ operator-sdk generate kustomize manifests Display name for the operator (required): > memcached-operator ... - $ kustomize build config/bundle | operator-sdk generate bundle --manifests --metadata --overwrite --version 0.0.1 + $ tree config/manifests + config/manifests + ├── bases + │   └── memcached-operator.clusterserviceversion.yaml + └── kustomization.yaml + $ kustomize build config/manifests | operator-sdk generate bundle --manifests --metadata --overwrite --version 0.0.1 Generating bundle manifest version 0.0.1 ... - # After running the above commands, you should see: - $ tree config/bundle - config/bundle - ├── bases - │   └── memcached-operator.clusterserviceversion.yaml - ├── kustomization.yaml + # After running the above commands, you should see this directory structure: + $ tree bundle + bundle ├── manifests │   ├── cache.my.domain_memcacheds.yaml │   └── memcached-operator.clusterserviceversion.yaml @@ -65,7 +83,7 @@ const examples = ` └── annotations.yaml # Then it validates your bundle files and builds your bundle image: - $ operator-sdk bundle validate config/bundle + $ operator-sdk bundle validate ./bundle $ docker build -f bundle.Dockerfile -t $BUNDLE_IMG . Sending build context to Docker daemon 42.33MB Step 1/9 : FROM scratch @@ -74,15 +92,10 @@ const examples = ` # You can then push your bundle image: $ make docker-push IMG=$BUNDLE_IMG ` +) -// kustomization.yaml file contents for manifests. This should always be written to -// config/bundle/kustomization.yaml since it only references files in config. -const manifestsKustomization = `resources: -- ../default -- ../samples -` - -var defaultDir = filepath.Join("config", "bundle") +// defaultRootDir is the default root directory in which to generate bundle files. +const defaultRootDir = "bundle" // setCommonDefaults sets defaults useful to all modes of this subcommand. func (c *bundleCmd) setCommonDefaults(cfg *config.Config) { @@ -96,51 +109,6 @@ func (c *bundleCmd) setCommonDefaults(cfg *config.Config) { } } -// runKustomize generates kustomize bundle bases. -func (c bundleCmd) runKustomize(cfg *config.Config) error { - - if !c.quiet { - fmt.Println("Generating bundle manifest kustomize bases") - } - - if c.inputDir == "" { - c.inputDir = defaultDir - } - if c.outputDir == "" { - c.outputDir = defaultDir - } - if c.apisDir == "" { - if cfg.MultiGroup { - c.apisDir = "apis" - } else { - c.apisDir = "api" - } - } - - csvGen := gencsv.Generator{ - OperatorName: c.operatorName, - OperatorType: genutil.PluginKeyToOperatorType(cfg.Layout), - } - opts := []gencsv.Option{ - gencsv.WithBase(c.inputDir, c.apisDir, c.interactiveLevel), - gencsv.WithBaseWriter(c.outputDir), - } - if err := csvGen.Generate(cfg, opts...); err != nil { - return fmt.Errorf("error generating ClusterServiceVersion: %v", err) - } - - // Write a kustomization.yaml to the config directory. - if err := kustomize.Write(defaultDir, manifestsKustomization); err != nil { - return err - } - - if !c.quiet { - fmt.Println("Bases generated successfully in", c.outputDir) - } - - return nil -} - // validateManifests validates c for bundle manifests generation. func (c bundleCmd) validateManifests(*config.Config) (err error) { if c.version != "" { @@ -149,6 +117,10 @@ func (c bundleCmd) validateManifests(*config.Config) (err error) { } } + if c.kustomizeDir == "" { + return errors.New("--kustomize-dir must be set") + } + if !genutil.IsPipeReader() { if c.deployDir == "" { return errors.New("--deploy-dir must be set if not reading from stdin") @@ -179,19 +151,11 @@ func (c bundleCmd) runManifests(cfg *config.Config) (err error) { } if c.inputDir == "" { - c.inputDir = defaultDir + c.inputDir = defaultRootDir } if !c.stdout { if c.outputDir == "" { - c.outputDir = defaultDir - } - } - // Only regenerate API definitions once. - if c.apisDir == "" && !c.kustomize { - if cfg.MultiGroup { - c.apisDir = "apis" - } else { - c.apisDir = "api" + c.outputDir = defaultRootDir } } @@ -216,7 +180,9 @@ func (c bundleCmd) runManifests(cfg *config.Config) (err error) { stdout := genutil.NewMultiManifestWriter(os.Stdout) opts := []gencsv.Option{ - gencsv.WithBase(c.inputDir, c.apisDir, c.interactiveLevel), + // By not passing apisDir and turning interactive prompts on, we forcibly rely on the kustomize base + // for UI metadata and uninferrable data. + gencsv.WithBase(c.kustomizeDir, "", projutil.InteractiveHardOff), } if c.stdout { opts = append(opts, gencsv.WithWriter(stdout)) @@ -270,7 +236,7 @@ func (c bundleCmd) runMetadata() error { if directory == "" { // There may be no existing bundle at the default path, so assume manifests // only exist in the output directory. - defaultDirectory := filepath.Join(defaultDir, bundle.ManifestsDir) + defaultDirectory := filepath.Join(defaultRootDir, bundle.ManifestsDir) if c.outputDir != "" && genutil.IsNotExist(defaultDirectory) { directory = filepath.Join(c.outputDir, bundle.ManifestsDir) } else { diff --git a/cmd/operator-sdk/generate/bundle/bundle_legacy.go b/cmd/operator-sdk/generate/bundle/bundle_legacy.go index 738f54142a..4a84e9082d 100644 --- a/cmd/operator-sdk/generate/bundle/bundle_legacy.go +++ b/cmd/operator-sdk/generate/bundle/bundle_legacy.go @@ -28,7 +28,25 @@ import ( "github.com/operator-framework/operator-sdk/internal/util/projutil" ) -const examplesLegacy = ` +const ( + longHelpLegacy = ` +Running 'generate bundle' is the first step to publishing your operator to a catalog +and/or deploying it with OLM. This command generates a set of bundle manifests, +metadata, and a bundle.Dockerfile for your operator, and will interactively ask +for UI metadata, an important component of publishing your operator, by default unless +a bundle for your operator exists or you set '--interactive=false'. + +Set '--version' to supply a semantic version for your bundle if you are creating one +for the first time or upgrading an existing one. + +If '--output-dir' is set and you wish to build bundle images from that directory, +either manually update your bundle.Dockerfile or set '--overwrite'. + +More information on bundles: +https://github.com/operator-framework/operator-registry/#manifest-format +` + + examplesLegacy = ` # Create bundle manifests, metadata, and a bundle.Dockerfile: $ operator-sdk generate bundle --version 0.0.1 INFO[0000] Generating bundle manifest version 0.0.1 @@ -56,9 +74,10 @@ const examplesLegacy = ` ... $ docker push $BUNDLE_IMG ` +) // setCommonDefaultsLegacy sets defaults useful to all modes of this subcommand. -func (c *bundleCmd) setCommonDefaultsLegacy() { +func (c *bundleCmdLegacy) setCommonDefaults() { if c.operatorName == "" { c.operatorName = filepath.Base(projutil.MustGetwd()) } @@ -71,7 +90,7 @@ func (c *bundleCmd) setCommonDefaultsLegacy() { // validateManifestsLegacy validates c for bundle manifests generation for // legacy project layouts. -func (c bundleCmd) validateManifestsLegacy() error { +func (c bundleCmdLegacy) validateManifests() error { if c.version != "" { if err := genutil.ValidateVersion(c.version); err != nil { return err @@ -81,7 +100,7 @@ func (c bundleCmd) validateManifestsLegacy() error { } // runManifestsLegacy generates bundle manifests for legacy project layouts. -func (c bundleCmd) runManifestsLegacy() (err error) { +func (c bundleCmdLegacy) runManifests() (err error) { if !c.quiet { if c.version == "" { @@ -149,7 +168,7 @@ func (c bundleCmd) runManifestsLegacy() (err error) { // validateMetadataLegacy validates c for bundle metadata generation for // legacy project layouts. -func (c bundleCmd) validateMetadataLegacy() (err error) { +func (c bundleCmdLegacy) validateMetadata() (err error) { // Ensure a default channel is present. if c.defaultChannel == "" { return fmt.Errorf("--default-channel must be set if setting multiple channels") @@ -160,7 +179,7 @@ func (c bundleCmd) validateMetadataLegacy() (err error) { // runMetadataLegacy generates a bundle.Dockerfile and bundle metadata for // legacy project layouts. -func (c bundleCmd) runMetadataLegacy() error { +func (c bundleCmdLegacy) runMetadata() error { directory := c.inputDir if directory == "" { diff --git a/cmd/operator-sdk/generate/bundle/cmd.go b/cmd/operator-sdk/generate/bundle/cmd.go index 6733f806f5..ba18eb241b 100644 --- a/cmd/operator-sdk/generate/bundle/cmd.go +++ b/cmd/operator-sdk/generate/bundle/cmd.go @@ -16,6 +16,7 @@ package bundle import ( "fmt" + "path/filepath" log "github.com/sirupsen/logrus" "github.com/spf13/cobra" @@ -25,27 +26,9 @@ import ( "github.com/operator-framework/operator-sdk/internal/util/projutil" ) -const longHelp = ` - Running 'generate bundle' is the first step to publishing your operator to a catalog - and/or deploying it with OLM. This command generates a set of bundle manifests, - metadata, and a bundle.Dockerfile for your operator, and will interactively ask - for UI metadata, an important component of publishing your operator, by default unless - a bundle for your operator exists or you set '--interactive=false'. - - Set '--version' to supply a semantic version for your bundle if you are creating one - for the first time or upgrading an existing one. - - If '--output-dir' is set and you wish to build bundle images from that directory, - either manually update your bundle.Dockerfile or set '--overwrite'. - - More information on bundles: - https://github.com/operator-framework/operator-registry/#manifest-format -` - //nolint:maligned type bundleCmd struct { // Options to turn on different parts of bundling. - kustomize bool manifests bool metadata bool @@ -54,22 +37,27 @@ type bundleCmd struct { version string inputDir string outputDir string + kustomizeDir string deployDir string - apisDir string crdsDir string stdout bool quiet bool - // Interactive options. - interactiveLevel projutil.InteractiveLevel - interactive bool - // Metadata options. channels string defaultChannel string overwrite bool } +//nolint:maligned +type bundleCmdLegacy struct { + bundleCmd + + apisDir string + interactiveLevel projutil.InteractiveLevel + interactive bool +} + // NewCmd returns the 'bundle' command configured for the new project layout. func NewCmd() *cobra.Command { c := &bundleCmd{} @@ -83,22 +71,9 @@ func NewCmd() *cobra.Command { return fmt.Errorf("command %s doesn't accept any arguments", cmd.CommandPath()) } - // Check if the user has any specific preference to enable/disable - // interactive prompts. Default behaviour is to disable the prompt - // unless a base bundle does not exist. - if cmd.Flags().Changed("interactive") { - if c.interactive { - c.interactiveLevel = projutil.InteractiveOnAll - } else { - c.interactiveLevel = projutil.InteractiveHardOff - } - } - - // Generate kustomize bases, manifests, and metadata by default if no - // flags are set so the default behavior is "do everything". + // Generate manifests and metadata by default if no flags are set so the default behavior is "do everything". fs := cmd.Flags() - if !fs.Changed("kustomize") && !fs.Changed("metadata") && !fs.Changed("manifests") { - c.kustomize = true + if !fs.Changed("metadata") && !fs.Changed("manifests") { c.manifests = true c.metadata = true } @@ -123,11 +98,6 @@ func NewCmd() *cobra.Command { } // Run command logic. - if c.kustomize { - if err = c.runKustomize(cfg); err != nil { - log.Fatalf("Error generating bundle bases: %v", err) - } - } if c.manifests { if err = c.runManifests(cfg); err != nil { log.Fatalf("Error generating bundle manifests: %v", err) @@ -143,9 +113,8 @@ func NewCmd() *cobra.Command { }, } - cmd.Flags().BoolVar(&c.kustomize, "kustomize", false, "Generate kustomize bases") - cmd.Flags().BoolVar(&c.manifests, "manifests", false, "Generate bundle manifests") - cmd.Flags().BoolVar(&c.metadata, "metadata", false, "Generate bundle metadata and Dockerfile") + cmd.Flags().StringVar(&c.kustomizeDir, "kustomize-dir", filepath.Join("config", "manifests"), + "Directory containing kustomize bases and a kustomization.yaml") cmd.Flags().BoolVar(&c.stdout, "stdout", false, "Write bundle manifest to stdout") c.addCommonFlagsTo(cmd.Flags()) @@ -155,11 +124,11 @@ func NewCmd() *cobra.Command { // NewCmdLegacy returns the 'bundle' command configured for the legacy project layout. func NewCmdLegacy() *cobra.Command { - c := &bundleCmd{} + c := &bundleCmdLegacy{} cmd := &cobra.Command{ Use: "bundle", Short: "Generates bundle data for the operator", - Long: longHelp, + Long: longHelpLegacy, Example: examplesLegacy, RunE: func(cmd *cobra.Command, args []string) (err error) { if len(args) != 0 { @@ -185,29 +154,29 @@ func NewCmdLegacy() *cobra.Command { c.manifests = true } - c.setCommonDefaultsLegacy() + c.setCommonDefaults() // Validate command args before running so a preceding mode doesn't run // before a following validation fails. if c.manifests { - if err = c.validateManifestsLegacy(); err != nil { + if err = c.validateManifests(); err != nil { return fmt.Errorf("invalid command options: %v", err) } } if c.metadata { - if err = c.validateMetadataLegacy(); err != nil { + if err = c.validateMetadata(); err != nil { return fmt.Errorf("invalid command options: %v", err) } } // Run command logic. if c.manifests { - if err = c.runManifestsLegacy(); err != nil { + if err = c.runManifests(); err != nil { log.Fatalf("Error generating bundle manifests: %v", err) } } if c.metadata { - if err = c.runMetadataLegacy(); err != nil { + if err = c.runMetadata(); err != nil { log.Fatalf("Error generating bundle metadata: %v", err) } } @@ -216,8 +185,9 @@ func NewCmdLegacy() *cobra.Command { }, } - cmd.Flags().BoolVar(&c.manifests, "manifests", false, "Generate bundle manifests") - cmd.Flags().BoolVar(&c.metadata, "metadata", false, "Generate bundle metadata and Dockerfile") + cmd.Flags().StringVar(&c.apisDir, "apis-dir", "", "Root directory for API type defintions") + cmd.Flags().BoolVar(&c.interactive, "interactive", false, "When set or no bundle base exists, an interactive "+ + "command prompt will be presented to accept bundle ClusterServiceVersion metadata") c.addCommonFlagsTo(cmd.Flags()) @@ -226,6 +196,9 @@ func NewCmdLegacy() *cobra.Command { // TODO(estroz): add flag to skip API metadata regeneration. func (c *bundleCmd) addCommonFlagsTo(fs *pflag.FlagSet) { + fs.BoolVar(&c.manifests, "manifests", false, "Generate bundle manifests") + fs.BoolVar(&c.metadata, "metadata", false, "Generate bundle metadata and Dockerfile") + fs.StringVar(&c.operatorName, "operator-name", "", "Name of the bundle's operator") fs.StringVarP(&c.version, "version", "v", "", "Semantic version of the operator in the generated bundle. "+ "Only set if creating a new bundle or upgrading your operator") @@ -234,12 +207,9 @@ func (c *bundleCmd) addCommonFlagsTo(fs *pflag.FlagSet) { fs.StringVar(&c.outputDir, "output-dir", "", "Directory to write the bundle to") fs.StringVar(&c.deployDir, "deploy-dir", "", "Root directory for operator manifests such as "+ "Deployments and RBAC, ex. 'deploy'. This directory is different from that passed to --input-dir") - fs.StringVar(&c.apisDir, "apis-dir", "", "Root directory for API type defintions") fs.StringVar(&c.crdsDir, "crds-dir", "", "Root directory for CustomResoureDefinition manifests") fs.StringVar(&c.channels, "channels", "alpha", "A comma-separated list of channels the bundle belongs to") fs.StringVar(&c.defaultChannel, "default-channel", "", "The default channel for the bundle") fs.BoolVar(&c.overwrite, "overwrite", false, "Overwrite the bundle's metadata and Dockerfile if they exist") fs.BoolVarP(&c.quiet, "quiet", "q", false, "Run in quiet mode") - fs.BoolVar(&c.interactive, "interactive", false, "When set or no bundle base exists, an interactive "+ - "command prompt will be presented to accept bundle ClusterServiceVersion metadata") } diff --git a/cmd/operator-sdk/generate/packagemanifests/cmd.go b/cmd/operator-sdk/generate/packagemanifests/cmd.go index 1bf8fc4ab0..439d893bfe 100644 --- a/cmd/operator-sdk/generate/packagemanifests/cmd.go +++ b/cmd/operator-sdk/generate/packagemanifests/cmd.go @@ -16,6 +16,7 @@ package packagemanifests import ( "fmt" + "path/filepath" log "github.com/sirupsen/logrus" "github.com/spf13/cobra" @@ -25,58 +26,42 @@ import ( "github.com/operator-framework/operator-sdk/internal/util/projutil" ) -const longHelp = ` - Note: while the package manifests format is not yet deprecated, the operator-framework is migrated - towards using bundles by default. Run 'operator-sdk generate bundle -h' for more information. - - Running 'generate packagemanifests' is the first step to publishing your operator to a catalog - and/or deploying it with OLM. This command generates a set of manifests in a versioned directory - and a package manifest file for your operator. It will interactively ask for UI metadata, - an important component of publishing your operator, by default unless a package for your - operator exists or you set '--interactive=false'. - - Set '--version' to supply a semantic version for your new package. This is a required flag when running - 'generate packagemanifests --manifests'. - - More information on the package manifests format: - https://github.com/operator-framework/operator-registry/#manifest-format -` - //nolint:maligned type packagemanifestsCmd struct { - // Options to turn on different parts of packaging. - kustomize bool - manifests bool - // Common options. operatorName string version string fromVersion string inputDir string outputDir string + kustomizeDir string deployDir string - apisDir string crdsDir string updateCRDs bool stdout bool quiet bool - // Interactive options. - interactiveLevel projutil.InteractiveLevel - interactive bool - // Package manifest options. channelName string isDefaultChannel bool } +//nolint:maligned +type packagemanifestsCmdLegacy struct { + packagemanifestsCmd + + apisDir string + interactiveLevel projutil.InteractiveLevel + interactive bool +} + // NewCmd returns the 'packagemanifests' command configured for the new project layout. func NewCmd() *cobra.Command { c := &packagemanifestsCmd{} cmd := &cobra.Command{ Use: "packagemanifests", - Short: "Generates a package manifests format", + Short: "Generates package manifests data for the operator", Long: longHelp, Example: examples, RunE: func(cmd *cobra.Command, args []string) error { @@ -84,51 +69,25 @@ func NewCmd() *cobra.Command { return fmt.Errorf("command %s doesn't accept any arguments", cmd.CommandPath()) } - // Check if the user has any specific preference to enable/disable - // interactive prompts. Default behaviour is to disable the prompt - // unless a base package does not exist. - if cmd.Flags().Changed("interactive") { - if c.interactive { - c.interactiveLevel = projutil.InteractiveOnAll - } else { - c.interactiveLevel = projutil.InteractiveHardOff - } - } - - // Generate kustomize bases and manifests by default if no flags are set - // so the default behavior is "do everything". - fs := cmd.Flags() - if !fs.Changed("kustomize") && !fs.Changed("manifests") { - c.kustomize = true - c.manifests = true - } - cfg, err := kbutil.ReadConfig() if err != nil { log.Fatal(fmt.Errorf("error reading configuration: %v", err)) } - c.setCommonDefaults(cfg) + c.setDefaults(cfg) - if c.kustomize { - if err = c.runKustomize(cfg); err != nil { - log.Fatalf("Error generating package bases: %v", err) - } + if err = c.validate(); err != nil { + return fmt.Errorf("invalid command options: %v", err) } - if c.manifests { - if err = c.validateManifests(); err != nil { - return fmt.Errorf("invalid command options: %v", err) - } - if err = c.runManifests(cfg); err != nil { - log.Fatalf("Error generating package manifests: %v", err) - } + if err = c.run(cfg); err != nil { + log.Fatalf("Error generating package manifests: %v", err) } return nil }, } - cmd.Flags().BoolVar(&c.kustomize, "kustomize", false, "Generate kustomize bases") - cmd.Flags().BoolVar(&c.manifests, "manifests", false, "Generate package manifests") + cmd.Flags().StringVar(&c.kustomizeDir, "kustomize-dir", filepath.Join("config", "manifests"), + "Directory containing kustomize bases and a kustomization.yaml") cmd.Flags().BoolVar(&c.stdout, "stdout", false, "Write package to stdout") c.addCommonFlagsTo(cmd.Flags()) @@ -138,12 +97,12 @@ func NewCmd() *cobra.Command { // NewCmdLegacy returns the 'packagemanifests' command configured for the legacy project layout. func NewCmdLegacy() *cobra.Command { - c := &packagemanifestsCmd{} + c := &packagemanifestsCmdLegacy{} cmd := &cobra.Command{ Use: "packagemanifests", Short: "Generates a package manifests format", - Long: longHelp, + Long: longHelpLegacy, Example: examplesLegacy, RunE: func(cmd *cobra.Command, args []string) error { if len(args) != 0 { @@ -160,12 +119,12 @@ func NewCmdLegacy() *cobra.Command { } } - c.setCommonDefaultsLegacy() + c.setDefaults() - if err := c.validateManifestsLegacy(); err != nil { + if err := c.validate(); err != nil { return fmt.Errorf("invalid command options: %v", err) } - if err := c.runManifestsLegacy(); err != nil { + if err := c.run(); err != nil { log.Fatalf("Error generating package manifests: %v", err) } @@ -173,6 +132,10 @@ func NewCmdLegacy() *cobra.Command { }, } + cmd.Flags().StringVar(&c.apisDir, "apis-dir", "", "Root directory for API type defintions") + cmd.Flags().BoolVar(&c.interactive, "interactive", false, "When set or no package base exists, an interactive "+ + "command prompt will be presented to accept package ClusterServiceVersion metadata") + c.addCommonFlagsTo(cmd.Flags()) return cmd @@ -186,13 +149,10 @@ func (c *packagemanifestsCmd) addCommonFlagsTo(fs *pflag.FlagSet) { fs.StringVar(&c.outputDir, "output-dir", "", "Directory in which to write package manifests") fs.StringVar(&c.deployDir, "deploy-dir", "", "Root directory for operator manifests such as "+ "Deployments and RBAC, ex. 'deploy'. This directory is different from that passed to --input-dir") - fs.StringVar(&c.apisDir, "apis-dir", "", "Root directory for API type defintions") fs.StringVar(&c.crdsDir, "crds-dir", "", "Root directory for CustomResoureDefinition manifests") fs.StringVar(&c.channelName, "channel", "", "Channel name for the generated package") fs.BoolVar(&c.isDefaultChannel, "default-channel", false, "Use the channel passed to --channel "+ "as the package manifest file's default channel") fs.BoolVar(&c.updateCRDs, "update-crds", true, "Update CustomResoureDefinition manifests in this package") fs.BoolVarP(&c.quiet, "quiet", "q", false, "Run in quiet mode") - fs.BoolVar(&c.interactive, "interactive", false, "When set or no package base exists, an interactive "+ - "command prompt will be presented to accept package ClusterServiceVersion metadata") } diff --git a/cmd/operator-sdk/generate/packagemanifests/packagemanifests.go b/cmd/operator-sdk/generate/packagemanifests/packagemanifests.go index e283e9cbc1..625e5738d9 100644 --- a/cmd/operator-sdk/generate/packagemanifests/packagemanifests.go +++ b/cmd/operator-sdk/generate/packagemanifests/packagemanifests.go @@ -26,99 +26,77 @@ import ( gencsv "github.com/operator-framework/operator-sdk/internal/generate/clusterserviceversion" "github.com/operator-framework/operator-sdk/internal/generate/collector" genpkg "github.com/operator-framework/operator-sdk/internal/generate/packagemanifest" - "github.com/operator-framework/operator-sdk/internal/scaffold/kustomize" + "github.com/operator-framework/operator-sdk/internal/util/projutil" ) -//nolint:lll -const examples = ` +const ( + longHelp = ` +Note: while the package manifests format is not yet deprecated, the operator-framework is migrated +towards using bundles by default. Run 'operator-sdk generate bundle -h' for more information. + +Running 'generate packagemanifests' is the first step to publishing your operator to a catalog and/or deploying +it with OLM. This command generates a set of manifests in a versioned directory and a package manifest file for +your operator. Typically one would run 'generate kustomize manifests' first to (re)generate kustomize bases +consumed by this command. + +Set '--version' to supply a semantic version for your new package. This is a required flag when running +'generate packagemanifests --manifests'. + +More information on the package manifests format: +https://github.com/operator-framework/operator-registry/#manifest-format +` + + //nolint:lll + examples = ` # Generate manifests then create the package manifests base: $ make manifests /home/user/go/bin/controller-gen "crd:trivialVersions=true" rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases - $ operator-sdk generate packagemanifests -q --kustomize + $ operator-sdk generate kustomize manifests Display name for the operator (required): > memcached-operator ... - $ kustomize build config/packagemanifests | operator-sdk generate packagemanifests --manifests --version 0.0.1 + $ tree config/manifests + config/manifests + ├── bases + │   └── memcached-operator.clusterserviceversion.yaml + └── kustomization.yaml + $ kustomize build config/manifests | operator-sdk generate packagemanifests --manifests --version 0.0.1 Generating package manifests version 0.0.1 ... - # After running the above commands, you should see: - $ tree config/packages - config/packages - ├── bases - │   └── memcached-operator.clusterserviceversion.yaml - ├── kustomization.yaml + # After running the above commands, you should see this directory structure: + $ tree packagemanifests + packagemanifests ├── 0.0.1 │   ├── cache.my.domain_memcacheds.yaml │   └── memcached-operator.clusterserviceversion.yaml └── memcached-operator.package.yaml ` +) -// kustomization.yaml file contents for manifests. This should always be written to -// config/packagemanifests/kustomization.yaml since it only references files in config. -const manifestsKustomization = `resources: -- ../default -- ../samples -` - -var defaultDir = filepath.Join("config", "packagemanifests") +// defaultRootDir is the default root directory in which to generate package manifests files. +const defaultRootDir = "packagemanifests" -// setCommonDefaults sets defaults useful to all modes of this subcommand. -func (c *packagemanifestsCmd) setCommonDefaults(cfg *config.Config) { +// setDefaults sets command defaults. +func (c *packagemanifestsCmd) setDefaults(cfg *config.Config) { if c.operatorName == "" { c.operatorName = filepath.Base(cfg.Repo) } -} - -// runKustomize generates kustomize package bases. -func (c packagemanifestsCmd) runKustomize(cfg *config.Config) error { - - if !c.quiet { - fmt.Println("Generating package manifests kustomize bases") - } if c.inputDir == "" { - c.inputDir = defaultDir - } - if c.outputDir == "" { - c.outputDir = defaultDir + c.inputDir = defaultRootDir } - if c.apisDir == "" { - if cfg.MultiGroup { - c.apisDir = "apis" - } else { - c.apisDir = "api" + if !c.stdout { + if c.outputDir == "" { + c.outputDir = defaultRootDir } } - - csvGen := gencsv.Generator{ - OperatorName: c.operatorName, - OperatorType: genutil.PluginKeyToOperatorType(cfg.Layout), - } - opts := []gencsv.Option{ - gencsv.WithBase(c.inputDir, c.apisDir, c.interactiveLevel), - gencsv.WithBaseWriter(c.outputDir), - } - if err := csvGen.Generate(cfg, opts...); err != nil { - return fmt.Errorf("error generating ClusterServiceVersion: %v", err) - } - - // Write a kustomization.yaml to the config directory. - if err := kustomize.WriteIfNotExist(defaultDir, manifestsKustomization); err != nil { - return err - } - - if !c.quiet { - fmt.Println("Bases generated successfully in", c.outputDir) - } - - return nil } -// validateManifests validates c for package manifests generation. -func (c packagemanifestsCmd) validateManifests() error { +// validate validates c for package manifests generation. +func (c packagemanifestsCmd) validate() error { if c.version != "" { if err := genutil.ValidateVersion(c.version); err != nil { @@ -132,6 +110,13 @@ func (c packagemanifestsCmd) validateManifests() error { return errors.New("--from-version cannot be set for PROJECT-configured projects") } + if c.inputDir == "" { + return errors.New("--input-dir must be set") + } + if c.kustomizeDir == "" { + return errors.New("--kustomize-dir must be set") + } + if !genutil.IsPipeReader() { if c.deployDir == "" { return errors.New("--deploy-dir must be set if not reading from stdin") @@ -154,31 +139,13 @@ func (c packagemanifestsCmd) validateManifests() error { return nil } -// runManifests generates package manifests. -func (c packagemanifestsCmd) runManifests(cfg *config.Config) error { +// run generates package manifests. +func (c packagemanifestsCmd) run(cfg *config.Config) error { if !c.quiet && !c.stdout { fmt.Println("Generating package manifests version", c.version) } - if c.inputDir == "" { - c.inputDir = defaultDir - } - if !c.stdout { - if c.outputDir == "" { - c.outputDir = defaultDir - } - } - // Only regenerate API definitions once. - if c.apisDir == "" && !c.kustomize { - if cfg.MultiGroup { - c.apisDir = "apis" - } else { - c.apisDir = "api" - } - } - packageDir := filepath.Join(c.outputDir, c.version) - if err := c.generatePackageManifest(); err != nil { return err } @@ -204,7 +171,9 @@ func (c packagemanifestsCmd) runManifests(cfg *config.Config) error { stdout := genutil.NewMultiManifestWriter(os.Stdout) opts := []gencsv.Option{ - gencsv.WithBase(c.inputDir, c.apisDir, c.interactiveLevel), + // By not passing apisDir and turning interactive prompts on, we forcibly rely on the kustomize base + // for UI metadata and uninferrable data. + gencsv.WithBase(c.kustomizeDir, "", projutil.InteractiveHardOff), } if c.stdout { opts = append(opts, gencsv.WithWriter(stdout)) @@ -229,7 +198,8 @@ func (c packagemanifestsCmd) runManifests(cfg *config.Config) error { return err } } else { - if err := genutil.WriteObjectsToFiles(packageDir, objs...); err != nil { + dir := filepath.Join(c.outputDir, c.version) + if err := genutil.WriteObjectsToFiles(dir, objs...); err != nil { return err } } diff --git a/cmd/operator-sdk/generate/packagemanifests/packagemanifests_legacy.go b/cmd/operator-sdk/generate/packagemanifests/packagemanifests_legacy.go index 7e2d4d0b56..000afb3112 100644 --- a/cmd/operator-sdk/generate/packagemanifests/packagemanifests_legacy.go +++ b/cmd/operator-sdk/generate/packagemanifests/packagemanifests_legacy.go @@ -26,7 +26,25 @@ import ( "github.com/operator-framework/operator-sdk/internal/util/projutil" ) -const examplesLegacy = ` +const ( + longHelpLegacy = ` +Note: while the package manifests format is not yet deprecated, the operator-framework is migrated +towards using bundles by default. Run 'operator-sdk generate bundle -h' for more information. + +Running 'generate packagemanifests' is the first step to publishing your operator to a catalog +and/or deploying it with OLM. This command generates a set of manifests in a versioned directory +and a package manifest file for your operator. It will interactively ask for UI metadata, +an important component of publishing your operator, by default unless a package for your +operator exists or you set '--interactive=false'. + +Set '--version' to supply a semantic version for your new package. This is a required flag when running +'generate packagemanifests --manifests'. + +More information on the package manifests format: +https://github.com/operator-framework/operator-registry/#manifest-format +` + + examplesLegacy = ` # Create the package manifest file and a new package: $ operator-sdk generate packagemanifests --version 0.0.1 INFO[0000] Generating package manifests version 0.0.1 @@ -44,9 +62,10 @@ const examplesLegacy = ` │ └── memcached-operator.clusterserviceversion.yaml └── memacached-operator.package.yaml ` +) -// setCommonDefaultsLegacy sets defaults useful to all modes of this subcommand for legacy project layouts. -func (c *packagemanifestsCmd) setCommonDefaultsLegacy() { +// setDefaults sets defaults useful to all modes of this subcommand for legacy project layouts. +func (c *packagemanifestsCmdLegacy) setDefaults() { if c.operatorName == "" { c.operatorName = filepath.Base(projutil.MustGetwd()) } @@ -70,8 +89,8 @@ func (c *packagemanifestsCmd) setCommonDefaultsLegacy() { } } -// validateManifestsLegacy validates c for package manifests generation for legacy project layouts. -func (c packagemanifestsCmd) validateManifestsLegacy() error { +// validate validates c for package manifests generation for legacy project layouts. +func (c packagemanifestsCmdLegacy) validate() error { if err := genutil.ValidateVersion(c.version); err != nil { return err @@ -89,13 +108,12 @@ func (c packagemanifestsCmd) validateManifestsLegacy() error { return nil } -// runManifestsLegacy generates package manifests for legacy project layouts. -func (c packagemanifestsCmd) runManifestsLegacy() error { +// run generates package manifests for legacy project layouts. +func (c packagemanifestsCmdLegacy) run() error { if !c.quiet { log.Infoln("Generating package manifests version", c.version) } - packageDir := filepath.Join(c.outputDir, c.version) if err := c.generatePackageManifest(); err != nil { return err @@ -130,7 +148,8 @@ func (c packagemanifestsCmd) runManifestsLegacy() error { for _, crd := range col.V1beta1CustomResourceDefinitions { objs = append(objs, crd) } - if err := genutil.WriteObjectsToFilesLegacy(packageDir, objs...); err != nil { + dir := filepath.Join(c.outputDir, c.version) + if err := genutil.WriteObjectsToFilesLegacy(dir, objs...); err != nil { return err } } diff --git a/internal/plugins/golang/v2/init.go b/internal/plugins/golang/v2/init.go index b648cb00c4..69154f1a5b 100644 --- a/internal/plugins/golang/v2/init.go +++ b/internal/plugins/golang/v2/init.go @@ -95,9 +95,9 @@ BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL) makefileBundleFragment = ` # Generate bundle manifests and metadata, then validate generated files. bundle: manifests - operator-sdk generate bundle -q --kustomize - kustomize build config/bundle | operator-sdk generate bundle -q --manifests --metadata --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS) - operator-sdk bundle validate config/bundle + operator-sdk generate kustomize manifests -q + kustomize build config/manifests | operator-sdk generate bundle -q --manifests --metadata --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS) + operator-sdk bundle validate ./bundle ` makefileBundleBuildFragment = ` diff --git a/test/e2e-new/e2e_suite.go b/test/e2e-new/e2e_suite.go index 1ea95d63d7..8a63e8beac 100644 --- a/test/e2e-new/e2e_suite.go +++ b/test/e2e-new/e2e_suite.go @@ -149,10 +149,10 @@ var _ = Describe("operator-sdk", func() { By("generating the operator bundle") // Turn off interactive prompts for all generation tasks. - replace := "operator-sdk generate bundle" + replace := "operator-sdk generate kustomize manifests" replaceInFile(filepath.Join(tc.Dir, "Makefile"), replace, replace+" --interactive=false") err = tc.Make("bundle") - Expect(err).Should(Succeed()) + Expect(err).NotTo(HaveOccurred()) By("building the operator bundle image") // Use the existing image tag but with a "-bundle" suffix. @@ -162,26 +162,19 @@ var _ = Describe("operator-sdk", func() { bundleImage += ":" + imageSplit[1] } err = tc.Make("bundle-build", "BUNDLE_IMG="+bundleImage) - Expect(err).Should(Succeed()) + Expect(err).NotTo(HaveOccurred()) By("generating the operator package manifests") - var genPkgManCmd *exec.Cmd Expect(tc.Make("manifests")).Should(Succeed()) - genPkgManCmd = exec.Command(tc.BinaryName, "generate", "packagemanifests", - "--kustomize", - "--interactive=false") - _, err = tc.Run(genPkgManCmd) - Expect(err).Should(Succeed()) - kustomizeOutput, err := tc.Run(exec.Command("kustomize", "build", filepath.Join("config", "packagemanifests"))) - Expect(err).Should(Succeed()) - genPkgManCmd = exec.Command(tc.BinaryName, "generate", "packagemanifests", - "--manifests", - "--update-crds", - "--version", "0.0.1") - Expect(err).Should(Succeed()) + genKustomizeCmd := exec.Command(tc.BinaryName, "generate", "kustomize", "manifests") + _, err = tc.Run(genKustomizeCmd) + Expect(err).NotTo(HaveOccurred()) + kustomizeOutput, err := tc.Run(exec.Command("kustomize", "build", filepath.Join("config", "manifests"))) + Expect(err).NotTo(HaveOccurred()) + genPkgManCmd := exec.Command(tc.BinaryName, "generate", "packagemanifests", "--version", "0.0.1") tc.Stdin = bytes.NewBuffer(kustomizeOutput) _, err = tc.Run(genPkgManCmd) - Expect(err).Should(Succeed()) + Expect(err).NotTo(HaveOccurred()) }) }) }) diff --git a/website/content/en/docs/cli/operator-sdk_generate_bundle.md b/website/content/en/docs/cli/operator-sdk_generate_bundle.md index ddb423f2d7..a4a046c46c 100644 --- a/website/content/en/docs/cli/operator-sdk_generate_bundle.md +++ b/website/content/en/docs/cli/operator-sdk_generate_bundle.md @@ -8,20 +8,20 @@ Generates bundle data for the operator ### Synopsis - Running 'generate bundle' is the first step to publishing your operator to a catalog - and/or deploying it with OLM. This command generates a set of bundle manifests, - metadata, and a bundle.Dockerfile for your operator, and will interactively ask - for UI metadata, an important component of publishing your operator, by default unless - a bundle for your operator exists or you set '--interactive=false'. +Running 'generate bundle' is the first step to publishing your operator to a catalog +and/or deploying it with OLM. This command generates a set of bundle manifests, +metadata, and a bundle.Dockerfile for your operator, and will interactively ask +for UI metadata, an important component of publishing your operator, by default unless +a bundle for your operator exists or you set '--interactive=false'. - Set '--version' to supply a semantic version for your bundle if you are creating one - for the first time or upgrading an existing one. +Set '--version' to supply a semantic version for your bundle if you are creating one +for the first time or upgrading an existing one. - If '--output-dir' is set and you wish to build bundle images from that directory, - either manually update your bundle.Dockerfile or set '--overwrite'. +If '--output-dir' is set and you wish to build bundle images from that directory, +either manually update your bundle.Dockerfile or set '--overwrite'. - More information on bundles: - https://github.com/operator-framework/operator-registry/#manifest-format +More information on bundles: +https://github.com/operator-framework/operator-registry/#manifest-format ``` diff --git a/website/content/en/docs/cli/operator-sdk_generate_packagemanifests.md b/website/content/en/docs/cli/operator-sdk_generate_packagemanifests.md index da13808383..6ff7e82298 100644 --- a/website/content/en/docs/cli/operator-sdk_generate_packagemanifests.md +++ b/website/content/en/docs/cli/operator-sdk_generate_packagemanifests.md @@ -8,20 +8,20 @@ Generates a package manifests format ### Synopsis - Note: while the package manifests format is not yet deprecated, the operator-framework is migrated - towards using bundles by default. Run 'operator-sdk generate bundle -h' for more information. +Note: while the package manifests format is not yet deprecated, the operator-framework is migrated +towards using bundles by default. Run 'operator-sdk generate bundle -h' for more information. - Running 'generate packagemanifests' is the first step to publishing your operator to a catalog - and/or deploying it with OLM. This command generates a set of manifests in a versioned directory - and a package manifest file for your operator. It will interactively ask for UI metadata, - an important component of publishing your operator, by default unless a package for your - operator exists or you set '--interactive=false'. +Running 'generate packagemanifests' is the first step to publishing your operator to a catalog +and/or deploying it with OLM. This command generates a set of manifests in a versioned directory +and a package manifest file for your operator. It will interactively ask for UI metadata, +an important component of publishing your operator, by default unless a package for your +operator exists or you set '--interactive=false'. - Set '--version' to supply a semantic version for your new package. This is a required flag when running - 'generate packagemanifests --manifests'. +Set '--version' to supply a semantic version for your new package. This is a required flag when running +'generate packagemanifests --manifests'. - More information on the package manifests format: - https://github.com/operator-framework/operator-registry/#manifest-format +More information on the package manifests format: +https://github.com/operator-framework/operator-registry/#manifest-format ``` diff --git a/website/content/en/docs/new-cli/operator-sdk_generate.md b/website/content/en/docs/new-cli/operator-sdk_generate.md index 9e316c0695..c54e6a1cad 100644 --- a/website/content/en/docs/new-cli/operator-sdk_generate.md +++ b/website/content/en/docs/new-cli/operator-sdk_generate.md @@ -27,5 +27,5 @@ code or manifests. * [operator-sdk](../operator-sdk) - Development kit for building Kubernetes extensions and tools. * [operator-sdk generate bundle](../operator-sdk_generate_bundle) - Generates bundle data for the operator * [operator-sdk generate kustomize](../operator-sdk_generate_kustomize) - Contains subcommands that generate operator-framework kustomize data for the operator -* [operator-sdk generate packagemanifests](../operator-sdk_generate_packagemanifests) - Generates a package manifests format +* [operator-sdk generate packagemanifests](../operator-sdk_generate_packagemanifests) - Generates package manifests data for the operator diff --git a/website/content/en/docs/new-cli/operator-sdk_generate_bundle.md b/website/content/en/docs/new-cli/operator-sdk_generate_bundle.md index 9d1ee3256c..49540de0ec 100644 --- a/website/content/en/docs/new-cli/operator-sdk_generate_bundle.md +++ b/website/content/en/docs/new-cli/operator-sdk_generate_bundle.md @@ -8,20 +8,18 @@ Generates bundle data for the operator ### Synopsis - Running 'generate bundle' is the first step to publishing your operator to a catalog - and/or deploying it with OLM. This command generates a set of bundle manifests, - metadata, and a bundle.Dockerfile for your operator, and will interactively ask - for UI metadata, an important component of publishing your operator, by default unless - a bundle for your operator exists or you set '--interactive=false'. +Running 'generate bundle' is the first step to publishing your operator to a catalog and/or deploying it with OLM. +This command generates a set of bundle manifests, metadata, and a bundle.Dockerfile for your operator. +Typically one would run 'generate kustomize manifests' first to (re)generate kustomize bases consumed by this command. - Set '--version' to supply a semantic version for your bundle if you are creating one - for the first time or upgrading an existing one. +Set '--version' to supply a semantic version for your bundle if you are creating one +for the first time or upgrading an existing one. - If '--output-dir' is set and you wish to build bundle images from that directory, - either manually update your bundle.Dockerfile or set '--overwrite'. +If '--output-dir' is set and you wish to build bundle images from that directory, +either manually update your bundle.Dockerfile or set '--overwrite'. - More information on bundles: - https://github.com/operator-framework/operator-registry/#manifest-format +More information on bundles: +https://github.com/operator-framework/operator-registry/#manifest-format ``` @@ -42,22 +40,24 @@ operator-sdk generate bundle [flags] # manifests, metadata, and a bundle.Dockerfile: $ make manifests /home/user/go/bin/controller-gen "crd:trivialVersions=true" rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases - $ operator-sdk generate bundle -q --kustomize + $ operator-sdk generate kustomize manifests Display name for the operator (required): > memcached-operator ... - $ kustomize build config/bundle | operator-sdk generate bundle --manifests --metadata --overwrite --version 0.0.1 + $ tree config/manifests + config/manifests + ├── bases + │   └── memcached-operator.clusterserviceversion.yaml + └── kustomization.yaml + $ kustomize build config/manifests | operator-sdk generate bundle --manifests --metadata --overwrite --version 0.0.1 Generating bundle manifest version 0.0.1 ... - # After running the above commands, you should see: - $ tree config/bundle - config/bundle - ├── bases - │   └── memcached-operator.clusterserviceversion.yaml - ├── kustomization.yaml + # After running the above commands, you should see this directory structure: + $ tree bundle + bundle ├── manifests │   ├── cache.my.domain_memcacheds.yaml │   └── memcached-operator.clusterserviceversion.yaml @@ -65,7 +65,7 @@ operator-sdk generate bundle [flags] └── annotations.yaml # Then it validates your bundle files and builds your bundle image: - $ operator-sdk bundle validate config/bundle + $ operator-sdk bundle validate ./bundle $ docker build -f bundle.Dockerfile -t $BUNDLE_IMG . Sending build context to Docker daemon 42.33MB Step 1/9 : FROM scratch @@ -79,15 +79,13 @@ operator-sdk generate bundle [flags] ### Options ``` - --apis-dir string Root directory for API type defintions --channels string A comma-separated list of channels the bundle belongs to (default "alpha") --crds-dir string Root directory for CustomResoureDefinition manifests --default-channel string The default channel for the bundle --deploy-dir string Root directory for operator manifests such as Deployments and RBAC, ex. 'deploy'. This directory is different from that passed to --input-dir -h, --help help for bundle --input-dir string Directory to read an existing bundle from. This directory is the parent of your bundle 'manifests' directory, and different from --deploy-dir - --interactive When set or no bundle base exists, an interactive command prompt will be presented to accept bundle ClusterServiceVersion metadata - --kustomize Generate kustomize bases + --kustomize-dir string Directory containing kustomize bases and a kustomization.yaml (default "config/manifests") --manifests Generate bundle manifests --metadata Generate bundle metadata and Dockerfile --operator-name string Name of the bundle's operator diff --git a/website/content/en/docs/new-cli/operator-sdk_generate_packagemanifests.md b/website/content/en/docs/new-cli/operator-sdk_generate_packagemanifests.md index 4680dfa5cc..e6792b89f1 100644 --- a/website/content/en/docs/new-cli/operator-sdk_generate_packagemanifests.md +++ b/website/content/en/docs/new-cli/operator-sdk_generate_packagemanifests.md @@ -3,25 +3,24 @@ title: "operator-sdk generate packagemanifests" --- ## operator-sdk generate packagemanifests -Generates a package manifests format +Generates package manifests data for the operator ### Synopsis - Note: while the package manifests format is not yet deprecated, the operator-framework is migrated - towards using bundles by default. Run 'operator-sdk generate bundle -h' for more information. +Note: while the package manifests format is not yet deprecated, the operator-framework is migrated +towards using bundles by default. Run 'operator-sdk generate bundle -h' for more information. - Running 'generate packagemanifests' is the first step to publishing your operator to a catalog - and/or deploying it with OLM. This command generates a set of manifests in a versioned directory - and a package manifest file for your operator. It will interactively ask for UI metadata, - an important component of publishing your operator, by default unless a package for your - operator exists or you set '--interactive=false'. +Running 'generate packagemanifests' is the first step to publishing your operator to a catalog and/or deploying +it with OLM. This command generates a set of manifests in a versioned directory and a package manifest file for +your operator. Typically one would run 'generate kustomize manifests' first to (re)generate kustomize bases +consumed by this command. - Set '--version' to supply a semantic version for your new package. This is a required flag when running - 'generate packagemanifests --manifests'. +Set '--version' to supply a semantic version for your new package. This is a required flag when running +'generate packagemanifests --manifests'. - More information on the package manifests format: - https://github.com/operator-framework/operator-registry/#manifest-format +More information on the package manifests format: +https://github.com/operator-framework/operator-registry/#manifest-format ``` @@ -35,22 +34,24 @@ operator-sdk generate packagemanifests [flags] # Generate manifests then create the package manifests base: $ make manifests /home/user/go/bin/controller-gen "crd:trivialVersions=true" rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases - $ operator-sdk generate packagemanifests -q --kustomize + $ operator-sdk generate kustomize manifests Display name for the operator (required): > memcached-operator ... - $ kustomize build config/packagemanifests | operator-sdk generate packagemanifests --manifests --version 0.0.1 + $ tree config/manifests + config/manifests + ├── bases + │   └── memcached-operator.clusterserviceversion.yaml + └── kustomization.yaml + $ kustomize build config/manifests | operator-sdk generate packagemanifests --manifests --version 0.0.1 Generating package manifests version 0.0.1 ... - # After running the above commands, you should see: - $ tree config/packages - config/packages - ├── bases - │   └── memcached-operator.clusterserviceversion.yaml - ├── kustomization.yaml + # After running the above commands, you should see this directory structure: + $ tree packagemanifests + packagemanifests ├── 0.0.1 │   ├── cache.my.domain_memcacheds.yaml │   └── memcached-operator.clusterserviceversion.yaml @@ -61,16 +62,13 @@ operator-sdk generate packagemanifests [flags] ### Options ``` - --apis-dir string Root directory for API type defintions --channel string Channel name for the generated package --crds-dir string Root directory for CustomResoureDefinition manifests --default-channel Use the channel passed to --channel as the package manifest file's default channel --deploy-dir string Root directory for operator manifests such as Deployments and RBAC, ex. 'deploy'. This directory is different from that passed to --input-dir -h, --help help for packagemanifests --input-dir string Directory to read existing package manifests from. This directory is the parent of individual versioned package directories, and different from --deploy-dir - --interactive When set or no package base exists, an interactive command prompt will be presented to accept package ClusterServiceVersion metadata - --kustomize Generate kustomize bases - --manifests Generate package manifests + --kustomize-dir string Directory containing kustomize bases and a kustomization.yaml (default "config/manifests") --operator-name string Name of the packaged operator --output-dir string Directory in which to write package manifests -q, --quiet Run in quiet mode From fd0fa161133fba36f897653d74ee7ed5a847799b Mon Sep 17 00:00:00 2001 From: Eric Stroczynski Date: Thu, 18 Jun 2020 23:05:17 -0700 Subject: [PATCH 2/2] address PR comments --- changelog/fragments/rename-generate-defaults.yaml | 14 -------------- cmd/operator-sdk/generate/bundle/bundle.go | 2 +- cmd/operator-sdk/generate/bundle/cmd.go | 2 +- cmd/operator-sdk/generate/packagemanifests/cmd.go | 2 +- internal/plugins/golang/v2/init.go | 2 +- .../docs/new-cli/operator-sdk_generate_bundle.md | 4 ++-- .../operator-sdk_generate_packagemanifests.md | 2 +- 7 files changed, 7 insertions(+), 21 deletions(-) delete mode 100644 changelog/fragments/rename-generate-defaults.yaml diff --git a/changelog/fragments/rename-generate-defaults.yaml b/changelog/fragments/rename-generate-defaults.yaml deleted file mode 100644 index 151d49a547..0000000000 --- a/changelog/fragments/rename-generate-defaults.yaml +++ /dev/null @@ -1,14 +0,0 @@ -entries: - - description: > - `generate ` will no longer write kustomize manifests bases and kustomization.yaml; - instead, `generate kustomize manifests` will do so - kind: change - - description: > - `--kustomize` has been removed from `generate `. Use `generate kustomize manifests` - to write manifests bases and kustomization.yaml instead - kind: removal - - description: > - `bundle` will write manifests/metadata to the top-level `bundle/` directory, - and `packagemanifests` will write manifests and the package manifest to - the top-level `packagemanifests/` directory - kind: change diff --git a/cmd/operator-sdk/generate/bundle/bundle.go b/cmd/operator-sdk/generate/bundle/bundle.go index 8f25e6bb2e..d533184e81 100644 --- a/cmd/operator-sdk/generate/bundle/bundle.go +++ b/cmd/operator-sdk/generate/bundle/bundle.go @@ -69,7 +69,7 @@ https://github.com/operator-framework/operator-registry/#manifest-format ├── bases │   └── memcached-operator.clusterserviceversion.yaml └── kustomization.yaml - $ kustomize build config/manifests | operator-sdk generate bundle --manifests --metadata --overwrite --version 0.0.1 + $ kustomize build config/manifests | operator-sdk generate bundle --overwrite --version 0.0.1 Generating bundle manifest version 0.0.1 ... diff --git a/cmd/operator-sdk/generate/bundle/cmd.go b/cmd/operator-sdk/generate/bundle/cmd.go index ba18eb241b..66dbe0a603 100644 --- a/cmd/operator-sdk/generate/bundle/cmd.go +++ b/cmd/operator-sdk/generate/bundle/cmd.go @@ -114,7 +114,7 @@ func NewCmd() *cobra.Command { } cmd.Flags().StringVar(&c.kustomizeDir, "kustomize-dir", filepath.Join("config", "manifests"), - "Directory containing kustomize bases and a kustomization.yaml") + "Directory containing kustomize bases and a kustomization.yaml for operator-framework manifests") cmd.Flags().BoolVar(&c.stdout, "stdout", false, "Write bundle manifest to stdout") c.addCommonFlagsTo(cmd.Flags()) diff --git a/cmd/operator-sdk/generate/packagemanifests/cmd.go b/cmd/operator-sdk/generate/packagemanifests/cmd.go index 439d893bfe..83fb5d515a 100644 --- a/cmd/operator-sdk/generate/packagemanifests/cmd.go +++ b/cmd/operator-sdk/generate/packagemanifests/cmd.go @@ -87,7 +87,7 @@ func NewCmd() *cobra.Command { } cmd.Flags().StringVar(&c.kustomizeDir, "kustomize-dir", filepath.Join("config", "manifests"), - "Directory containing kustomize bases and a kustomization.yaml") + "Directory containing kustomize bases and a kustomization.yaml for operator-framework manifests") cmd.Flags().BoolVar(&c.stdout, "stdout", false, "Write package to stdout") c.addCommonFlagsTo(cmd.Flags()) diff --git a/internal/plugins/golang/v2/init.go b/internal/plugins/golang/v2/init.go index 69154f1a5b..89055e053f 100644 --- a/internal/plugins/golang/v2/init.go +++ b/internal/plugins/golang/v2/init.go @@ -96,7 +96,7 @@ BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL) # Generate bundle manifests and metadata, then validate generated files. bundle: manifests operator-sdk generate kustomize manifests -q - kustomize build config/manifests | operator-sdk generate bundle -q --manifests --metadata --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS) + kustomize build config/manifests | operator-sdk generate bundle -q --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS) operator-sdk bundle validate ./bundle ` diff --git a/website/content/en/docs/new-cli/operator-sdk_generate_bundle.md b/website/content/en/docs/new-cli/operator-sdk_generate_bundle.md index 49540de0ec..d641690b3e 100644 --- a/website/content/en/docs/new-cli/operator-sdk_generate_bundle.md +++ b/website/content/en/docs/new-cli/operator-sdk_generate_bundle.md @@ -51,7 +51,7 @@ operator-sdk generate bundle [flags] ├── bases │   └── memcached-operator.clusterserviceversion.yaml └── kustomization.yaml - $ kustomize build config/manifests | operator-sdk generate bundle --manifests --metadata --overwrite --version 0.0.1 + $ kustomize build config/manifests | operator-sdk generate bundle --overwrite --version 0.0.1 Generating bundle manifest version 0.0.1 ... @@ -85,7 +85,7 @@ operator-sdk generate bundle [flags] --deploy-dir string Root directory for operator manifests such as Deployments and RBAC, ex. 'deploy'. This directory is different from that passed to --input-dir -h, --help help for bundle --input-dir string Directory to read an existing bundle from. This directory is the parent of your bundle 'manifests' directory, and different from --deploy-dir - --kustomize-dir string Directory containing kustomize bases and a kustomization.yaml (default "config/manifests") + --kustomize-dir string Directory containing kustomize bases and a kustomization.yaml for operator-framework manifests (default "config/manifests") --manifests Generate bundle manifests --metadata Generate bundle metadata and Dockerfile --operator-name string Name of the bundle's operator diff --git a/website/content/en/docs/new-cli/operator-sdk_generate_packagemanifests.md b/website/content/en/docs/new-cli/operator-sdk_generate_packagemanifests.md index e6792b89f1..d916bce984 100644 --- a/website/content/en/docs/new-cli/operator-sdk_generate_packagemanifests.md +++ b/website/content/en/docs/new-cli/operator-sdk_generate_packagemanifests.md @@ -68,7 +68,7 @@ operator-sdk generate packagemanifests [flags] --deploy-dir string Root directory for operator manifests such as Deployments and RBAC, ex. 'deploy'. This directory is different from that passed to --input-dir -h, --help help for packagemanifests --input-dir string Directory to read existing package manifests from. This directory is the parent of individual versioned package directories, and different from --deploy-dir - --kustomize-dir string Directory containing kustomize bases and a kustomization.yaml (default "config/manifests") + --kustomize-dir string Directory containing kustomize bases and a kustomization.yaml for operator-framework manifests (default "config/manifests") --operator-name string Name of the packaged operator --output-dir string Directory in which to write package manifests -q, --quiet Run in quiet mode