66 "fmt"
77 "time"
88
9+ "github.com/cenkalti/backoff/v4"
910 "github.com/sirupsen/logrus"
1011 "k8s.io/client-go/kubernetes"
1112
@@ -19,6 +20,8 @@ func newApproveCSRHandler(log logrus.FieldLogger, clientset kubernetes.Interface
1920 clientset : clientset ,
2021 csrFetchInterval : 5 * time .Second ,
2122 initialCSRFetchTimeout : 5 * time .Minute ,
23+ maxRetries : 10 ,
24+ retryAfter : 1 * time .Second ,
2225 }
2326}
2427
@@ -27,6 +30,8 @@ type approveCSRHandler struct {
2730 clientset kubernetes.Interface
2831 csrFetchInterval time.Duration
2932 initialCSRFetchTimeout time.Duration
33+ maxRetries uint64
34+ retryAfter time.Duration
3035}
3136
3237func (h * approveCSRHandler ) Handle (ctx context.Context , data interface {}) error {
@@ -37,6 +42,20 @@ func (h *approveCSRHandler) Handle(ctx context.Context, data interface{}) error
3742
3843 log := h .log .WithField ("node_name" , req .NodeName )
3944
45+ b := backoff .WithContext (
46+ backoff .WithMaxRetries (backoff .NewConstantBackOff (h .retryAfter ), h .maxRetries ),
47+ ctx ,
48+ )
49+ return backoff .RetryNotify (func () error {
50+ return h .handle (ctx , log , req )
51+ }, b , func (err error , duration time.Duration ) {
52+ if err != nil {
53+ log .Warnf ("csr approval failed, will retry: %v" , err )
54+ }
55+ })
56+ }
57+
58+ func (h * approveCSRHandler ) handle (ctx context.Context , log logrus.FieldLogger , req * castai.ActionApproveCSR ) error {
4059 // First get original csr which is created by kubelet.
4160 log .Debug ("getting initial csr" )
4261 cert , err := h .getInitialNodeCSR (ctx , req .NodeName )
0 commit comments