Skip to content

Commit

Permalink
write CRDs when generating a new package
Browse files Browse the repository at this point in the history
  • Loading branch information
estroz committed Jun 12, 2020
1 parent 018bbc6 commit e2f6bc9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
10 changes: 7 additions & 3 deletions cmd/operator-sdk/generate/packagemanifests/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,13 @@ type packagemanifestsCmd struct {
deployDir string
apisDir string
crdsDir string
updateCRDs bool
stdout bool
quiet bool

// CRD update options
updateCRDs bool
updateCRDsFlag *pflag.Flag

// Interactive options.
interactiveLevel projutil.InteractiveLevel
interactive bool
Expand Down Expand Up @@ -130,8 +133,9 @@ func (c *packagemanifestsCmd) addCommonFlagsTo(fs *pflag.FlagSet) {
fs.StringVar(&c.channelName, "channel", "", "Channel name for the generated package")
fs.BoolVar(&c.isDefaultChannel, "default-channel", false, "Use the channel passed to --channel "+
"as the package manifest file's default channel")
fs.BoolVar(&c.updateCRDs, "update-crds", false, "Update CustomResoureDefinition manifests "+
"in this package")
fs.BoolVar(&c.updateCRDs, "update-crds", false, "Update CustomResoureDefinition manifests in this package. "+
"This will occur automatically when a new package is generated")
c.updateCRDsFlag = fs.Lookup("update-crds")
fs.BoolVarP(&c.quiet, "quiet", "q", false, "Run in quiet mode")
fs.BoolVar(&c.interactive, "interactive", false, "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 @@ -128,7 +128,7 @@ func (c packagemanifestsCmd) validateManifests() error {
}

// runManifests generates package manifests.
func (c packagemanifestsCmd) runManifests(cfg *config.Config) error {
func (c packagemanifestsCmd) runManifests(cfg *config.Config) (err error) {

if !c.quiet && !c.stdout {
fmt.Println("Generating package manifests version", c.version)
Expand Down Expand Up @@ -166,6 +166,9 @@ func (c packagemanifestsCmd) runManifests(cfg *config.Config) error {
return err
}
}
// When generating a new package, CRDs should be written unless --update-crds has been explicitly set to false.
updateCRDsOff := c.updateCRDsFlag.Changed && !c.updateCRDs
writeNewPackageCRDs := !updateCRDsOff && genutil.IsNotExist(filepath.Join(c.outputDir, c.version))

csvGen := gencsv.Generator{
OperatorName: c.operatorName,
Expand All @@ -188,7 +191,7 @@ func (c packagemanifestsCmd) runManifests(cfg *config.Config) error {
return fmt.Errorf("error generating ClusterServiceVersion: %v", err)
}

if c.updateCRDs {
if c.updateCRDs || writeNewPackageCRDs {
var objs []interface{}
for _, crd := range col.V1CustomResourceDefinitions {
objs = append(objs, crd)
Expand Down
1 change: 0 additions & 1 deletion test/e2e-new/e2e_suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,6 @@ var _ = Describe("operator-sdk", func() {
Expect(err).Should(Succeed())
genPkgManCmd = exec.Command(tc.BinaryName, "generate", "packagemanifests",
"--manifests",
"--update-crds",
"--version", "0.0.1")
Expect(err).Should(Succeed())
tc.Stdin = bytes.NewBuffer(kustomizeOutput)
Expand Down

0 comments on commit e2f6bc9

Please sign in to comment.