Skip to content

Commit

Permalink
Reduce cyclomatic complexity in controller.go (#6373)
Browse files Browse the repository at this point in the history
reduce cyclomatic complexity
  • Loading branch information
j1m-ryan authored Sep 9, 2024
1 parent 66cb364 commit 2b212ba
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions internal/k8s/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -3015,6 +3015,19 @@ func findPoliciesForSecret(policies []*conf_v1.Policy, secretNamespace string, s
return res
}

func (lbc *LoadBalancerController) getTransportServerBackupEndpointsAndKey(transportServer *conf_v1.TransportServer, u conf_v1.TransportServerUpstream, externalNameSvcs map[string]bool) ([]string, string) {
backupEndpointsKey := configs.GenerateEndpointsKey(transportServer.Namespace, u.Backup, nil, *u.BackupPort)
backupEndps, external, err := lbc.getEndpointsForUpstream(transportServer.Namespace, u.Backup, *u.BackupPort)
if err != nil {
glog.Warningf("Error getting Endpoints for Upstream %v: %v", u.Name, err)
}
if err == nil && external {
externalNameSvcs[configs.GenerateExternalNameSvcKey(transportServer.Namespace, u.Backup)] = true
}
bendps := getIPAddressesFromEndpoints(backupEndps)
return bendps, backupEndpointsKey
}

func (lbc *LoadBalancerController) createTransportServerEx(transportServer *conf_v1.TransportServer, listenerPort int) *configs.TransportServerEx {
endpoints := make(map[string][]string)
externalNameSvcs := make(map[string]bool)
Expand Down Expand Up @@ -3042,17 +3055,8 @@ func (lbc *LoadBalancerController) createTransportServerEx(transportServer *conf
}
}

// If backup defined on Upstream retrieve its external name and port.
if u.Backup != "" && u.BackupPort != nil {
backupEndpointsKey := configs.GenerateEndpointsKey(transportServer.Namespace, u.Backup, nil, *u.BackupPort)
backupEndps, external, err := lbc.getEndpointsForUpstream(transportServer.Namespace, u.Backup, *u.BackupPort)
if err != nil {
glog.Warningf("Error getting Endpoints for Upstream %v: %v", u.Name, err)
}
if err == nil && external {
externalNameSvcs[configs.GenerateExternalNameSvcKey(transportServer.Namespace, u.Backup)] = true
}
bendps := getIPAddressesFromEndpoints(backupEndps)
bendps, backupEndpointsKey := lbc.getTransportServerBackupEndpointsAndKey(transportServer, u, externalNameSvcs)
endpoints[backupEndpointsKey] = bendps
}
}
Expand Down

0 comments on commit 2b212ba

Please sign in to comment.