Skip to content

Commit 46beff5

Browse files
authored
Fix for already ready ksvc (#1925)
1 parent da50d99 commit 46beff5

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

pkg/serving/v1/client.go

+4
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,10 @@ func (cl *knServingClient) WaitForService(ctx context.Context, name string, wcon
366366
}
367367
return err, 0
368368
}
369+
// In case of standalone wait command, it can be executed on already ready ksvc.
370+
if service.IsReady() {
371+
return nil, 0
372+
}
369373
return waitForReady.Wait(ctx, name, service.ResourceVersion, wait.Options{Timeout: &wconfig.Timeout, ErrorWindow: &wconfig.ErrorWindow}, msgCallback)
370374
}
371375

pkg/serving/v1/client_test.go

+13
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,7 @@ func TestWaitForService(t *testing.T) {
748748
serving, client := setup()
749749

750750
serviceName := "test-service"
751+
readyServiceName := "ready-service"
751752
notFoundServiceName := "not-found-service"
752753
internalErrorServiceName := "internal-error-service"
753754

@@ -771,6 +772,9 @@ func TestWaitForService(t *testing.T) {
771772
case serviceName:
772773
err = nil
773774
svc = newService(serviceName)
775+
case readyServiceName:
776+
err = nil
777+
svc = wait.CreateTestServiceWithConditions(readyServiceName, corev1.ConditionTrue, corev1.ConditionTrue, "", "", 2)
774778
case notFoundServiceName:
775779
err = apierrors.NewNotFound(servingv1.Resource("service"), notFoundServiceName)
776780
case internalErrorServiceName:
@@ -790,6 +794,15 @@ func TestWaitForService(t *testing.T) {
790794
assert.NilError(t, err)
791795
assert.Assert(t, duration > 0)
792796
})
797+
t.Run("wait on a service that is already ready with success", func(t *testing.T) {
798+
err, duration := client.WaitForService(context.Background(), readyServiceName, WaitConfig{
799+
Timeout: time.Duration(10) * time.Second,
800+
ErrorWindow: time.Duration(2) * time.Second,
801+
}, wait.NoopMessageCallback())
802+
assert.NilError(t, err)
803+
println("duration:", duration)
804+
assert.Assert(t, duration == 0)
805+
})
793806
t.Run("wait on a service to become ready with not found error", func(t *testing.T) {
794807
err, duration := client.WaitForService(context.Background(), notFoundServiceName, WaitConfig{
795808
Timeout: time.Duration(10) * time.Second,

0 commit comments

Comments
 (0)