Skip to content

Commit

Permalink
⚡ update: fix duplicate cert, update tags earlier
Browse files Browse the repository at this point in the history
  • Loading branch information
anngdinh committed May 21, 2024
1 parent 0d66639 commit 9d1648c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 9 deletions.
12 changes: 11 additions & 1 deletion pkg/ingress/controller/annotation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
13 changes: 9 additions & 4 deletions pkg/ingress/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
13 changes: 9 additions & 4 deletions pkg/vngcloud/vlb.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 9d1648c

Please sign in to comment.