File tree 4 files changed +25
-3
lines changed
commands/operator-sdk/cmd
4 files changed +25
-3
lines changed Original file line number Diff line number Diff line change @@ -63,6 +63,9 @@ Example:
63
63
}
64
64
65
65
func apiRun (cmd * cobra.Command , args []string ) {
66
+ // Only Go projects can add apis.
67
+ projutil .MustGoProjectCmd (cmd )
68
+
66
69
// Create and validate new resource
67
70
projutil .MustInProjectRoot ()
68
71
r , err := scaffold .NewResource (apiVersion , kind )
Original file line number Diff line number Diff line change @@ -57,6 +57,9 @@ Example:
57
57
}
58
58
59
59
func controllerRun (cmd * cobra.Command , args []string ) {
60
+ // Only Go projects can add controllers.
61
+ projutil .MustGoProjectCmd (cmd )
62
+
60
63
projutil .MustInProjectRoot ()
61
64
// Create and validate new resource
62
65
r , err := scaffold .NewResource (apiVersion , kind )
Original file line number Diff line number Diff line change @@ -43,11 +43,16 @@ func k8sFunc(cmd *cobra.Command, args []string) {
43
43
if len (args ) != 0 {
44
44
log .Fatalf ("k8s command doesn't accept any arguments." )
45
45
}
46
+
47
+ // Only Go projects can generate k8s deepcopy code.
48
+ projutil .MustGoProjectCmd (cmd )
49
+
46
50
K8sCodegen ()
47
51
}
48
52
49
53
// K8sCodegen performs deepcopy code-generation for all custom resources under pkg/apis
50
54
func K8sCodegen () {
55
+
51
56
projutil .MustInProjectRoot ()
52
57
repoPkg := projutil .CheckAndGetCurrPkg ()
53
58
outputPkg := filepath .Join (repoPkg , "pkg/generated" )
Original file line number Diff line number Diff line change @@ -19,11 +19,13 @@ import (
19
19
"os"
20
20
"path/filepath"
21
21
"strings"
22
+
23
+ "github.com/spf13/cobra"
22
24
)
23
25
24
26
const (
25
27
SrcDir = "src"
26
- gopkgToml = "./Gopkg.toml "
28
+ mainFile = "./cmd/manager/main.go "
27
29
buildDockerfile = "./build/Dockerfile"
28
30
)
29
31
@@ -52,6 +54,15 @@ func MustInProjectRoot() {
52
54
}
53
55
}
54
56
57
+ func MustGoProjectCmd (cmd * cobra.Command ) {
58
+ t := GetOperatorType ()
59
+ switch t {
60
+ case OperatorTypeGo :
61
+ default :
62
+ log .Fatalf ("'%s' can only be run for Go operators." , cmd .CommandPath ())
63
+ }
64
+ }
65
+
55
66
func MustGetwd () string {
56
67
wd , err := os .Getwd ()
57
68
if err != nil {
@@ -82,8 +93,8 @@ func CheckAndGetCurrPkg() string {
82
93
// This function should be called after verifying the user is in project root
83
94
// e.g: "go", "ansible"
84
95
func GetOperatorType () OperatorType {
85
- // Assuming that if Gopkg.toml exists then this is a Go operator
86
- _ , err := os .Stat (gopkgToml )
96
+ // Assuming that if main.go exists then this is a Go operator
97
+ _ , err := os .Stat (mainFile )
87
98
if err != nil && os .IsNotExist (err ) {
88
99
return OperatorTypeAnsible
89
100
}
You can’t perform that action at this time.
0 commit comments