Skip to content

Commit 3448eaf

Browse files
joelanfordhasbro17
authored andcommitted
Revert "Allow some commands to generate k8s, without requiring build files. (#1966)" (#2039)
This reverts commit a3458ab.
1 parent 8132d35 commit 3448eaf

File tree

4 files changed

+16
-27
lines changed

4 files changed

+16
-27
lines changed

CHANGELOG.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
- Upgrade base image for Go, Helm, and scorecard proxy from `registry.access.redhat.com/ubi7/ubi-minimal:latest` to `registry.access.redhat.com/ubi8/ubi-minimal:latest`. ([#1952](https://github.com/operator-framework/operator-sdk/pull/1952))
1919
- Upgrade base image for Ansible from `registry.access.redhat.com/ubi7/ubi:latest` to `registry.access.redhat.com/ubi8/ubi:latest`. ([#1990](https://github.com/operator-framework/operator-sdk/pull/1990) and [#2004](https://github.com/operator-framework/operator-sdk/pull/2004))
2020
- Updated kube-state-metrics dependency from `v1.6.0` to `v1.7.2`. ([#1943](https://github.com/operator-framework/operator-sdk/pull/1943))
21-
- Change the structure used by sub-commands to check the type and the root dir of the projects for no longer relay in the `Dockerfile` and `main.go` files. ([#1966](https://github.com/operator-framework/operator-sdk/pull/1966))
2221

2322
### Breaking changes
2423

cmd/operator-sdk/main.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@ func main() {
5757
log.Debug("Debug logging is set")
5858
}
5959
if err := checkDepManagerForCmd(cmd); err != nil {
60-
// Allow cases where subcommands do not require deps files
61-
log.Warnf("Operator type %s and the %s. Please, review the structure of your project.", projutil.GetOperatorType(), err)
60+
log.Fatal(err)
6261
}
6362
},
6463
}

cmd/operator-sdk/printdeps/cmd.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@ package printdeps
1616

1717
import (
1818
"fmt"
19+
1920
"github.com/operator-framework/operator-sdk/internal/pkg/scaffold"
2021
"github.com/operator-framework/operator-sdk/internal/pkg/scaffold/ansible"
2122
"github.com/operator-framework/operator-sdk/internal/pkg/scaffold/helm"
2223
"github.com/operator-framework/operator-sdk/internal/util/projutil"
24+
2325
"github.com/spf13/cobra"
24-
log "github.com/sirupsen/logrus"
2526
)
2627

2728
var depManager string
@@ -49,19 +50,13 @@ func printDepsFunc(cmd *cobra.Command, args []string) error {
4950
}
5051
projutil.MustInProjectRoot()
5152

52-
// Allow the cases of some sub-commands might not require check the deps files.
53-
if projutil.GetOperatorType() == projutil.OperatorTypeUnknown {
54-
log.Fatal(fmt.Errorf("unknown project type, we were unable to print the deps"))
55-
}
56-
5753
if err := printDeps(depManager); err != nil {
5854
return fmt.Errorf("print deps failed: %v", err)
5955
}
6056
return nil
6157
}
6258

6359
func printDeps(depManager string) (err error) {
64-
6560
// Use depManager if set. Fall back to the project's current dep manager
6661
// type if unset.
6762
mt := projutil.DepManagerType(depManager)

internal/util/projutil/project_util.go

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ const (
3535
GoModEnv = "GO111MODULE"
3636
SrcDir = "src"
3737

38-
fsep = string(filepath.Separator)
39-
buildDir = "build" + fsep
40-
rolesDir = "roles"
41-
pkgApiDir = "pkg" + fsep + "apis" + fsep
42-
helmChartsDir = "helm-charts"
43-
goModFile = "go.mod"
44-
gopkgTOMLFile = "Gopkg.toml"
38+
fsep = string(filepath.Separator)
39+
mainFile = "cmd" + fsep + "manager" + fsep + "main.go"
40+
buildDockerfile = "build" + fsep + "Dockerfile"
41+
rolesDir = "roles"
42+
helmChartsDir = "helm-charts"
43+
goModFile = "go.mod"
44+
gopkgTOMLFile = "Gopkg.toml"
4545
)
4646

4747
// OperatorType - the type of operator
@@ -114,11 +114,11 @@ func MustInProjectRoot() {
114114
// CheckProjectRoot checks if the current dir is the project root, and returns
115115
// an error if not.
116116
func CheckProjectRoot() error {
117-
// If the current directory has a "build/", then it is safe to say
117+
// If the current directory has a "build/Dockerfile", then it is safe to say
118118
// we are at the project root.
119-
if _, err := os.Stat(buildDir); err != nil {
119+
if _, err := os.Stat(buildDockerfile); err != nil {
120120
if os.IsNotExist(err) {
121-
return fmt.Errorf("must run command in project root dir: project structure requires %s", buildDir)
121+
return fmt.Errorf("must run command in project root dir: project structure requires %s", buildDockerfile)
122122
}
123123
return errors.Wrap(err, "error while checking if current directory is the project root")
124124
}
@@ -129,7 +129,7 @@ func CheckGoProjectCmd(cmd *cobra.Command) error {
129129
if IsOperatorGo() {
130130
return nil
131131
}
132-
return fmt.Errorf("'%s' can only be run for Go operators; %s, %s or %s does not exist", cmd.CommandPath(), goModFile, gopkgTOMLFile, pkgApiDir)
132+
return fmt.Errorf("'%s' can only be run for Go operators; %s does not exist", cmd.CommandPath(), mainFile)
133133
}
134134

135135
func MustGetwd() string {
@@ -215,12 +215,8 @@ func GetOperatorType() OperatorType {
215215
}
216216

217217
func IsOperatorGo() bool {
218-
_, errGoMod := os.Stat(goModFile)
219-
_, errGopkgTOMLFile := os.Stat(gopkgTOMLFile)
220-
_, errPkgApiDir := os.Stat(pkgApiDir)
221-
222-
// check if has go modules or dep files or pkg/api
223-
return errGoMod == nil || errGopkgTOMLFile == nil || errPkgApiDir == nil
218+
_, err := os.Stat(mainFile)
219+
return err == nil
224220
}
225221

226222
func IsOperatorAnsible() bool {

0 commit comments

Comments
 (0)