@@ -17,7 +17,6 @@ limitations under the License.
17
17
package deployimage
18
18
19
19
import (
20
- "errors"
21
20
"fmt"
22
21
"os/exec"
23
22
"path/filepath"
@@ -68,128 +67,95 @@ func Run(kbc *utils.TestContext) {
68
67
var controllerPodName string
69
68
var err error
70
69
70
+ SetDefaultEventuallyPollingInterval (time .Second )
71
+ SetDefaultEventuallyTimeout (time .Minute )
72
+
71
73
By ("updating the go.mod" )
72
- err = kbc .Tidy ()
73
- ExpectWithOffset (1 , err ).NotTo (HaveOccurred ())
74
+ Expect (kbc .Tidy ()).To (Succeed ())
74
75
75
76
By ("run make manifests" )
76
- err = kbc .Make ("manifests" )
77
- ExpectWithOffset (1 , err ).NotTo (HaveOccurred ())
77
+ Expect (kbc .Make ("manifests" )).To (Succeed ())
78
78
79
79
By ("run make generate" )
80
- err = kbc .Make ("generate" )
81
- ExpectWithOffset (1 , err ).NotTo (HaveOccurred ())
80
+ Expect (kbc .Make ("generate" )).To (Succeed ())
82
81
83
82
By ("run make all" )
84
- err = kbc .Make ("all" )
85
- ExpectWithOffset (1 , err ).NotTo (HaveOccurred ())
83
+ Expect (kbc .Make ("all" )).To (Succeed ())
86
84
87
85
By ("run make install" )
88
- err = kbc .Make ("install" )
89
- ExpectWithOffset (1 , err ).NotTo (HaveOccurred ())
86
+ Expect (kbc .Make ("install" )).To (Succeed ())
90
87
91
88
By ("building the controller image" )
92
- err = kbc .Make ("docker-build" , "IMG=" + kbc .ImageName )
93
- ExpectWithOffset (1 , err ).NotTo (HaveOccurred ())
89
+ Expect (kbc .Make ("docker-build" , "IMG=" + kbc .ImageName )).To (Succeed ())
94
90
95
91
By ("loading the controller docker image into the kind cluster" )
96
- err = kbc .LoadImageToKindCluster ()
97
- ExpectWithOffset (1 , err ).NotTo (HaveOccurred ())
92
+ Expect (kbc .LoadImageToKindCluster ()).To (Succeed ())
98
93
99
94
By ("deploying the controller-manager" )
100
95
cmd := exec .Command ("make" , "deploy" , "IMG=" + kbc .ImageName )
101
- outputMake , err := kbc .Run (cmd )
102
- ExpectWithOffset (1 , err ).NotTo (HaveOccurred ())
103
-
104
- By ("validating that manager Pod/container(s) are restricted" )
105
- ExpectWithOffset (1 , outputMake ).NotTo (ContainSubstring ("Warning: would violate PodSecurity" ))
96
+ Expect (kbc .Run (cmd )).NotTo (ContainSubstring ("Warning: would violate PodSecurity" ))
106
97
107
98
By ("validating that the controller-manager pod is running as expected" )
108
- verifyControllerUp := func () error {
99
+ verifyControllerUp := func (g Gomega ) {
109
100
// Get pod name
110
101
podOutput , err := kbc .Kubectl .Get (
111
102
true ,
112
103
"pods" , "-l" , "control-plane=controller-manager" ,
113
104
"-o" , "go-template={{ range .items }}{{ if not .metadata.deletionTimestamp }}{{ .metadata.name }}" +
114
105
"{{ \" \\ n\" }}{{ end }}{{ end }}" )
115
- ExpectWithOffset ( 2 , err ).NotTo (HaveOccurred ())
106
+ g . Expect ( err ).NotTo (HaveOccurred ())
116
107
podNames := util .GetNonEmptyLines (podOutput )
117
- if len (podNames ) != 1 {
118
- return fmt .Errorf ("expect 1 controller pods running, but got %d" , len (podNames ))
119
- }
108
+ g .Expect (podNames ).To (HaveLen (1 ), "wrong number of controller-manager pods" )
120
109
controllerPodName = podNames [0 ]
121
- ExpectWithOffset ( 2 , controllerPodName ).Should (ContainSubstring ("controller-manager" ))
110
+ g . Expect ( controllerPodName ).To (ContainSubstring ("controller-manager" ))
122
111
123
112
// Validate pod status
124
- status , err := kbc .Kubectl .Get (
125
- true ,
126
- "pods" , controllerPodName , "-o" , "jsonpath={.status.phase}" )
127
- ExpectWithOffset (2 , err ).NotTo (HaveOccurred ())
128
- if status != "Running" {
129
- return fmt .Errorf ("controller pod in %s status" , status )
130
- }
131
- return nil
113
+ g .Expect (kbc .Kubectl .Get (true , "pods" , controllerPodName , "-o" , "jsonpath={.status.phase}" )).
114
+ To (Equal ("Running" ), "incorrect controller pod status" )
132
115
}
133
116
defer func () {
134
117
out , err := kbc .Kubectl .CommandInNamespace ("describe" , "all" )
135
- ExpectWithOffset ( 1 , err ).NotTo (HaveOccurred ())
118
+ Expect ( err ).NotTo (HaveOccurred ())
136
119
_ , _ = fmt .Fprintln (GinkgoWriter , out )
137
120
}()
138
- EventuallyWithOffset ( 1 , verifyControllerUp , time . Minute , time . Second ).Should (Succeed ())
121
+ Eventually ( verifyControllerUp ).Should (Succeed ())
139
122
By ("creating an instance of the CR" )
140
123
sampleFile := filepath .Join ("config" , "samples" ,
141
124
fmt .Sprintf ("%s_%s_%s.yaml" , kbc .Group , kbc .Version , strings .ToLower (kbc .Kind )))
142
125
143
126
sampleFilePath , err := filepath .Abs (filepath .Join (fmt .Sprintf ("e2e-%s" , kbc .TestSuffix ), sampleFile ))
144
127
Expect (err ).To (Not (HaveOccurred ()))
145
128
146
- EventuallyWithOffset (1 , func () error {
147
- _ , err = kbc .Kubectl .Apply (true , "-f" , sampleFilePath )
148
- return err
149
- }, time .Minute , time .Second ).Should (Succeed ())
129
+ Eventually (func (g Gomega ) {
130
+ g .Expect (kbc .Kubectl .Apply (true , "-f" , sampleFilePath )).Error ().NotTo (HaveOccurred ())
131
+ }).Should (Succeed ())
150
132
151
133
By ("validating that pod(s) status.phase=Running" )
152
- getMemcachedPodStatus := func () error {
153
- status , err := kbc .Kubectl .Get (true , "pods" , "-l" ,
154
- fmt .Sprintf ("app.kubernetes.io/name=%s" , kbc .Kind ),
134
+ verifyMemcachedPodStatus := func (g Gomega ) {
135
+ g . Expect ( kbc .Kubectl .Get (true , "pods" , "-l" ,
136
+ fmt .Sprintf ("app.kubernetes.io/name=e2e- %s" , kbc .TestSuffix ),
155
137
"-o" , "jsonpath={.items[*].status}" ,
156
- )
157
- ExpectWithOffset (2 , err ).NotTo (HaveOccurred ())
158
- if ! strings .Contains (status , "\" phase\" :\" Running\" " ) {
159
- return err
160
- }
161
- return nil
138
+ )).To (ContainSubstring ("\" phase\" :\" Running\" " ))
162
139
}
163
- EventuallyWithOffset ( 1 , getMemcachedPodStatus , time . Minute , time . Second ).Should (Succeed ())
140
+ Eventually ( verifyMemcachedPodStatus ).Should (Succeed ())
164
141
165
142
By ("validating that the status of the custom resource created is updated or not" )
166
- var status string
167
- getStatus := func () error {
168
- status , err = kbc .Kubectl .Get (true , strings .ToLower (kbc .Kind ),
143
+ verifyAvailableStatus := func (g Gomega ) {
144
+ g .Expect (kbc .Kubectl .Get (true , strings .ToLower (kbc .Kind ),
169
145
strings .ToLower (kbc .Kind )+ "-sample" ,
170
- "-o" , "jsonpath={.status.conditions}" )
171
- ExpectWithOffset (2 , err ).NotTo (HaveOccurred ())
172
- if ! strings .Contains (status , "Available" ) {
173
- return errors .New (`status condition with type "Available" should be set` )
174
- }
175
- return nil
146
+ "-o" , "jsonpath={.status.conditions}" )).To (ContainSubstring ("Available" ),
147
+ `status condition with type "Available" should be set` )
176
148
}
177
- Eventually (getStatus , time . Minute , time . Second ).Should (Succeed ())
149
+ Eventually (verifyAvailableStatus ).Should (Succeed ())
178
150
179
151
By ("validating the finalizer" )
180
- EventuallyWithOffset (1 , func () error {
181
- _ , err = kbc .Kubectl .Delete (true , "-f" , sampleFilePath )
182
- return err
183
- }, time .Minute , time .Second ).Should (Succeed ())
152
+ Eventually (func (g Gomega ) {
153
+ g .Expect (kbc .Kubectl .Delete (true , "-f" , sampleFilePath )).Error ().NotTo (HaveOccurred ())
154
+ }).Should (Succeed ())
184
155
185
- EventuallyWithOffset ( 1 , func () error {
186
- events , err := kbc .Kubectl .Get (true , "events" , "--field-selector=type=Warning" ,
156
+ Eventually ( func (g Gomega ) {
157
+ g . Expect ( kbc .Kubectl .Get (true , "events" , "--field-selector=type=Warning" ,
187
158
"-o" , "jsonpath={.items[*].message}" ,
188
- )
189
- ExpectWithOffset (2 , err ).NotTo (HaveOccurred ())
190
- if ! strings .Contains (events , "is being deleted from the namespace" ) {
191
- return err
192
- }
193
- return nil
194
- }, time .Minute , time .Second ).Should (Succeed ())
159
+ )).To (ContainSubstring ("is being deleted from the namespace" ))
160
+ }).Should (Succeed ())
195
161
}
0 commit comments