Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 7 additions & 0 deletions changelog/fragments/generate-crds-non-go.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
entries:
- description: >
The `generate crds` subcommand now checks for the existence of the
`pkg/apis` directory and logs a descriptive fatal error message if
it does not exist or is not a directory.

kind: "bugfix"
19 changes: 16 additions & 3 deletions cmd/operator-sdk/generate/crds.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@ package generate

import (
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing fragment

"fmt"

gencrd "github.com/operator-framework/operator-sdk/internal/generate/crd"
"github.com/operator-framework/operator-sdk/internal/genutil"
"os"

log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"

gencrd "github.com/operator-framework/operator-sdk/internal/generate/crd"
"github.com/operator-framework/operator-sdk/internal/genutil"
"github.com/operator-framework/operator-sdk/internal/scaffold"
"github.com/operator-framework/operator-sdk/internal/util/projutil"
)

var (
Expand Down Expand Up @@ -54,6 +57,16 @@ func crdsFunc(cmd *cobra.Command, args []string) error {
if len(args) != 0 {
return fmt.Errorf("command %s doesn't accept any arguments", cmd.CommandPath())
}
projutil.MustInProjectRoot()

stat, err := os.Stat(scaffold.ApisDir)
if os.IsNotExist(err) {
log.Fatalf("Failed to generate CRDs; directory %q not found.", scaffold.ApisDir)
} else if err != nil {
log.Fatalf("Failed to generate CRDs; stat: %v", err)
} else if !stat.IsDir() {
log.Fatalf("Failed to generate CRDs; expected %q to be a directory.", scaffold.ApisDir)
}

// Skip usage printing on error, since this command will never fail from
// improper CLI usage.
Expand Down