Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CSV versioning #1016

Merged
merged 46 commits into from
Feb 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
821bac7
* pkg/scaffold/olm-catalog/csv*.go: use afero Fs in CSV generation
estroz Jan 24, 2019
6a5567d
Merge branch 'master' into inject-fs
estroz Jan 25, 2019
70162b3
pkg/.../csv.go: getFS instead of naked field ref
estroz Jan 25, 2019
5632f73
internal/.../file_util.go: {NewFileWriter,Get}(FS)? instead of naked …
estroz Jan 25, 2019
977cb29
Merge branch 'master' into inject-fs
estroz Jan 28, 2019
e8c94c4
* pkg/scaffold/olm-catalog/*: add project name and version to CSV and…
estroz Jan 28, 2019
a1c57f7
initFS in getFS
estroz Jan 29, 2019
70cbb26
remove os.Stat and check IfNotExists after reading file
estroz Jan 29, 2019
6fc2b53
Merge branch 'inject-fs' into csv-versioning
estroz Jan 29, 2019
6dfbaef
use initFS where appropriate
estroz Jan 29, 2019
7570d2c
Merge branch 'master' into csv-versioning
estroz Jan 31, 2019
6181606
update scorecard config file with new CSV path
estroz Feb 1, 2019
99551ed
Merge branch 'master' into csv-versioning
estroz Feb 1, 2019
244696b
Merge branch 'master' into csv-versioning
estroz Feb 1, 2019
b96b3d3
Merge branch 'master' into csv-versioning
estroz Feb 4, 2019
2108b24
Merge branch 'master' into csv-versioning
estroz Feb 6, 2019
efd857e
commands/.../olm-catalog/gen-csv.go: add update-crds and crds-dir flags
estroz Feb 7, 2019
46a72f4
commands/.../scorecard/olm_tests.go: move getCRDs to k8sutil
estroz Feb 7, 2019
198b6f8
commands/.../generate/openapi.go: use k8sutil.GetCRDs instead of spli…
estroz Feb 7, 2019
5a1ff24
remove ConcatCRD
estroz Feb 7, 2019
43d8355
write CRD to correct path
estroz Feb 7, 2019
52462f5
use non-nil CRD
estroz Feb 7, 2019
c84537c
use non-nil CRD
estroz Feb 7, 2019
ea820d5
append full path in GetCRDManifestPaths
estroz Feb 7, 2019
1fd4287
Merge branch 'move-getcrds' into csv-versioning
estroz Feb 7, 2019
efa276d
update sdk-cli-ref with new flags and output, revert scorecard-subcom…
estroz Feb 7, 2019
72d7f18
Merge branch 'master' into csv-versioning
estroz Feb 8, 2019
e60881a
internal/util/fileutil/file_util.go: remove unused NewFileWriter()
estroz Feb 9, 2019
b5e8069
Merge branch 'afero-scaffold' into csv-versioning
estroz Feb 9, 2019
fc1ba5b
remove unnecessary comments
estroz Feb 12, 2019
90be5cc
pkg/scaffold/*: set afero.Fs field on a CustomRenderer if one exists
estroz Feb 12, 2019
838ef94
Merge branch 'afero-scaffold' into csv-versioning
estroz Feb 12, 2019
8f3a4e2
Merge branch 'master' into afero-scaffold
estroz Feb 12, 2019
9ab0062
Merge branch 'master' into csv-versioning
estroz Feb 12, 2019
c6467b8
pkg/scaffold/anisble/k8s_status.go: impl SetFS on K8sStatus
estroz Feb 12, 2019
c58a4b2
use scaffold's Fs in CSV unit tests
estroz Feb 12, 2019
d8b5d04
remove k8s_status template
estroz Feb 12, 2019
4881297
Merge branch 'afero-scaffold' into csv-versioning
estroz Feb 12, 2019
54f90e5
Merge branch 'master' into csv-versioning
estroz Feb 13, 2019
15cf07f
Merge branch 'master' into csv-versioning
estroz Feb 13, 2019
c8b016c
Update doc/sdk-cli-reference.md
lilic Feb 14, 2019
b0407f4
Merge branch 'master' into csv-versioning
estroz Feb 18, 2019
246b243
update memcached CSV file references
estroz Feb 18, 2019
966cbe6
use config file CRD paths and remove --crds-dir
estroz Feb 18, 2019
1947477
remove --crds-dir from cli ref
estroz Feb 18, 2019
3b75273
Merge branch 'master' into csv-versioning
estroz Feb 19, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 67 additions & 10 deletions commands/operator-sdk/cmd/olm-catalog/gen-csv.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@ package catalog

import (
"fmt"
"io/ioutil"
"path/filepath"
"strings"

"github.com/operator-framework/operator-sdk/internal/util/fileutil"
"github.com/operator-framework/operator-sdk/internal/util/projutil"
"github.com/operator-framework/operator-sdk/pkg/scaffold"
"github.com/operator-framework/operator-sdk/pkg/scaffold/input"
Expand All @@ -30,7 +33,9 @@ import (

var (
csvVersion string
fromVersion string
csvConfigPath string
updateCRDs bool
)

func NewGenCSVCmd() *cobra.Command {
Expand All @@ -40,15 +45,19 @@ func NewGenCSVCmd() *cobra.Command {
Long: `The gen-csv command generates a Cluster Service Version (CSV) YAML manifest
for the operator. This file is used to publish the operator to the OLM Catalog.

A CSV semantic version is supplied via the --csv-version flag.
A CSV semantic version is supplied via the --csv-version flag. If your operator
has already generated a CSV manifest you want to use as a base, supply its
version to --from-version. Otherwise the SDK will scaffold a new CSV manifest.

Configure CSV generation by writing a config file 'deploy/olm-catalog/csv-config.yaml`,
RunE: genCSVFunc,
}

genCSVCmd.Flags().StringVar(&csvVersion, "csv-version", "", "Semantic version of the CSV")
genCSVCmd.MarkFlagRequired("csv-version")
genCSVCmd.Flags().StringVar(&fromVersion, "from-version", "", "Semantic version of an existing CSV to use as a base")
genCSVCmd.Flags().StringVar(&csvConfigPath, "csv-config", "", "Path to CSV config file. Defaults to deploy/olm-catalog/csv-config.yaml")
genCSVCmd.Flags().BoolVar(&updateCRDs, "update-crds", false, "Update CRD manifests in deploy/{operator-name}/{csv-version} the using latest API's")

return genCSVCmd
}
Expand All @@ -74,25 +83,73 @@ func genCSVFunc(cmd *cobra.Command, args []string) error {
log.Infof("Generating CSV manifest version %s", csvVersion)

s := &scaffold.Scaffold{}
err := s.Execute(cfg,
&catalog.CSV{CSVVersion: csvVersion, ConfigFilePath: csvConfigPath},
&catalog.ConcatCRD{ConfigFilePath: csvConfigPath},
)
if err != nil {
csv := &catalog.CSV{
CSVVersion: csvVersion,
FromVersion: fromVersion,
ConfigFilePath: csvConfigPath,
}
if err := s.Execute(cfg, csv); err != nil {
return fmt.Errorf("catalog scaffold failed: (%v)", err)
}

// Write CRD's to the new or updated CSV package dir.
if updateCRDs {
input, err := csv.GetInput()
if err != nil {
return err
}
cfg, err := catalog.GetCSVConfig(csvConfigPath)
if err != nil {
return err
}
err = writeCRDsToDir(cfg.CRDCRPaths, filepath.Dir(input.Path))
if err != nil {
return err
}
}

return nil
}

func verifyGenCSVFlags() error {
v, err := semver.NewVersion(csvVersion)
if err := verifyCSVVersion(csvVersion); err != nil {
return err
}
if fromVersion != "" {
if err := verifyCSVVersion(fromVersion); err != nil {
return err
}
}
return nil
}

func verifyCSVVersion(version string) error {
v, err := semver.NewVersion(version)
if err != nil {
return fmt.Errorf("%s is not a valid semantic version: (%v)", csvVersion, err)
return fmt.Errorf("%s is not a valid semantic version: (%v)", version, err)
}
// Ensures numerical values composing csvVersion don't contain leading 0's,
// ex. 01.01.01
if v.String() != csvVersion {
return fmt.Errorf("provided CSV version %s contains bad values (parses to %s)", csvVersion, v)
if v.String() != version {
return fmt.Errorf("provided CSV version %s contains bad values (parses to %s)", version, v)
}
return nil
}

func writeCRDsToDir(crdPaths []string, toDir string) error {
for _, p := range crdPaths {
if !strings.HasSuffix(p, "crd.yaml") {
continue
}
b, err := ioutil.ReadFile(p)
if err != nil {
return err
}
path := filepath.Join(toDir, filepath.Base(p))
err = ioutil.WriteFile(path, b, fileutil.DefaultFileMode)
if err != nil {
return err
}
}
return nil
}
19 changes: 10 additions & 9 deletions doc/sdk-cli-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,25 +178,26 @@ Parent command for all OLM Catalog related commands.

### gen-csv

Writes a Cluster Service Version (CSV) manifest and concatenated CRD files to `deploy/olm-catalog`.
Writes a Cluster Service Version (CSV) manifest and optionally CRD files to `deploy/olm-catalog/{operator-name}/{csv-version}`.

#### Flags

* `--csv-version` (required) Semantic version of the CSV manifest.
* `--csv-config` Path to CSV config file. Defaults to deploy/olm-catalog/csv-config.yaml.
* `--csv-version` string - (required) Semantic version of the CSV manifest.
* `--from-version` string - Semantic version of CSV manifest to use as a base for a new version.
* `--csv-config` string - Path to CSV config file. Defaults to deploy/olm-catalog/csv-config.yaml.
* `--update-crds` Update CRD manifests in deploy/{operator-name}/{csv-version} using the latest CRD manifests.

#### Example

```console
$ operator-sdk olm-catalog gen-csv --csv-version 0.1.1
INFO[0000] Generating CSV manifest version 0.1.1
INFO[0000] Fill in the following required fields in file deploy/olm-catalog/operator-name.csv.yaml:
$ operator-sdk olm-catalog gen-csv --csv-version 0.1.0 --update-crds
INFO[0000] Generating CSV manifest version 0.1.0
INFO[0000] Fill in the following required fields in file deploy/olm-catalog/operator-name/0.1.0/operator-name.v0.1.0.clusterserviceversion.yaml:
spec.keywords
spec.maintainers
spec.provider
spec.labels
INFO[0000] Created deploy/olm-catalog/operator-name.csv.yaml
INFO[0000] Created deploy/olm-catalog/_generated.concat_crd.yaml
INFO[0000] Created deploy/olm-catalog/operator-name/0.1.0/operator-name.v0.1.0.clusterserviceversion.yaml
```

## migrate
Expand Down Expand Up @@ -385,7 +386,7 @@ Run scorecard tests on an operator
### Example

```console
$ operator-sdk scorecard --cr-manifest deploy/crds/cache_v1alpha1_memcached_cr.yaml --csv-path deploy/memcachedoperator.0.0.2.csv.yaml
$ operator-sdk scorecard --cr-manifest deploy/crds/cache_v1alpha1_memcached_cr.yaml --csv-path deploy/olm-catalog/memcached-operator/0.0.2/memcached-operator.v0.0.2.clusterserviceversion.yaml
Checking for existence of spec and status blocks in CR
Checking that operator actions are reflected in status
Checking that writing into CRs has an effect
Expand Down
4 changes: 2 additions & 2 deletions doc/test-framework/scorecard.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ $ operator-sdk scorecard --cr-manifest deploy/crds/app_operator_cr.yaml --csv-pa
The scorecard supports the use of a config file instead of or in addition to flags for configuration. By default, the scorecard will look
for a file called `.osdk-scorecard` with either a `.yaml`, `.json`, or `.toml` file extension. You can also
specify a different config file with the `--config` flag. The configuration options in the config file match the flags.
For instance, for the flags `--cr-manifest "deploy/crds/cache_v1alpha1_memcached_cr.yaml" --init-timeout 60 --csv-path "deploy/memcachedoperator.0.0.2.csv.yaml"`, the corresponding yaml config file would contain:
For instance, for the flags `--cr-manifest "deploy/crds/cache_v1alpha1_memcached_cr.yaml" --init-timeout 60 --csv-path "deploy/olm-catalog/memcached-operator/0.0.2/memcached-operator.v0.0.2.clusterserviceversion.yaml"`, the corresponding yaml config file would contain:

```yaml
cr-manifest: "deploy/crds/cache_v1alpha1_memcached_cr.yaml"
init-timeout: 60
csv-path: "deploy/memcachedoperator.0.0.2.csv.yaml"
csv-path: "deploy/olm-catalog/memcached-operator/0.0.2/memcached-operator.v0.0.2.clusterserviceversion.yaml"
```

The hierarchy of config methods from highest priority to least is: flag->file->default.
Expand Down
3 changes: 2 additions & 1 deletion hack/tests/scorecard-subcommand.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env bash

DEST_IMAGE="quay.io/example/scorecard-proxy"
CSV_PATH="deploy/olm-catalog/memcached-operator/0.0.2/memcached-operator.v0.0.2.clusterserviceversion.yaml"
CONFIG_PATH=".test-osdk-scorecard.yaml"

set -ex
Expand All @@ -13,7 +14,7 @@ pushd test/test-framework
commandoutput="$(operator-sdk scorecard \
--cr-manifest deploy/crds/cache_v1alpha1_memcached_cr.yaml \
--init-timeout 60 \
--csv-path deploy/memcachedoperator.0.0.2.csv.yaml \
--csv-path "$CSV_PATH" \
--verbose \
--proxy-image "$DEST_IMAGE" \
--proxy-pull-policy Never \
Expand Down
85 changes: 0 additions & 85 deletions pkg/scaffold/olm-catalog/concat_crd.go

This file was deleted.

81 changes: 0 additions & 81 deletions pkg/scaffold/olm-catalog/concat_crd_test.go

This file was deleted.

2 changes: 1 addition & 1 deletion pkg/scaffold/olm-catalog/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type CSVConfig struct {
}

// TODO: discuss case of no config file at default path: write new file or not.
func getCSVConfig(cfgFile string) (*CSVConfig, error) {
func GetCSVConfig(cfgFile string) (*CSVConfig, error) {
cfg := &CSVConfig{}
if _, err := os.Stat(cfgFile); err == nil {
cfgData, err := ioutil.ReadFile(cfgFile)
Expand Down
Loading