-
Notifications
You must be signed in to change notification settings - Fork 1.8k
cmd/operator-sdk/olmcatalog/gen-csv.go: --write-config to write CSV config to disk #1346
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
Changes from all commits
21e44e0
61d780c
e4a9779
b677bd5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -15,16 +15,70 @@ | |||||
| package olmcatalog | ||||||
|
|
||||||
| import ( | ||||||
| "fmt" | ||||||
| "path/filepath" | ||||||
|
|
||||||
| "github.com/operator-framework/operator-sdk/internal/pkg/scaffold" | ||||||
| "github.com/operator-framework/operator-sdk/internal/pkg/scaffold/input" | ||||||
| catalog "github.com/operator-framework/operator-sdk/internal/pkg/scaffold/olm-catalog" | ||||||
| "github.com/operator-framework/operator-sdk/internal/util/projutil" | ||||||
|
|
||||||
| log "github.com/sirupsen/logrus" | ||||||
| "github.com/spf13/cobra" | ||||||
| ) | ||||||
|
|
||||||
| var ( | ||||||
| writeCSVConfigOpt = "write-csv-config" | ||||||
|
|
||||||
| writeCSVConfigPath string | ||||||
| ) | ||||||
|
|
||||||
| func NewCmd() *cobra.Command { | ||||||
| cmd := &cobra.Command{ | ||||||
| Use: "olm-catalog <olm-catalog-command>", | ||||||
| Use: "olm-catalog [flags] <olm-catalog-command>", | ||||||
| Short: "Invokes a olm-catalog command", | ||||||
| Long: `The operator-sdk olm-catalog command invokes a command to perform | ||||||
| Catalog related actions.`, | ||||||
| RunE: olmCatalogFunc, | ||||||
| } | ||||||
| cmd.AddCommand(newGenCSVCmd()) | ||||||
|
|
||||||
| i, err := (&catalog.CSVConfig{}).GetInput() | ||||||
| if err != nil { | ||||||
| log.Fatalf("Error retrieving CSV config path: %v", err) | ||||||
| } | ||||||
|
Comment on lines
+46
to
+49
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could not the path be an attribute of the struct and the check be made in the Validate func of it? |
||||||
| cmd.PersistentFlags().StringVar(&writeCSVConfigPath, writeCSVConfigOpt, "", | ||||||
| "Write a default CSV config file. A default path is used if no value is provided."+ | ||||||
| " Set --write-csv-config=<path> to supply a non-default path") | ||||||
| cmd.Flag(writeCSVConfigOpt).NoOptDefVal = i.Path | ||||||
|
|
||||||
| return cmd | ||||||
| } | ||||||
|
|
||||||
| func olmCatalogFunc(cmd *cobra.Command, args []string) error { | ||||||
| if cmd.Flags().Changed(writeCSVConfigOpt) { | ||||||
| absProjectPath := projutil.MustGetwd() | ||||||
| cfg := &input.Config{ | ||||||
| AbsProjectPath: absProjectPath, | ||||||
| ProjectName: filepath.Base(absProjectPath), | ||||||
| } | ||||||
| if projutil.IsOperatorGo() { | ||||||
| cfg.Repo = projutil.CheckAndGetProjectGoPkg() | ||||||
| } | ||||||
| s := &scaffold.Scaffold{} | ||||||
| if err := writeConfig(s, cfg); err != nil { | ||||||
| return err | ||||||
| } | ||||||
| } | ||||||
| return nil | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it creating a new input.Config? Could not it be a NewConfig in its struct, or at least has a more meaningful name? |
||||||
| } | ||||||
| func writeConfig(s *scaffold.Scaffold, cfg *input.Config) error { | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| log.Info("Writing new default CSV config.") | ||||||
| csvCfg := &catalog.CSVConfig{ | ||||||
| Input: input.Input{Path: writeCSVConfigPath}, | ||||||
| } | ||||||
| if err := s.Execute(cfg, csvCfg); err != nil { | ||||||
| return fmt.Errorf("error scaffolding CSV config: %v", err) | ||||||
| } | ||||||
| return nil | ||||||
| } | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,7 @@ package olmcatalog | |
| import ( | ||
| "fmt" | ||
| "io/ioutil" | ||
| "os" | ||
| "path/filepath" | ||
| "strings" | ||
|
|
||
|
|
@@ -56,18 +57,18 @@ Configure CSV generation by writing a config file 'deploy/olm-catalog/csv-config | |
| 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().StringVar(&csvConfigPath, "csv-config", "", "Path to CSV config file. If unset, default file paths are used") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think is good to keep the default path in the info. |
||
| genCSVCmd.Flags().BoolVar(&updateCRDs, "update-crds", false, "Update CRD manifests in deploy/{operator-name}/{csv-version} the using latest API's") | ||
|
|
||
| return genCSVCmd | ||
| } | ||
|
|
||
| func genCSVFunc(cmd *cobra.Command, args []string) error { | ||
| func genCSVFunc(cmd *cobra.Command, args []string) (err error) { | ||
| if len(args) != 0 { | ||
| return fmt.Errorf("command %s doesn't accept any arguments", cmd.CommandPath()) | ||
| } | ||
|
|
||
| if err := verifyGenCSVFlags(); err != nil { | ||
| if err = verifyGenCSVFlags(); err != nil { | ||
| return err | ||
| } | ||
|
|
||
|
|
@@ -79,30 +80,46 @@ func genCSVFunc(cmd *cobra.Command, args []string) error { | |
| if projutil.IsOperatorGo() { | ||
| cfg.Repo = projutil.CheckAndGetProjectGoPkg() | ||
| } | ||
| s := &scaffold.Scaffold{} | ||
|
|
||
| if cmd.Flags().Changed(writeCSVConfigOpt) { | ||
| if err := writeConfig(s, cfg); err != nil { | ||
| return err | ||
| } | ||
| } | ||
|
|
||
| var csvCfgFile *catalog.CSVConfigFile | ||
| if _, err = os.Stat(csvConfigPath); err == nil { | ||
| log.Infof("Using custom CSV config %s.", csvConfigPath) | ||
| csvCfgFile, err = catalog.GetCSVConfigFile(csvConfigPath) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| } else if err != nil && csvConfigPath != "" { | ||
| return fmt.Errorf("error reading CSV config %s: %v", csvConfigPath, err) | ||
| } else { | ||
| log.Info("Using default CSV config.") | ||
| csvCfgFile = &catalog.CSVConfigFile{} | ||
| } | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could not it be improved? |
||
| log.Infof("Generating CSV manifest version %s", csvVersion) | ||
|
|
||
| s := &scaffold.Scaffold{} | ||
| csv := &catalog.CSV{ | ||
| CSVVersion: csvVersion, | ||
| FromVersion: fromVersion, | ||
| ConfigFilePath: csvConfigPath, | ||
| CSVVersion: csvVersion, | ||
| FromVersion: fromVersion, | ||
| CSVConfigFile: csvCfgFile, | ||
| } | ||
| 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) | ||
| i, err := csv.GetInput() | ||
| if err != nil { | ||
| return err | ||
| } | ||
| err = writeCRDsToDir(cfg.CRDCRPaths, filepath.Dir(input.Path)) | ||
| err = writeCRDsToDir(csvCfgFile.CRDCRPaths, filepath.Dir(i.Path)) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
space