Skip to content

Commit 6ef05db

Browse files
committed
The idea of how this test should work
Signed-off-by: Laura Lorenz <[email protected]>
1 parent 6337a28 commit 6ef05db

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

test/e2e_node/criproxy_test.go

+13-4
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ var _ = SIGDescribe(feature.CriProxy, framework.WithSerial(), func() {
9797
})
9898

9999
ginkgo.It("Image pull retry backs off on error.", func(ctx context.Context) {
100+
// inject PullImage failed to trigger backoff
100101
expectedErr := fmt.Errorf("PullImage failed")
101102
err := addCRIProxyInjector(func(apiName string) error {
102103
if apiName == criproxy.PullImage {
@@ -120,15 +121,22 @@ var _ = SIGDescribe(feature.CriProxy, framework.WithSerial(), func() {
120121
isExpectedErrMsg := strings.Contains(eventMsg, expectedErr.Error())
121122
gomega.Expect(isExpectedErrMsg).To(gomega.BeTrueBecause("we injected an exception into the PullImage interface of the cri proxy"))
122123

123-
// remove error so after backoff we will succeed
124+
// Wait for ~40s worth of backoffs to occur so we can confirm the backoff growth.
125+
podErr = e2epod.WaitForPodContainerStarted(ctx, f.ClientSet, f.Namespace.Name, pod.Name, 0, 40*time.Second)
126+
gomega.Expect(podErr).To(gomega.HaveOccurred(), "Expected container not to start from repeadedly backing off image pulls")
127+
128+
// Remove error so after next backoff we will succeed.
124129
_ = resetCRIProxyInjector()
125130

126131
podErr = e2epod.WaitForPodRunningInNamespace(ctx, f.ClientSet, pod)
127132
framework.ExpectNoError(podErr)
128133

134+
// Parse observed backoffs (TODO: don't use Events, but logs) and compare to expectations
129135
durations, err := getImageBackOffDurations(ctx, f, pod.Name)
130136
framework.ExpectNoError(err)
137+
gomega.Expect(durations).Error().ShouldNot(gomega.BeNil(), "Should have observed backoffs in Pod event log")
131138
gomega.Expect(durations[0]).Should(gomega.BeNumerically("~", time.Duration(10*time.Second), time.Duration(2*time.Second)))
139+
// TODO: and check the next set of durations are 2x, etc
132140

133141
})
134142
})
@@ -191,25 +199,26 @@ func getImageBackOffDurations(ctx context.Context, f *framework.Framework, podNa
191199
var backoffs []time.Duration
192200

193201
type BackOffRecord struct {
194-
podName string
195202
initialEventTime time.Time
196203
backoffEventTimes []time.Time
197204
duration time.Duration
198205
}
199206

200207
records := make(map[int]*BackOffRecord)
208+
records[0] = &BackOffRecord{}
201209
var backoffCount int
202210
var pullTime time.Time
203211
var r *BackOffRecord
212+
// I'm doing this here for events but really it needs to be off kubelet logs or some kind of synchronous watch
213+
// Because the events normalize to the latest
214+
// But this is the idea
204215
for _, event := range events.Items {
205216
if event.InvolvedObject.Name == podName {
206-
207217
switch event.Reason {
208218
case kubeletevents.PullingImage:
209219
if !pullTime.IsZero() {
210220
if event.FirstTimestamp.Time.After(pullTime) {
211221
r = records[backoffCount]
212-
r.podName = podName
213222
r.duration = r.initialEventTime.Sub(r.backoffEventTimes[len(r.backoffEventTimes)-1])
214223
backoffs = append(backoffs, r.duration)
215224
backoffCount++

0 commit comments

Comments
 (0)