From 4b38e1756c307aa793ea0373114aeda4e3c14fc7 Mon Sep 17 00:00:00 2001 From: Marcin Kaciuba Date: Thu, 3 Oct 2024 10:26:10 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20auto=20approve=20csr=20-=20watch=20ignor?= =?UTF-8?q?e=20contex.Canceled=20and=20clear=20functi=E2=80=A6=20(#140)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: auto approve csr - watch ignore contex.Canceled and clear function stack * code review remarks --- csr/csr.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/csr/csr.go b/csr/csr.go index 70d15748..d8b56eac 100644 --- a/csr/csr.go +++ b/csr/csr.go @@ -281,8 +281,13 @@ func WatchCastAINodeCSRs(ctx context.Context, log logrus.FieldLogger, client kub waitext.Forever, func(ctx context.Context) (bool, error) { w, err = getWatcher(ctx, client) + // Context canceled is when the cluster-controller is stopped. + // In that case context.Canceled is not an error. + if errors.Is(err, context.Canceled) { + return false, err + } if err != nil { - return true, fmt.Errorf("fail to open v1 and v1beta watching client: %w", err) + return true, fmt.Errorf("getWatcher: %w", err) } return false, nil }, @@ -306,7 +311,8 @@ func WatchCastAINodeCSRs(ctx context.Context, log logrus.FieldLogger, client kub case event, ok := <-w.ResultChan(): if !ok { log.Debug("watcher closed") - WatchCastAINodeCSRs(ctx, log, client, c) // start over in case of any error + go WatchCastAINodeCSRs(ctx, log, client, c) // start over in case of any error + return } csrResult, name, request := toCertificate(event)