Skip to content

Commit a48569c

Browse files
author
Eric Stroczynski
authored
[v0.19.x] cmd/operator-sdk/generate/packagemanifests: add --from-version flag (#3509) (#3524)
1 parent 8852ca0 commit a48569c

File tree

7 files changed

+18
-5
lines changed

7 files changed

+18
-5
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
entries:
2+
- description: >
3+
Added the `--from-version` flag to `generate packagemanifests`.
4+
kind: addition

cmd/operator-sdk/generate/internal/genutil.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func ValidateVersion(version string) error {
4040
// Ensures numerical values composing csvVersion don't contain leading 0's,
4141
// ex. 01.01.01
4242
if v.String() != version {
43-
return fmt.Errorf("provided CSV version %s contains bad values (parses to %s)", version, v)
43+
return fmt.Errorf("version %s contains bad values (parses to %s)", version, v)
4444
}
4545
return nil
4646
}

cmd/operator-sdk/generate/packagemanifests/cmd.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ func NewCmdLegacy() *cobra.Command {
144144
func (c *packagemanifestsCmd) addCommonFlagsTo(fs *pflag.FlagSet) {
145145
fs.StringVar(&c.operatorName, "operator-name", "", "Name of the packaged operator")
146146
fs.StringVarP(&c.version, "version", "v", "", "Semantic version of the packaged operator")
147+
fs.StringVar(&c.fromVersion, "from-version", "", "Semantic version of the operator being upgraded from")
147148
fs.StringVar(&c.inputDir, "input-dir", "", "Directory to read existing package manifests from. "+
148149
"This directory is the parent of individual versioned package directories, and different from --deploy-dir")
149150
fs.StringVar(&c.outputDir, "output-dir", "", "Directory in which to write package manifests")

cmd/operator-sdk/generate/packagemanifests/packagemanifests.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,9 @@ func (c packagemanifestsCmd) validate() error {
106106
}
107107

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

112114
if c.inputDir == "" {
@@ -165,6 +167,7 @@ func (c packagemanifestsCmd) run(cfg *config.Config) error {
165167
OperatorName: c.operatorName,
166168
OperatorType: genutil.PluginKeyToOperatorType(cfg.Layout),
167169
Version: c.version,
170+
FromVersion: c.fromVersion,
168171
Collector: col,
169172
}
170173

website/content/en/docs/cli/operator-sdk_generate_packagemanifests.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ operator-sdk generate packagemanifests [flags]
5959
--crds-dir string Root directory for CustomResoureDefinition manifests
6060
--default-channel Use the channel passed to --channel as the package manifest file's default channel
6161
--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
62+
--from-version string Semantic version of the operator being upgraded from
6263
-h, --help help for packagemanifests
6364
--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
6465
--interactive When set or no package base exists, an interactive command prompt will be presented to accept package ClusterServiceVersion metadata

website/content/en/docs/new-cli/operator-sdk_generate_packagemanifests.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ operator-sdk generate packagemanifests [flags]
6666
--crds-dir string Root directory for CustomResoureDefinition manifests
6767
--default-channel Use the channel passed to --channel as the package manifest file's default channel
6868
--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
69+
--from-version string Semantic version of the operator being upgraded from
6970
-h, --help help for packagemanifests
7071
--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
7172
--kustomize-dir string Directory containing kustomize bases and a kustomization.yaml for operator-framework manifests (default "config/manifests")

website/content/en/docs/olm-integration/generating-a-csv.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,16 @@ you should add the following to your `Makefile` to make development easier:
125125

126126
```make
127127
# Options for "packagemanifests".
128+
ifneq ($(origin FROM_VERSION), undefined)
129+
PKG_FROM_VERSION := --from-version=$(FROM_VERSION)
130+
endif
128131
ifneq ($(origin CHANNEL), undefined)
129132
PKG_CHANNELS := --channel=$(CHANNEL)
130133
endif
131134
ifeq ($(IS_CHANNEL_DEFAULT), 1)
132135
PKG_IS_DEFAULT_CHANNEL := --default-channel
133136
endif
134-
PKG_MAN_OPTS ?= $(PKG_CHANNELS) $(PKG_IS_DEFAULT_CHANNEL)
137+
PKG_MAN_OPTS ?= $(FROM_VERSION) $(PKG_CHANNELS) $(PKG_IS_DEFAULT_CHANNEL)
135138

136139
# Generate package manifests.
137140
packagemanifests: manifests
@@ -187,11 +190,11 @@ $ make bundle CHANNELS=beta DEFAULT_CHANNEL=beta
187190
If using a package manifests format, run:
188191

189192
```console
190-
$ make packagemanifests CHANNEL=beta IS_CHANNEL_DEFAULT=1
193+
$ make packagemanifests FROM_VERSION=0.0.1 CHANNEL=beta IS_CHANNEL_DEFAULT=1
191194
```
192195

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

196199
## CSV fields
197200

0 commit comments

Comments
 (0)