From 46beff542b250b1cae4664f53db3af62daf31840 Mon Sep 17 00:00:00 2001 From: David Simansky Date: Tue, 23 Apr 2024 09:41:26 +0200 Subject: [PATCH] Fix for already ready ksvc (#1925) --- pkg/serving/v1/client.go | 4 ++++ pkg/serving/v1/client_test.go | 13 +++++++++++++ 2 files changed, 17 insertions(+) diff --git a/pkg/serving/v1/client.go b/pkg/serving/v1/client.go index f5c6e964a..05d165125 100644 --- a/pkg/serving/v1/client.go +++ b/pkg/serving/v1/client.go @@ -366,6 +366,10 @@ func (cl *knServingClient) WaitForService(ctx context.Context, name string, wcon } return err, 0 } + // In case of standalone wait command, it can be executed on already ready ksvc. + if service.IsReady() { + return nil, 0 + } return waitForReady.Wait(ctx, name, service.ResourceVersion, wait.Options{Timeout: &wconfig.Timeout, ErrorWindow: &wconfig.ErrorWindow}, msgCallback) } diff --git a/pkg/serving/v1/client_test.go b/pkg/serving/v1/client_test.go index 480b9dfd2..acf7d7fb7 100644 --- a/pkg/serving/v1/client_test.go +++ b/pkg/serving/v1/client_test.go @@ -748,6 +748,7 @@ func TestWaitForService(t *testing.T) { serving, client := setup() serviceName := "test-service" + readyServiceName := "ready-service" notFoundServiceName := "not-found-service" internalErrorServiceName := "internal-error-service" @@ -771,6 +772,9 @@ func TestWaitForService(t *testing.T) { case serviceName: err = nil svc = newService(serviceName) + case readyServiceName: + err = nil + svc = wait.CreateTestServiceWithConditions(readyServiceName, corev1.ConditionTrue, corev1.ConditionTrue, "", "", 2) case notFoundServiceName: err = apierrors.NewNotFound(servingv1.Resource("service"), notFoundServiceName) case internalErrorServiceName: @@ -790,6 +794,15 @@ func TestWaitForService(t *testing.T) { assert.NilError(t, err) assert.Assert(t, duration > 0) }) + t.Run("wait on a service that is already ready with success", func(t *testing.T) { + err, duration := client.WaitForService(context.Background(), readyServiceName, WaitConfig{ + Timeout: time.Duration(10) * time.Second, + ErrorWindow: time.Duration(2) * time.Second, + }, wait.NoopMessageCallback()) + assert.NilError(t, err) + println("duration:", duration) + assert.Assert(t, duration == 0) + }) t.Run("wait on a service to become ready with not found error", func(t *testing.T) { err, duration := client.WaitForService(context.Background(), notFoundServiceName, WaitConfig{ Timeout: time.Duration(10) * time.Second,