@@ -78,17 +78,17 @@ func (m *LBManager) DeleteSvcLB(ctx context.Context, in *api.Postgres) error {
78
78
func (m * LBManager ) nextFreeSocket (ctx context.Context ) (string , int32 , error ) {
79
79
// TODO prevent concurrency issues when calculating port / ip.
80
80
81
- existingLBIP := ""
81
+ anyExistingLBIP := ""
82
82
83
83
// Fetch all services managed by this postgreslet
84
84
lbs := & corev1.ServiceList {}
85
85
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 )
87
87
}
88
88
89
89
// If there are none, this will be the first (managed) service we create, so start with PortRangeStart and return
90
90
if len (lbs .Items ) == 0 {
91
- return existingLBIP , m .PortRangeStart , nil
91
+ return anyExistingLBIP , m .PortRangeStart , nil
92
92
}
93
93
94
94
// 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) {
102
102
if svc .Spec .LoadBalancerIP != "" {
103
103
// Technically, we only store the IP of the last Service in this list.
104
104
// 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
106
106
}
107
107
}
108
108
@@ -115,11 +115,11 @@ func (m *LBManager) nextFreeSocket(ctx context.Context) (string, int32, error) {
115
115
continue
116
116
}
117
117
// The postgreslet hasn't assigned this port yet, so use it.
118
- return existingLBIP , port , nil
118
+ return anyExistingLBIP , port , nil
119
119
}
120
120
121
121
// 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" )
123
123
}
124
124
125
125
func containsElem (s []int32 , v int32 ) bool {
0 commit comments