File tree 4 files changed +27
-3
lines changed
commands/operator-sdk/cmd
4 files changed +27
-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 15
15
package projutil
16
16
17
17
import (
18
+ "fmt"
18
19
"log"
19
20
"os"
20
21
"path/filepath"
21
22
"strings"
23
+
24
+ "github.com/spf13/cobra"
22
25
)
23
26
24
27
const (
25
28
SrcDir = "src"
26
- gopkgToml = "./Gopkg.toml "
29
+ mainFile = "./cmd/manager/main.go "
27
30
buildDockerfile = "./build/Dockerfile"
28
31
)
29
32
@@ -52,6 +55,16 @@ func MustInProjectRoot() {
52
55
}
53
56
}
54
57
58
+ func MustGoProjectCmd (cmd * cobra.Command ) {
59
+ t := GetOperatorType ()
60
+ switch t {
61
+ case OperatorTypeGo :
62
+ default :
63
+ fmt .Fprintf (os .Stderr , "'%s' is meant for Go projects.\n " , cmd .CommandPath ())
64
+ os .Exit (1 )
65
+ }
66
+ }
67
+
55
68
func MustGetwd () string {
56
69
wd , err := os .Getwd ()
57
70
if err != nil {
@@ -82,8 +95,8 @@ func CheckAndGetCurrPkg() string {
82
95
// This function should be called after verifying the user is in project root
83
96
// e.g: "go", "ansible"
84
97
func GetOperatorType () OperatorType {
85
- // Assuming that if Gopkg.toml exists then this is a Go operator
86
- _ , err := os .Stat (gopkgToml )
98
+ // Assuming that if main.go exists then this is a Go operator
99
+ _ , err := os .Stat (mainFile )
87
100
if err != nil && os .IsNotExist (err ) {
88
101
return OperatorTypeAnsible
89
102
}
You can’t perform that action at this time.
0 commit comments