From 9d1648c5e4b011e17fa72789d0ee03b67d77b7ef Mon Sep 17 00:00:00 2001 From: andrew Date: Tue, 21 May 2024 16:43:34 +0700 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=20update:=20fix=20duplicate=20cert,?= =?UTF-8?q?=20update=20tags=20earlier?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/ingress/controller/annotation.go | 12 +++++++++++- pkg/ingress/controller/controller.go | 13 +++++++++---- pkg/vngcloud/vlb.go | 13 +++++++++---- 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/pkg/ingress/controller/annotation.go b/pkg/ingress/controller/annotation.go index 7ed59af..72dab53 100644 --- a/pkg/ingress/controller/annotation.go +++ b/pkg/ingress/controller/annotation.go @@ -273,7 +273,17 @@ func NewIngressConfig(pService *nwv1.Ingress) *IngressConfig { } } if option, ok := pService.Annotations[ServiceAnnotationCertificateIDs]; ok { - opt.CertificateIDs = utils.ParseStringListAnnotation(option, ServiceAnnotationCertificateIDs) + arr := utils.ParseStringListAnnotation(option, ServiceAnnotationCertificateIDs) + // remove duplicate certificate IDs + mapCertIDs := make(map[string]bool) + result := []string{} + for _, certID := range arr { + if !mapCertIDs[certID] { + result = append(result, certID) + mapCertIDs[certID] = true + } + } + opt.CertificateIDs = result } return opt } diff --git a/pkg/ingress/controller/controller.go b/pkg/ingress/controller/controller.go index b811a8d..0570290 100644 --- a/pkg/ingress/controller/controller.go +++ b/pkg/ingress/controller/controller.go @@ -1064,6 +1064,10 @@ func (c *Controller) ensureLoadBalancerInstance(inspect *Expander) (string, erro klog.Errorf("error when create new lb: %v", err) return "", err } + err = c.ensureTags(lb.UUID, inspect.serviceConf.Tags) + if err != nil { + klog.Errorln("error when ensure tags", err) + } inspect.serviceConf.LoadBalancerID = lb.UUID vngcloudutil.WaitForLBActive(c.vLBSC, c.getProjectID(), inspect.serviceConf.LoadBalancerID) } @@ -1099,6 +1103,11 @@ func (c *Controller) actionCompareIngress(lbID string, oldIngExpander, newIngExp var err error vngcloudutil.WaitForLBActive(c.vLBSC, c.getProjectID(), lbID) + err = c.ensureTags(lbID, newIngExpander.serviceConf.Tags) + if err != nil { + klog.Errorln("error when ensure tags", err) + } + curLBExpander, err := c.inspectCurrentLB(lbID) if err != nil { klog.Errorln("error when inspect current lb", err) @@ -1196,10 +1205,6 @@ func (c *Controller) actionCompareIngress(lbID string, oldIngExpander, newIngExp if err != nil { klog.Errorln("error when ensure security groups", err) } - err = c.ensureTags(lbID, newIngExpander.serviceConf.Tags) - if err != nil { - klog.Errorln("error when ensure security groups", err) - } // delete redundant policy and pool if in oldIng // with id from curLBExpander diff --git a/pkg/vngcloud/vlb.go b/pkg/vngcloud/vlb.go index 86d6e5b..b44d9f8 100644 --- a/pkg/vngcloud/vlb.go +++ b/pkg/vngcloud/vlb.go @@ -587,6 +587,10 @@ func (c *vLB) ensureLoadBalancerInstance(inspect *Expander) (string, error) { klog.Errorf("error when create new lb: %v", err) return "", err } + err = c.ensureTags(lb.UUID, inspect.serviceConf.Tags) + if err != nil { + klog.Errorln("error when ensure tags", err) + } inspect.serviceConf.LoadBalancerID = lb.UUID vngcloudutil.WaitForLBActive(c.vLBSC, c.getProjectID(), inspect.serviceConf.LoadBalancerID) } @@ -664,6 +668,11 @@ func (c *vLB) actionCompareIngress(lbID string, oldIngExpander, newIngExpander * var err error vngcloudutil.WaitForLBActive(c.vLBSC, c.getProjectID(), lbID) + err = c.ensureTags(lbID, newIngExpander.serviceConf.Tags) + if err != nil { + klog.Errorln("error when ensure tags", err) + } + // ensure all from newIngExpander mapPoolNameIndex := make(map[string]int) for poolIndex, ipool := range newIngExpander.PoolExpander { @@ -702,10 +711,6 @@ func (c *vLB) actionCompareIngress(lbID string, oldIngExpander, newIngExpander * if err != nil { klog.Errorln("error when ensure security groups", err) } - err = c.ensureTags(lbID, newIngExpander.serviceConf.Tags) - if err != nil { - klog.Errorln("error when ensure security groups", err) - } // delete redundant policy and pool if in oldIng // with id from curLBExpander