@@ -29,54 +29,42 @@ import (
29
29
)
30
30
31
31
var _ = Describe ("Running ansible projects" , func () {
32
- var controllerPodName string
33
- var memcachedSampleFile string
34
- var fooSampleFile string
35
- var memfinSampleFile string
36
- var memcachedDeployment string
37
- var metricsClusterRoleBindingName string
32
+
33
+ var (
34
+ controllerPodName , memcachedDeploymentName , metricsClusterRoleBindingName string
35
+ fooSampleFile , memfinSampleFile , memcachedSampleFile string
36
+ )
38
37
39
38
Context ("built with operator-sdk" , func () {
40
39
BeforeEach (func () {
41
40
metricsClusterRoleBindingName = fmt .Sprintf ("%s-metrics-reader" , tc .ProjectName )
42
-
43
- By ("checking samples" )
44
- memcachedSampleFile = filepath .Join (tc .Dir , "config" , "samples" ,
41
+ samplesDir := filepath .Join (tc .Dir , "config" , "samples" )
42
+ fooSampleFile = filepath .Join (samplesDir , fmt .Sprintf ("%s_%s_foo.yaml" , tc .Group , tc .Version ))
43
+ memfinSampleFile = filepath .Join (samplesDir , fmt .Sprintf ("%s_%s_memfin.yaml" , tc .Group , tc .Version ))
44
+ memcachedSampleFile = filepath .Join (samplesDir ,
45
45
fmt .Sprintf ("%s_%s_%s.yaml" , tc .Group , tc .Version , strings .ToLower (tc .Kind )))
46
- fooSampleFile = filepath .Join (tc .Dir , "config" , "samples" ,
47
- fmt .Sprintf ("%s_%s_foo.yaml" , tc .Group , tc .Version ))
48
- memfinSampleFile = filepath .Join (tc .Dir , "config" , "samples" ,
49
- fmt .Sprintf ("%s_%s_memfin.yaml" , tc .Group , tc .Version ))
50
46
51
47
By ("deploying project on the cluster" )
52
- err := tc .Make ("deploy" , "IMG=" + tc .ImageName )
53
- Expect (err ).NotTo (HaveOccurred ())
48
+ Expect (tc .Make ("deploy" , "IMG=" + tc .ImageName )).To (Succeed ())
54
49
})
50
+
55
51
AfterEach (func () {
56
- By ("deleting Curl Pod created " )
57
- _ , _ = tc .Kubectl .Delete (false , "pod" , "curl" )
52
+ By ("deleting curl pod " )
53
+ testutils . WrapWarnOutput ( tc .Kubectl .Delete (false , "pod" , "curl" ) )
58
54
59
- By ("deleting CR instances created " )
60
- _ , _ = tc . Kubectl . Delete ( false , "-f" , memcachedSampleFile )
61
- _ , _ = tc .Kubectl .Delete (false , "-f" , fooSampleFile )
62
- _ , _ = tc . Kubectl . Delete ( false , "-f" , memfinSampleFile )
55
+ By ("deleting test CR instances" )
56
+ for _ , sample := range [] string { memcachedSampleFile , fooSampleFile , memfinSampleFile } {
57
+ testutils . WrapWarnOutput ( tc .Kubectl .Delete (false , "-f" , sample ) )
58
+ }
63
59
64
60
By ("cleaning up permissions" )
65
- _ , _ = tc .Kubectl .Command ("delete" , "clusterrolebinding" ,
66
- metricsClusterRoleBindingName )
61
+ testutils .WrapWarnOutput (tc .Kubectl .Command ("delete" , "clusterrolebinding" , metricsClusterRoleBindingName ))
67
62
68
63
By ("undeploy project" )
69
- _ = tc .Make ("undeploy" )
64
+ testutils . WrapWarn ( tc .Make ("undeploy" ) )
70
65
71
66
By ("ensuring that the namespace was deleted" )
72
- verifyNamespaceDeleted := func () error {
73
- _ , err := tc .Kubectl .Command ("get" , "namespace" , tc .Kubectl .Namespace )
74
- if strings .Contains (err .Error (), "(NotFound): namespaces" ) {
75
- return err
76
- }
77
- return nil
78
- }
79
- Eventually (verifyNamespaceDeleted , 2 * time .Minute , time .Second ).ShouldNot (Succeed ())
67
+ testutils .WrapWarnOutput (tc .Kubectl .Wait (false , "namespace" , "foo" , "--for" , "delete" , "--timeout" , "2m" ))
80
68
})
81
69
82
70
It ("should run correctly in a cluster" , func () {
@@ -165,19 +153,19 @@ var _ = Describe("Running ansible projects", func() {
165
153
Eventually (verifyControllerProbe , time .Minute , time .Second ).ShouldNot (ContainSubstring ("Killing" ))
166
154
167
155
By ("getting memcached deploy by labels" )
168
- getMencachedDeploument := func () string {
169
- memcachedDeployment , err = tc .Kubectl .Get (
156
+ getMemcachedDeploymentName := func () string {
157
+ memcachedDeploymentName , err = tc .Kubectl .Get (
170
158
false , "deployment" ,
171
159
"-l" , "app=memcached" , "-o" , "jsonpath={..metadata.name}" )
172
160
Expect (err ).NotTo (HaveOccurred ())
173
- return memcachedDeployment
161
+ return memcachedDeploymentName
174
162
}
175
- Eventually (getMencachedDeploument , 2 * time .Minute , time .Second ).ShouldNot (BeEmpty ())
163
+ Eventually (getMemcachedDeploymentName , 2 * time .Minute , time .Second ).ShouldNot (BeEmpty ())
176
164
177
165
By ("checking the Memcached CR deployment status" )
178
166
verifyCRUp := func () string {
179
167
output , err := tc .Kubectl .Command (
180
- "rollout" , "status" , "deployment" , memcachedDeployment )
168
+ "rollout" , "status" , "deployment" , memcachedDeploymentName )
181
169
Expect (err ).NotTo (HaveOccurred ())
182
170
return output
183
171
}
@@ -211,14 +199,14 @@ var _ = Describe("Running ansible projects", func() {
211
199
212
200
By ("scaling deployment replicas to 2" )
213
201
_ , err = tc .Kubectl .Command (
214
- "scale" , "deployment" , memcachedDeployment , "--replicas" , "2" )
202
+ "scale" , "deployment" , memcachedDeploymentName , "--replicas" , "2" )
215
203
Expect (err ).NotTo (HaveOccurred ())
216
204
217
205
By ("verifying the deployment automatically scales back down to 1" )
218
206
verifyMemcachedScalesBack := func () error {
219
207
replicas , err := tc .Kubectl .Get (
220
208
false ,
221
- "deployment" , memcachedDeployment , "-o" , "jsonpath={..spec.replicas}" )
209
+ "deployment" , memcachedDeploymentName , "-o" , "jsonpath={..spec.replicas}" )
222
210
Expect (err ).NotTo (HaveOccurred ())
223
211
if replicas != "1" {
224
212
return fmt .Errorf ("memcached(CR) deployment with %s replicas" , replicas )
@@ -249,7 +237,7 @@ var _ = Describe("Running ansible projects", func() {
249
237
verifyMemcachedPatch := func () error {
250
238
replicas , err := tc .Kubectl .Get (
251
239
false ,
252
- "deployment" , memcachedDeployment , "-o" , "jsonpath={..spec.replicas}" )
240
+ "deployment" , memcachedDeploymentName , "-o" , "jsonpath={..spec.replicas}" )
253
241
Expect (err ).NotTo (HaveOccurred ())
254
242
if replicas != "2" {
255
243
return fmt .Errorf ("memcached(CR) deployment with %s replicas" , replicas )
@@ -381,7 +369,7 @@ var _ = Describe("Running ansible projects", func() {
381
369
getMemcachedDeployment := func () error {
382
370
_ , err := tc .Kubectl .Get (
383
371
false , "deployment" ,
384
- memcachedDeployment )
372
+ memcachedDeploymentName )
385
373
return err
386
374
}
387
375
Eventually (getMemcachedDeployment , time .Minute * 2 , time .Second ).ShouldNot (Succeed ())
0 commit comments