Skip to content
New issue

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

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

Already on GitHub? # to your account

Implementation of CSV scaffold and update process #673

Merged
merged 69 commits into from
Jan 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
f7c8bae
pkg/scaffold/olm-catalog: CSV scaffold, helpers/interface, simple tests
estroz Oct 22, 2018
13d1fbd
fileutil: remove os.O_TRUNC in default flags to prevent erroneous ove…
estroz Nov 1, 2018
87008bd
pkg/scaffold/olm-catalog/*: use a config file to get manifests
estroz Nov 20, 2018
452f0cc
--csv-version instead of --gen-csv
estroz Nov 21, 2018
f915a15
Gopkg.lock: dep ensure
estroz Nov 26, 2018
3628254
commands/operator-sdk/*: run CSV gen under olm-catalog sub-command in…
estroz Nov 26, 2018
9146d67
fix annoying import spacing errors
estroz Nov 26, 2018
895df66
un-export factory fields; update crd descriptions with user-written f…
estroz Nov 28, 2018
71c66fc
use setters in field init function
estroz Nov 28, 2018
fef6127
Merge branch 'master' into csv-gen-prototype
estroz Dec 13, 2018
9a747de
internal/util/fileutil/yaml.go: Scanner gets k8s yaml manifests from …
estroz Dec 13, 2018
980d3f7
internal/util/fileutil/yaml.go: Scanner gets k8s yaml manifests from …
estroz Dec 13, 2018
430bcc1
internal/util/{file,yaml}util: moved all yaml functions to yamlutil
estroz Dec 13, 2018
f72f000
update csv unit test Diff import path
estroz Dec 13, 2018
1c4622a
use yamlutil.Scanner to scan manifests
estroz Dec 13, 2018
a37741a
internal/util/{file,yaml}util: moved all yaml functions to yamlutil
estroz Dec 13, 2018
c3ca420
replaced 'Split(yamlfile, ---)' calls with scanner
estroz Dec 13, 2018
3d6c985
revendor
estroz Dec 13, 2018
cbb9da7
remove comment
estroz Dec 14, 2018
76b01da
rename file
estroz Dec 14, 2018
5e18e96
CombineManifests takes multiple manifests
estroz Dec 14, 2018
28b821b
use yamlutil.CombineManfiests instead over local fn
estroz Dec 14, 2018
f750c55
reorg branch
estroz Dec 14, 2018
6122f6d
fix indexing check
estroz Dec 14, 2018
8b2d752
Merge branch 'yaml-scanner' into csv-gen-prototype
estroz Dec 14, 2018
7c3bf79
remove unecessary make() calls
estroz Dec 14, 2018
159cd2b
Merge branch 'master' into csv-gen-prototype
estroz Dec 20, 2018
c2ac8ee
Update commands/operator-sdk/cmd/olm-catalog/gen-csv.go
joelanford Jan 8, 2019
c25142f
add comments, conflate readAllBytes parameters, implement CSVUpdater …
estroz Jan 8, 2019
3e2b2fa
pkg/scaffold/olm-catalog/csv_updaters.go: ClusterPermissions updater
estroz Jan 8, 2019
8cef57b
Merge branch 'master' into csv-gen-prototype
estroz Jan 8, 2019
3b07821
check GetInput() error
estroz Jan 9, 2019
88daad6
Csv -> CSV; fix getDisplayName
estroz Jan 9, 2019
28e04ba
remove newline
estroz Jan 9, 2019
57d0eba
Merge branch 'master' into csv-gen-prototype
estroz Jan 9, 2019
367be2f
pkg/scaffold/olm-catalog/*: remove unnecessary Info/Print log statements
estroz Jan 9, 2019
d490e4f
use Golang initialism/acronym conventions for naming CR(D)/CSV types/…
estroz Jan 10, 2019
0f40ff1
Merge branch 'master' into csv-gen-prototype
estroz Jan 10, 2019
f993622
update CLI docs and CSV log messages
estroz Jan 10, 2019
6485570
pkg/scaffold/olm-catalog/concat_crd.go: generate a file of concatenat…
estroz Jan 10, 2019
96d79c0
clean up CLI doc
estroz Jan 10, 2019
c7bbf6f
remove hyphens
estroz Jan 10, 2019
1468f37
pkg/scaffold/olm-catalog/csv*.go: pass a updaterStore to updater func…
estroz Jan 11, 2019
df5d60d
Merge branch 'master' into csv-gen-prototype
estroz Jan 14, 2019
dfee2be
fix CSV log/error messages
estroz Jan 14, 2019
3f40b54
pkg/scaffold/olm-catalog/*: walk all dirs in a config's CRDCRPaths, c…
estroz Jan 14, 2019
db1d850
internal/util/yamlutil/manifest.go: prettify CombineManifests output
estroz Jan 14, 2019
402ec12
pkg/scaffold/olm-catalog/*: add and improve unit tests
estroz Jan 14, 2019
ee1b6f1
Merge branch 'master' into csv-gen-prototype
estroz Jan 14, 2019
34721ed
fix log message cases
estroz Jan 14, 2019
c86c44c
Merge branch 'master' into csv-gen-prototype
estroz Jan 16, 2019
b50805a
cosmetic and text updates
estroz Jan 16, 2019
ee0e9eb
Merge branch 'master' into csv-gen-prototype
estroz Jan 17, 2019
4adc60d
update names to be in line with rest of project; PR comment updates; …
estroz Jan 17, 2019
c4488e2
remove DeployDir; naming cleanup; add ConcatCRD comment
estroz Jan 18, 2019
783d270
Merge branch 'master' into csv-gen-prototype
estroz Jan 18, 2019
8b37027
commands/.../gen-csv.go: add gen-csv flag validation comment
estroz Jan 21, 2019
7313137
add config field comments
estroz Jan 23, 2019
208611e
new() -> &...{} struct declaration styles
estroz Jan 23, 2019
ee331c3
finfo -> info
estroz Jan 23, 2019
61ed084
add --csv-config flag for config file path
estroz Jan 23, 2019
fda7228
Olm -> OLM
estroz Jan 24, 2019
97fc71f
Merge branch 'master' into csv-gen-prototype
estroz Jan 24, 2019
3109881
remove CSVUpdaterSet and impl Apply method on updaterStore
estroz Jan 24, 2019
bb3a124
remove annotation parsers for displayName and description
estroz Jan 24, 2019
4939553
add config file TODO
estroz Jan 24, 2019
85244ad
Update pkg/scaffold/olm-catalog/csv_test.go
hasbro17 Jan 24, 2019
95c8622
fix log message case
estroz Jan 24, 2019
8700e92
Merge branch 'master' into csv-gen-prototype
estroz Jan 24, 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
62 changes: 57 additions & 5 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions commands/operator-sdk/cmd/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,12 @@ func buildFunc(cmd *cobra.Command, args []string) error {
projutil.MustInProjectRoot()
goBuildEnv := append(os.Environ(), "GOOS=linux", "GOARCH=amd64", "CGO_ENABLED=0")
absProjectPath := projutil.MustGetwd()
projectName := filepath.Base(absProjectPath)

// Don't need to build Go code if a non-Go Operator.
if projutil.GetOperatorType() == projutil.OperatorTypeGo {
managerDir := filepath.Join(projutil.CheckAndGetProjectGoPkg(), scaffold.ManagerDir)
outputBinName := filepath.Join(absProjectPath, scaffold.BuildBinDir, filepath.Base(absProjectPath))
outputBinName := filepath.Join(absProjectPath, scaffold.BuildBinDir, projectName)
buildCmd := exec.Command("go", "build", "-o", outputBinName, managerDir)
buildCmd.Env = goBuildEnv
if err := projutil.ExecCmd(buildCmd); err != nil {
Expand All @@ -176,25 +177,25 @@ func buildFunc(cmd *cobra.Command, args []string) error {

if enableTests {
if projutil.GetOperatorType() == projutil.OperatorTypeGo {
testBinary := filepath.Join(absProjectPath, scaffold.BuildBinDir, filepath.Base(absProjectPath)+"-test")
testBinary := filepath.Join(absProjectPath, scaffold.BuildBinDir, projectName+"-test")
buildTestCmd := exec.Command("go", "test", "-c", "-o", testBinary, testLocationBuild+"/...")
buildTestCmd.Env = goBuildEnv
if err := projutil.ExecCmd(buildTestCmd); err != nil {
return fmt.Errorf("failed to build test binary: (%v)", err)
}
}

// if a user is using an older sdk repo as their library, make sure they have required build files
testDockerfile := filepath.Join(scaffold.BuildTestDir, scaffold.DockerfileFile)
_, err := os.Stat(testDockerfile)
if err != nil && os.IsNotExist(err) {

log.Info("Generating build manifests for test-framework.")

absProjectPath := projutil.MustGetwd()
cfg := &input.Config{
Repo: projutil.CheckAndGetProjectGoPkg(),
AbsProjectPath: absProjectPath,
ProjectName: filepath.Base(absProjectPath),
ProjectName: projectName,
}

s := &scaffold.Scaffold{}
Expand Down
32 changes: 32 additions & 0 deletions commands/operator-sdk/cmd/olm-catalog.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright 2018 The Operator-SDK Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package cmd

import (
catalog "github.com/operator-framework/operator-sdk/commands/operator-sdk/cmd/olm-catalog"

"github.com/spf13/cobra"
)

func NewOLMCatalogCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "olm-catalog <olm-catalog-command>",
Short: "Invokes a olm-catalog command",
Long: `The operator-sdk olm-catalog command invokes a command to perform
Catalog related actions.`,
}
cmd.AddCommand(catalog.NewGenCSVCmd())
return cmd
}
98 changes: 98 additions & 0 deletions commands/operator-sdk/cmd/olm-catalog/gen-csv.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
// Copyright 2018 The Operator-SDK Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package catalog

import (
"fmt"
"path/filepath"

"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"
catalog "github.com/operator-framework/operator-sdk/pkg/scaffold/olm-catalog"

"github.com/coreos/go-semver/semver"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

var (
csvVersion string
csvConfigPath string
)

func NewGenCSVCmd() *cobra.Command {
genCSVCmd := &cobra.Command{
Use: "gen-csv",
Short: "Generates a Cluster Service Version yaml file for the operator",
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.

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(&csvConfigPath, "csv-config", "", "Path to CSV config file. Defaults to deploy/olm-catalog/csv-config.yaml")

return genCSVCmd
}

func genCSVFunc(cmd *cobra.Command, args []string) error {
if len(args) != 0 {
return fmt.Errorf("command %s doesn't accept any arguments", cmd.CommandPath())
}

if err := verifyGenCSVFlags(); err != nil {
return err
}

absProjectPath := projutil.MustGetwd()
cfg := &input.Config{
AbsProjectPath: absProjectPath,
ProjectName: filepath.Base(absProjectPath),
}
if projutil.GetOperatorType() == projutil.OperatorTypeGo {
cfg.Repo = projutil.CheckAndGetProjectGoPkg()
}

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 {
return fmt.Errorf("catalog scaffold failed: (%v)", err)
}
return nil
}

func verifyGenCSVFlags() error {
v, err := semver.NewVersion(csvVersion)
if err != nil {
return fmt.Errorf("%s is not a valid semantic version: (%v)", csvVersion, 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)
}
return nil
}
1 change: 1 addition & 0 deletions commands/operator-sdk/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func NewRootCmd() *cobra.Command {
cmd.AddCommand(NewPrintDepsCmd())
cmd.AddCommand(NewMigrateCmd())
cmd.AddCommand(NewRunCmd())
cmd.AddCommand(NewOLMCatalogCmd())

return cmd
}
27 changes: 27 additions & 0 deletions doc/sdk-cli-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,33 @@ pkg/apis/app/v1alpha1/
└── zz_generated.deepcopy.go
```

## olm-catalog

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`.

#### 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.

#### 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:
spec.keywords
spec.maintainers
spec.provider
spec.labels
INFO[0000] Create deploy/olm-catalog/operator-name.csv.yaml
INFO[0000] Create deploy/olm-catalog/_generated.concat_crd.yaml
```

## migrate

Adds a main.go source file and any associated source files for an operator that
Expand Down
2 changes: 1 addition & 1 deletion internal/util/fileutil/file_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const (
DefaultFileMode = 0644
DefaultExecFileMode = 0755

DefaultFileFlags = os.O_WRONLY | os.O_CREATE | os.O_TRUNC
DefaultFileFlags = os.O_WRONLY | os.O_CREATE
)

// FileWriter is a io wrapper to write files
Expand Down
Loading