From be125ddaea2fb7cd53394921daf52fba2deb871e Mon Sep 17 00:00:00 2001 From: Michael Weibel Date: Fri, 10 Jan 2025 13:56:57 +0100 Subject: [PATCH] fix: adjust connection for custom gRPC trigger `grpc.NewClient` does not automatically connect to the gRPC server anymore. This is unlike the previously used `grpc.Dial`[1]. This change reintroduces initial connection test. [1]: https://github.com/grpc/grpc-go/blob/master/Documentation/anti-patterns.md Signed-off-by: Michael Weibel --- pkg/sensors/triggers/custom-trigger/custom-trigger.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/pkg/sensors/triggers/custom-trigger/custom-trigger.go b/pkg/sensors/triggers/custom-trigger/custom-trigger.go index aea60ee5d0..71fe0e14a7 100644 --- a/pkg/sensors/triggers/custom-trigger/custom-trigger.go +++ b/pkg/sensors/triggers/custom-trigger/custom-trigger.go @@ -97,21 +97,25 @@ func NewCustomTrigger(sensor *v1alpha1.Sensor, trigger *v1alpha1.Trigger, logger opt..., ) if err != nil { - return nil, err + return nil, fmt.Errorf("failed to connect to trigger server: %w", err) } backoff, err := sharedutil.Convert2WaitBackoff(&sharedutil.DefaultBackoff) if err != nil { - return nil, err + return nil, fmt.Errorf("failed to convert wait backoff: %w", err) } if err = wait.ExponentialBackoff(*backoff, func() (done bool, err error) { + logger.Debugw("waiting for trigger client connection...", "server-url", ct.ServerURL, "err", err, "state", conn.GetState().String()) + if conn.GetState() == connectivity.Idle { + conn.Connect() + } if conn.GetState() == connectivity.Ready { return true, nil } return false, nil }); err != nil { - return nil, err + return nil, fmt.Errorf("failed to connect to trigger server: %w", err) } customTrigger.triggerClient = triggers.NewTriggerClient(conn)