diff --git a/internal/k8s/controller.go b/internal/k8s/controller.go index 09bd5eb6f5..0efc7dff96 100644 --- a/internal/k8s/controller.go +++ b/internal/k8s/controller.go @@ -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) @@ -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 } }