Skip to content

Commit bd63504

Browse files
committed
only use controller-tools CRD generator if in a Go project
1 parent c576ed6 commit bd63504

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

internal/util/projutil/project_util.go

+10-7
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,15 @@ import (
2121
"path/filepath"
2222
"strings"
2323

24-
"github.com/operator-framework/operator-sdk/pkg/scaffold/ansible"
25-
"github.com/operator-framework/operator-sdk/pkg/scaffold/helm"
26-
2724
log "github.com/sirupsen/logrus"
2825
"github.com/spf13/cobra"
2926
)
3027

3128
const (
32-
SrcDir = "src"
29+
srcDir = "src"
3330
mainFile = "./cmd/manager/main.go"
31+
rolesDir = "./roles"
32+
helmChartsDir = "./helm-charts"
3433
buildDockerfile = "./build/Dockerfile"
3534
)
3635

@@ -87,7 +86,7 @@ func MustGetwd() string {
8786
// e.g: "github.com/example-inc/app-operator"
8887
func CheckAndGetProjectGoPkg() string {
8988
gopath := SetGopath(GetGopath())
90-
goSrc := filepath.Join(gopath, SrcDir)
89+
goSrc := filepath.Join(gopath, srcDir)
9190
wd := MustGetwd()
9291
currPkg := strings.Replace(wd, goSrc+string(filepath.Separator), "", 1)
9392
// strip any "/" prefix from the repo path.
@@ -102,15 +101,19 @@ func GetOperatorType() OperatorType {
102101
if _, err := os.Stat(mainFile); err == nil {
103102
return OperatorTypeGo
104103
}
105-
if stat, err := os.Stat(ansible.RolesDir); err == nil && stat.IsDir() {
104+
if stat, err := os.Stat(rolesDir); err == nil && stat.IsDir() {
106105
return OperatorTypeAnsible
107106
}
108-
if stat, err := os.Stat(helm.HelmChartsDir); err == nil && stat.IsDir() {
107+
if stat, err := os.Stat(helmChartsDir); err == nil && stat.IsDir() {
109108
return OperatorTypeHelm
110109
}
111110
return OperatorTypeUnknown
112111
}
113112

113+
func IsOperatorGo() bool {
114+
return GetOperatorType() == OperatorTypeGo
115+
}
116+
114117
// GetGopath gets GOPATH and makes sure it is set and non-empty.
115118
func GetGopath() string {
116119
gopath, ok := os.LookupEnv(GopathEnv)

pkg/scaffold/crd.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"strings"
2323
"sync"
2424

25+
"github.com/operator-framework/operator-sdk/internal/util/projutil"
2526
"github.com/operator-framework/operator-sdk/pkg/scaffold/input"
2627

2728
"github.com/ghodss/yaml"
@@ -82,8 +83,8 @@ func (s *Crd) CustomRender() ([]byte, error) {
8283
// so generate crds in a cached, in-memory fs to extract the data we need.
8384
// Note that controller-tools' generator makes different assumptions about
8485
// how crd field values are structured, so we don't want to use the generated
85-
// files directly.
86-
if !cache.fileExists(path) {
86+
// files directly. This generator will fail if not in a Go project.
87+
if !cache.fileExists(path) && projutil.IsOperatorGo() {
8788
g := &crdgenerator.Generator{
8889
RootPath: s.AbsProjectPath,
8990
Domain: "placeholder", // Our crds don't use this value.

0 commit comments

Comments
 (0)