Skip to content

Commit 0966c25

Browse files
authored
Only try fetch the main service instead of all of them (#597)
1 parent b954ac9 commit 0966c25

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

controllers/postgres_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ func (r *PostgresReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c
208208
log.V(debugLogLevel).Info("finalizer from storage encryption secret removed")
209209
}
210210

211-
deletable, err := r.OperatorManager.IsOperatorDeletable(ctx, namespace)
211+
deletable, err := r.OperatorManager.IsOperatorDeletable(ctx, namespace, instance.ToPeripheralResourceName())
212212
if err != nil {
213213
r.recorder.Eventf(instance, "Warning", "Error", "failed to check if the operator is idle: %v", err)
214214
return ctrl.Result{}, fmt.Errorf("error while checking if the operator is idle: %w", err)

pkg/operatormanager/operatormanager.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ func (m *OperatorManager) InstallOrUpdateOperator(ctx context.Context, namespace
161161
}
162162

163163
// IsOperatorDeletable returns true when there's no running instance operated by the operator
164-
func (m *OperatorManager) IsOperatorDeletable(ctx context.Context, namespace string) (bool, error) {
164+
func (m *OperatorManager) IsOperatorDeletable(ctx context.Context, namespace string, name string) (bool, error) {
165165
log := m.log.WithValues("ns", namespace)
166166

167167
setList := &appsv1.StatefulSetList{}
@@ -173,12 +173,14 @@ func (m *OperatorManager) IsOperatorDeletable(ctx context.Context, namespace str
173173
return false, nil
174174
}
175175

176-
services := &corev1.ServiceList{}
177-
if err := m.client.List(ctx, services, client.InNamespace(namespace), m.toInstanceMatchingLabels()); client.IgnoreNotFound(err) != nil {
178-
return false, fmt.Errorf("error while fetching the list of services operated by the operator: %w", err)
176+
// Try fetch service
177+
ns := types.NamespacedName{
178+
Namespace: namespace,
179+
Name: name,
179180
}
180-
if len(services.Items) != 0 {
181-
log.Info("services still running")
181+
err := m.client.Get(ctx, ns, &corev1.Service{})
182+
if !errors.IsNotFound(err) {
183+
log.Info("service still running")
182184
return false, nil
183185
}
184186

0 commit comments

Comments
 (0)