Skip to content

Commit 52a1f47

Browse files
committed
Further refactoring
1 parent 25c7e89 commit 52a1f47

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

pkg/lbmanager/lbmanager.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,17 +78,17 @@ func (m *LBManager) DeleteSvcLB(ctx context.Context, in *api.Postgres) error {
7878
func (m *LBManager) nextFreeSocket(ctx context.Context) (string, int32, error) {
7979
// TODO prevent concurrency issues when calculating port / ip.
8080

81-
existingLBIP := ""
81+
anyExistingLBIP := ""
8282

8383
// Fetch all services managed by this postgreslet
8484
lbs := &corev1.ServiceList{}
8585
if err := m.List(ctx, lbs, client.MatchingLabels(api.SvcLoadBalancerLabel)); err != nil {
86-
return existingLBIP, 0, fmt.Errorf("failed to fetch the list of services of type LoadBalancer: %w", err)
86+
return anyExistingLBIP, 0, fmt.Errorf("failed to fetch the list of services of type LoadBalancer: %w", err)
8787
}
8888

8989
// If there are none, this will be the first (managed) service we create, so start with PortRangeStart and return
9090
if len(lbs.Items) == 0 {
91-
return existingLBIP, m.PortRangeStart, nil
91+
return anyExistingLBIP, m.PortRangeStart, nil
9292
}
9393

9494
// If there are already any managed services, store all the used ports in a slice.
@@ -102,7 +102,7 @@ func (m *LBManager) nextFreeSocket(ctx context.Context) (string, int32, error) {
102102
if svc.Spec.LoadBalancerIP != "" {
103103
// Technically, we only store the IP of the last Service in this list.
104104
// As there should only be one IP per postgreslet and one postgreslet per cluster, this is good enough.
105-
existingLBIP = svc.Spec.LoadBalancerIP
105+
anyExistingLBIP = svc.Spec.LoadBalancerIP
106106
}
107107
}
108108

@@ -115,11 +115,11 @@ func (m *LBManager) nextFreeSocket(ctx context.Context) (string, int32, error) {
115115
continue
116116
}
117117
// The postgreslet hasn't assigned this port yet, so use it.
118-
return existingLBIP, port, nil
118+
return anyExistingLBIP, port, nil
119119
}
120120

121121
// If we made it this far, no free port could be found.
122-
return existingLBIP, 0, errors.New("no free port in the configured port range found")
122+
return anyExistingLBIP, 0, errors.New("no free port in the configured port range found")
123123
}
124124

125125
func containsElem(s []int32, v int32) bool {

0 commit comments

Comments
 (0)