From ced9f2bce0c65247df05c532d8b7915e2af8e2d5 Mon Sep 17 00:00:00 2001 From: Tim Ramlot <42113979+inteon@users.noreply.github.com> Date: Tue, 30 May 2023 15:08:02 +0200 Subject: [PATCH] if wait is set to 0, we still want to check the API once Signed-off-by: Tim Ramlot <42113979+inteon@users.noreply.github.com> --- cmd/ctl/pkg/check/api/api.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/cmd/ctl/pkg/check/api/api.go b/cmd/ctl/pkg/check/api/api.go index 00672697357..3df876a958a 100644 --- a/cmd/ctl/pkg/check/api/api.go +++ b/cmd/ctl/pkg/check/api/api.go @@ -102,7 +102,7 @@ func NewCmdCheckApi(ctx context.Context, ioStreams genericclioptions.IOStreams) SilenceUsage: true, SilenceErrors: true, } - cmd.Flags().DurationVar(&o.Wait, "wait", 0, "Wait until the cert-manager API is ready (default 0s)") + cmd.Flags().DurationVar(&o.Wait, "wait", 0, "Wait until the cert-manager API is ready (default 0s = poll once)") cmd.Flags().DurationVar(&o.Interval, "interval", 5*time.Second, "Time between checks when waiting, must include unit, e.g. 1m or 10m") cmd.Flags().BoolVarP(&o.Verbose, "verbose", "v", false, "Print detailed error messages") @@ -118,13 +118,18 @@ func (o *Options) Run(ctx context.Context) { } log.SetOutput(o.ErrOut) // Log all intermediate errors to stderr - pollErr := wait.PollUntilContextTimeout(ctx, o.Interval, o.Wait, true, func(ctx context.Context) (bool, error) { + start := time.Now() + pollErr := wait.PollUntilContextCancel(ctx, o.Interval, false, func(ctx context.Context) (bool, error) { if err := o.APIChecker.Check(ctx); err != nil { if !o.Verbose && errors.Unwrap(err) != nil { err = errors.Unwrap(err) } log.Printf("Not ready: %v", err) + + if time.Since(start) > o.Wait { + return false, context.DeadlineExceeded + } return false, nil }