Skip to content

Commit

Permalink
fix: auto approve csr - watch ignore contex.Canceled and clear functi… (
Browse files Browse the repository at this point in the history
#140)

* fix: auto approve csr - watch ignore contex.Canceled and clear function stack

* code review remarks
  • Loading branch information
aldor007 authored Oct 3, 2024
1 parent 5b9dfcc commit 4b38e17
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions csr/csr.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
Expand All @@ -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)
Expand Down

0 comments on commit 4b38e17

Please sign in to comment.