Skip to content

Commit

Permalink
Merge pull request #1024 from ioito/hotfix/qx-gcp-lb-sync
Browse files Browse the repository at this point in the history
fix(google): avoid sync lb panic
  • Loading branch information
ioito authored Jul 29, 2024
2 parents 8274cc3 + f2fa6ce commit 40d40e5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
7 changes: 6 additions & 1 deletion pkg/multicloud/google/globalloadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,12 @@ func (self *SGlobalLoadbalancer) GetAddress() string {
return ""
}

if self.isNameMatch(target) {
match, err := self.isNameMatch(target)
if err != nil {
log.Errorf("isNameMatch error: %v", err)
continue
}
if match {
return item.IPAddress
}
}
Expand Down
15 changes: 11 additions & 4 deletions pkg/multicloud/google/globalloadbalancer_components.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ type SGlobalInstanceGroupInstance struct {
NamedPorts []NamedPort `json:"namedPorts"`
}

func (self *SGlobalLoadbalancer) isNameMatch(target interface{}) bool {
func (self *SGlobalLoadbalancer) isNameMatch(target interface{}) (bool, error) {
var name string
switch t := target.(type) {
case *STargetHttpProxy, *STargetHttpsProxy:
Expand All @@ -59,7 +59,10 @@ func (self *SGlobalLoadbalancer) isNameMatch(target interface{}) bool {
case *STargetHttpsProxy:
URLMapUrl = t.(*STargetHttpsProxy).URLMap
}
urlMapResponse, _ := _jsonRequest(self.region.client.client, "GET", URLMapUrl, nil, false)
urlMapResponse, err := _jsonRequest(self.region.client.client, "GET", URLMapUrl, nil, false)
if err != nil {
return false, err
}
var urlMap SUrlMap
urlMapResponse.Unmarshal(&urlMap)
name = urlMap.Name
Expand All @@ -71,7 +74,7 @@ func (self *SGlobalLoadbalancer) isNameMatch(target interface{}) bool {
parts := strings.Split(t.Service, "/")
name = parts[len(parts)-1]
}
return name == self.GetName()
return name == self.GetName(), nil
}

func (self *SGlobalLoadbalancer) GetForwardingRules() ([]SForwardingRule, error) {
Expand Down Expand Up @@ -103,7 +106,11 @@ func (self *SGlobalLoadbalancer) GetForwardingRules() ([]SForwardingRule, error)
return nil, errors.Wrap(err, "getGlobalAddress.target.Unmarshal")
}

if self.isNameMatch(target) {
match, err := self.isNameMatch(target)
if err != nil {
return nil, errors.Wrapf(err, "isNameMatch")
}
if match {
_ret = append(_ret, item)
}
}
Expand Down

0 comments on commit 40d40e5

Please sign in to comment.