@@ -72,7 +72,7 @@ var _ = Describe("Graceful Recovery test", Ordered, Label("nfr", "graceful-recov
72
72
leaseName , err := getLeaderElectionLeaseHolderName ()
73
73
Expect (err ).ToNot (HaveOccurred ())
74
74
75
- output , err := restartNGFProcess (ngfContainerName )
75
+ output , err := restartNGFProcess ()
76
76
Expect (err ).ToNot (HaveOccurred (), string (output ))
77
77
78
78
checkContainerLogsForErrors (podNames [0 ])
@@ -89,6 +89,7 @@ var _ = Describe("Graceful Recovery test", Ordered, Label("nfr", "graceful-recov
89
89
Expect (err ).ToNot (HaveOccurred ())
90
90
91
91
Expect (resourceManager .ApplyFromFiles (files , ns .Name )).To (Succeed ())
92
+ time .Sleep (2 * time .Second )
92
93
Expect (resourceManager .WaitForAppsToBeReady (ns .Name )).To (Succeed ())
93
94
94
95
err = waitForWorkingTraffic ()
@@ -103,7 +104,7 @@ var _ = Describe("Graceful Recovery test", Ordered, Label("nfr", "graceful-recov
103
104
leaseName , err := getLeaderElectionLeaseHolderName ()
104
105
Expect (err ).ToNot (HaveOccurred ())
105
106
106
- output , err := restartNginxContainer (nginxContainerName )
107
+ output , err := restartNginxContainer ()
107
108
Expect (err ).ToNot (HaveOccurred (), string (output ))
108
109
109
110
checkContainerLogsForErrors (podNames [0 ])
@@ -120,32 +121,22 @@ var _ = Describe("Graceful Recovery test", Ordered, Label("nfr", "graceful-recov
120
121
Expect (err ).ToNot (HaveOccurred ())
121
122
122
123
Expect (resourceManager .ApplyFromFiles (files , ns .Name )).To (Succeed ())
124
+ time .Sleep (2 * time .Second )
123
125
Expect (resourceManager .WaitForAppsToBeReady (ns .Name )).To (Succeed ())
124
126
125
127
err = waitForWorkingTraffic ()
126
128
Expect (err ).ToNot (HaveOccurred ())
127
129
})
128
130
})
129
131
130
- func restartNginxContainer (nginxContainerName string ) ([]byte , error ) {
132
+ func restartNginxContainer () ([]byte , error ) {
131
133
podNames , err := framework .GetReadyNGFPodNames (k8sClient , ngfNamespace , releaseName , timeoutConfig .GetTimeout )
132
134
Expect (err ).ToNot (HaveOccurred ())
133
135
Expect (podNames ).ToNot (BeEmpty ())
134
136
135
- ctx , cancel := context .WithTimeout (context .Background (), timeoutConfig .GetTimeout )
136
- defer cancel ()
137
-
138
- var ngfPod core.Pod
139
- err = k8sClient .Get (ctx , types.NamespacedName {Namespace : ngfNamespace , Name : podNames [0 ]}, & ngfPod )
137
+ restartCount , err := getContainerRestartCount (nginxContainerName , podNames [0 ])
140
138
Expect (err ).ToNot (HaveOccurred ())
141
139
142
- var restartCount int
143
- for _ , containerStatus := range ngfPod .Status .ContainerStatuses {
144
- if containerStatus .Name == nginxContainerName {
145
- restartCount = int (containerStatus .RestartCount )
146
- }
147
- }
148
-
149
140
output , err := exec .Command ( // nolint:gosec
150
141
"kubectl" ,
151
142
"exec" ,
@@ -168,25 +159,14 @@ func restartNginxContainer(nginxContainerName string) ([]byte, error) {
168
159
return nil , nil
169
160
}
170
161
171
- func restartNGFProcess (ngfContainerName string ) ([]byte , error ) {
162
+ func restartNGFProcess () ([]byte , error ) {
172
163
podNames , err := framework .GetReadyNGFPodNames (k8sClient , ngfNamespace , releaseName , timeoutConfig .GetTimeout )
173
164
Expect (err ).ToNot (HaveOccurred ())
174
165
Expect (podNames ).ToNot (BeEmpty ())
175
166
176
- ctx , cancel := context .WithTimeout (context .Background (), timeoutConfig .GetTimeout )
177
- defer cancel ()
178
-
179
- var ngfPod core.Pod
180
- err = k8sClient .Get (ctx , types.NamespacedName {Namespace : ngfNamespace , Name : podNames [0 ]}, & ngfPod )
167
+ restartCount , err := getContainerRestartCount (ngfContainerName , podNames [0 ])
181
168
Expect (err ).ToNot (HaveOccurred ())
182
169
183
- var restartCount int
184
- for _ , containerStatus := range ngfPod .Status .ContainerStatuses {
185
- if containerStatus .Name == ngfContainerName {
186
- restartCount = int (containerStatus .RestartCount )
187
- }
188
- }
189
-
190
170
output , err := exec .Command ( // nolint:gosec
191
171
"kubectl" ,
192
172
"debug" ,
@@ -218,18 +198,13 @@ func waitForContainerRestart(ngfPodName string, containerName string, currentRes
218
198
ctx ,
219
199
500 * time .Millisecond ,
220
200
true , /* poll immediately */
221
- func (ctx context.Context ) (bool , error ) {
222
- var ngfPod core. Pod
223
- if err := k8sClient . Get ( ctx , types. NamespacedName { Namespace : ngfNamespace , Name : ngfPodName }, & ngfPod ); err != nil {
201
+ func (_ context.Context ) (bool , error ) {
202
+ restartCount , err := getContainerRestartCount ( containerName , ngfPodName )
203
+ if err != nil {
224
204
return false , nil
225
205
}
226
206
227
- for _ , containerStatus := range ngfPod .Status .ContainerStatuses {
228
- if containerStatus .Name == containerName {
229
- return int (containerStatus .RestartCount ) == currentRestartCount + 1 , nil
230
- }
231
- }
232
- return false , nil
207
+ return restartCount == currentRestartCount + 1 , nil
233
208
},
234
209
)
235
210
}
@@ -361,3 +336,22 @@ func getLeaderElectionLeaseHolderName() (string, error) {
361
336
}
362
337
return * lease .Spec .HolderIdentity , nil
363
338
}
339
+
340
+ func getContainerRestartCount (containerName , ngfPodName string ) (int , error ) {
341
+ ctx , cancel := context .WithTimeout (context .Background (), timeoutConfig .GetTimeout )
342
+ defer cancel ()
343
+
344
+ var ngfPod core.Pod
345
+ if err := k8sClient .Get (ctx , types.NamespacedName {Namespace : ngfNamespace , Name : ngfPodName }, & ngfPod ); err != nil {
346
+ return 0 , errors .New ("could not retrieve ngfPod" )
347
+ }
348
+
349
+ var restartCount int
350
+ for _ , containerStatus := range ngfPod .Status .ContainerStatuses {
351
+ if containerStatus .Name == containerName {
352
+ restartCount = int (containerStatus .RestartCount )
353
+ }
354
+ }
355
+
356
+ return restartCount , nil
357
+ }
0 commit comments