Skip to content

Commit

Permalink
[v0.19.x] cmd/operator-sdk/generate/packagemanifests: add `--from-ver…
Browse files Browse the repository at this point in the history
…sion` flag (#3509) (#3524)
  • Loading branch information
Eric Stroczynski committed Jul 24, 2020
1 parent 8852ca0 commit a48569c
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 5 deletions.
4 changes: 4 additions & 0 deletions changelog/fragments/packagemanifests-from-version.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
entries:
- description: >
Added the `--from-version` flag to `generate packagemanifests`.
kind: addition
2 changes: 1 addition & 1 deletion cmd/operator-sdk/generate/internal/genutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func ValidateVersion(version string) error {
// Ensures numerical values composing csvVersion don't contain leading 0's,
// ex. 01.01.01
if v.String() != version {
return fmt.Errorf("provided CSV version %s contains bad values (parses to %s)", version, v)
return fmt.Errorf("version %s contains bad values (parses to %s)", version, v)
}
return nil
}
Expand Down
1 change: 1 addition & 0 deletions cmd/operator-sdk/generate/packagemanifests/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ func NewCmdLegacy() *cobra.Command {
func (c *packagemanifestsCmd) addCommonFlagsTo(fs *pflag.FlagSet) {
fs.StringVar(&c.operatorName, "operator-name", "", "Name of the packaged operator")
fs.StringVarP(&c.version, "version", "v", "", "Semantic version of the packaged operator")
fs.StringVar(&c.fromVersion, "from-version", "", "Semantic version of the operator being upgraded from")
fs.StringVar(&c.inputDir, "input-dir", "", "Directory to read existing package manifests from. "+
"This directory is the parent of individual versioned package directories, and different from --deploy-dir")
fs.StringVar(&c.outputDir, "output-dir", "", "Directory in which to write package manifests")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ func (c packagemanifestsCmd) validate() error {
}

if c.fromVersion != "" {
return errors.New("--from-version cannot be set for PROJECT-configured projects")
if err := genutil.ValidateVersion(c.fromVersion); err != nil {
return err
}
}

if c.inputDir == "" {
Expand Down Expand Up @@ -165,6 +167,7 @@ func (c packagemanifestsCmd) run(cfg *config.Config) error {
OperatorName: c.operatorName,
OperatorType: genutil.PluginKeyToOperatorType(cfg.Layout),
Version: c.version,
FromVersion: c.fromVersion,
Collector: col,
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ operator-sdk generate packagemanifests [flags]
--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
--from-version string Semantic version of the operator being upgraded from
-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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ operator-sdk generate packagemanifests [flags]
--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
--from-version string Semantic version of the operator being upgraded from
-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 for operator-framework manifests (default "config/manifests")
Expand Down
9 changes: 6 additions & 3 deletions website/content/en/docs/olm-integration/generating-a-csv.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,16 @@ you should add the following to your `Makefile` to make development easier:

```make
# Options for "packagemanifests".
ifneq ($(origin FROM_VERSION), undefined)
PKG_FROM_VERSION := --from-version=$(FROM_VERSION)
endif
ifneq ($(origin CHANNEL), undefined)
PKG_CHANNELS := --channel=$(CHANNEL)
endif
ifeq ($(IS_CHANNEL_DEFAULT), 1)
PKG_IS_DEFAULT_CHANNEL := --default-channel
endif
PKG_MAN_OPTS ?= $(PKG_CHANNELS) $(PKG_IS_DEFAULT_CHANNEL)
PKG_MAN_OPTS ?= $(FROM_VERSION) $(PKG_CHANNELS) $(PKG_IS_DEFAULT_CHANNEL)

# Generate package manifests.
packagemanifests: manifests
Expand Down Expand Up @@ -187,11 +190,11 @@ $ make bundle CHANNELS=beta DEFAULT_CHANNEL=beta
If using a package manifests format, run:

```console
$ make packagemanifests CHANNEL=beta IS_CHANNEL_DEFAULT=1
$ make packagemanifests FROM_VERSION=0.0.1 CHANNEL=beta IS_CHANNEL_DEFAULT=1
```

Running the command for either format will persist user-defined fields, updates `spec.version`,
and populates `spec.replaces` with the old CSV versions' name.
and populates `spec.replaces` with the old CSV version's name.

## CSV fields

Expand Down

0 comments on commit a48569c

Please sign in to comment.