@@ -39,6 +39,7 @@ type testLocalConfig struct {
39
39
namespacedManPath string
40
40
goTestFlags string
41
41
namespace string
42
+ noSetup bool
42
43
}
43
44
44
45
var tlConfig testLocalConfig
@@ -54,6 +55,7 @@ func NewTestLocalCmd() *cobra.Command {
54
55
testCmd .Flags ().StringVar (& tlConfig .namespacedManPath , "namespaced-manifest" , "" , "Path to manifest for per-test, namespaced resources (e.g. RBAC and Operator manifest)" )
55
56
testCmd .Flags ().StringVar (& tlConfig .goTestFlags , "go-test-flags" , "" , "Additional flags to pass to go test" )
56
57
testCmd .Flags ().StringVar (& tlConfig .namespace , "namespace" , "" , "If non-empty, single namespace to run tests in" )
58
+ testCmd .Flags ().BoolVar (& tlConfig .noSetup , "no-setup" , false , "Disable test resource creation" )
57
59
58
60
return testCmd
59
61
}
@@ -62,11 +64,14 @@ func testLocalFunc(cmd *cobra.Command, args []string) {
62
64
if len (args ) != 1 {
63
65
log .Fatal ("operator-sdk test local requires exactly 1 argument" )
64
66
}
67
+ if (tlConfig .noSetup && tlConfig .globalManPath != "" ) || (tlConfig .noSetup && tlConfig .namespacedManPath != "" ) {
68
+ log .Fatal ("the global-manifest and namespaced-manifest flags cannot be enabled at the same time as the no-setup flag" )
69
+ }
65
70
66
71
log .Info ("Testing operator locally." )
67
72
68
73
// if no namespaced manifest path is given, combine deploy/service_account.yaml, deploy/role.yaml, deploy/role_binding.yaml and deploy/operator.yaml
69
- if tlConfig .namespacedManPath == "" {
74
+ if tlConfig .namespacedManPath == "" && ! tlConfig . noSetup {
70
75
err := os .MkdirAll (deployTestDir , os .FileMode (fileutil .DefaultDirFileMode ))
71
76
if err != nil {
72
77
log .Fatalf ("could not create %s: (%v)" , deployTestDir , err )
@@ -105,7 +110,7 @@ func testLocalFunc(cmd *cobra.Command, args []string) {
105
110
}
106
111
}()
107
112
}
108
- if tlConfig .globalManPath == "" {
113
+ if tlConfig .globalManPath == "" && ! tlConfig . noSetup {
109
114
err := os .MkdirAll (deployTestDir , os .FileMode (fileutil .DefaultDirFileMode ))
110
115
if err != nil {
111
116
log .Fatalf ("could not create %s: (%v)" , deployTestDir , err )
@@ -141,6 +146,25 @@ func testLocalFunc(cmd *cobra.Command, args []string) {
141
146
}
142
147
}()
143
148
}
149
+ if tlConfig .noSetup {
150
+ err := os .MkdirAll (deployTestDir , os .FileMode (fileutil .DefaultDirFileMode ))
151
+ if err != nil {
152
+ log .Fatalf ("could not create %s: (%v)" , deployTestDir , err )
153
+ }
154
+ tlConfig .namespacedManPath = filepath .Join (deployTestDir , "empty.yaml" )
155
+ tlConfig .globalManPath = filepath .Join (deployTestDir , "empty.yaml" )
156
+ emptyBytes := []byte {}
157
+ err = ioutil .WriteFile (tlConfig .globalManPath , emptyBytes , os .FileMode (fileutil .DefaultFileMode ))
158
+ if err != nil {
159
+ log .Fatalf ("could not create empty manifest file: (%v)" , err )
160
+ }
161
+ defer func () {
162
+ err := os .Remove (tlConfig .globalManPath )
163
+ if err != nil {
164
+ log .Fatalf ("could not delete empty manifest file: (%v)" , err )
165
+ }
166
+ }()
167
+ }
144
168
testArgs := []string {"test" , args [0 ] + "/..." }
145
169
testArgs = append (testArgs , "-" + test .KubeConfigFlag , tlConfig .kubeconfig )
146
170
testArgs = append (testArgs , "-" + test .NamespacedManPathFlag , tlConfig .namespacedManPath )
@@ -151,7 +175,7 @@ func testLocalFunc(cmd *cobra.Command, args []string) {
151
175
if tlConfig .goTestFlags != "" {
152
176
testArgs = append (testArgs , strings .Split (tlConfig .goTestFlags , " " )... )
153
177
}
154
- if tlConfig .namespace != "" {
178
+ if tlConfig .namespace != "" || tlConfig . noSetup {
155
179
testArgs = append (testArgs , "-" + test .SingleNamespaceFlag , "-parallel=1" )
156
180
}
157
181
dc := exec .Command ("go" , testArgs ... )
0 commit comments