From ea60426b19b67341fec776e48e360f092fc8c30b Mon Sep 17 00:00:00 2001 From: Trekkie Coder Date: Mon, 24 Jul 2023 23:57:55 +0900 Subject: [PATCH] Specific error status check moved out from REST request/resp handling --- pkg/agent/manager/loadbalancer/loadbalancer.go | 17 +++++++++++++---- pkg/api/request.go | 2 +- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/pkg/agent/manager/loadbalancer/loadbalancer.go b/pkg/agent/manager/loadbalancer/loadbalancer.go index b885715..0d06218 100644 --- a/pkg/agent/manager/loadbalancer/loadbalancer.go +++ b/pkg/agent/manager/loadbalancer/loadbalancer.go @@ -621,8 +621,12 @@ func (m *Manager) addLoadBalancer(svc *corev1.Service) error { var err error for _, lbModel := range lbModelList { if err = c.LoadBalancer().Create(ctx, &lbModel); err != nil { - klog.Errorf("failed to create load-balancer(%s) :%v", c.Url, err) - break + if !strings.Contains(err.Error(), "exist") { + klog.Errorf("failed to create load-balancer(%s) :%v", c.Url, err) + break + } else { + err = nil + } } } h <- err @@ -1196,8 +1200,13 @@ loop: isSuccess = true break } else { - klog.Infof("reinstallLoxiLbRules: lbModel: %v retry(%d)", lbModel, retry) - time.Sleep(1 * time.Second) + if !strings.Contains(err.Error(), "exist") { + klog.Infof("reinstallLoxiLbRules: lbModel: %v retry(%d)", lbModel, retry) + time.Sleep(1 * time.Second) + } else { + isSuccess = true + break + } } } if !isSuccess { diff --git a/pkg/api/request.go b/pkg/api/request.go index 873e701..091ce7f 100644 --- a/pkg/api/request.go +++ b/pkg/api/request.go @@ -133,7 +133,7 @@ func (l *LoxiRequest) Do(ctx context.Context) *LoxiResponse { return &LoxiResponse{err: err} } - if result.Result != "Success" && !strings.Contains(result.Result, "exist") { + if result.Result != "Success" { return &LoxiResponse{err: errors.New(result.Result)} } }