From 04fa87ccd1edf6dfec048717a3bd1ee7d3ab1a1d Mon Sep 17 00:00:00 2001 From: Aleksei Sviridkin Date: Thu, 12 Nov 2026 23:30:02 +0300 Subject: [PATCH] style(backups): clear staticcheck findings in overlapping controllers Drop a field-manager constant nothing uses in the MariaDB driver, switch on the MongoDB operator's state as a tagged switch, and reword the error strings of the MongoDB driver and the workload monitor so they do not start with a capital. The errors keep their meaning and nothing matches their text. Assisted-by: LLM Signed-off-by: Aleksei Sviridkin --- .../backupcontroller/mariadbstrategy_controller.go | 2 -- .../backupcontroller/psmdbstrategy_controller.go | 14 +++++++------- internal/controller/workloadmonitor_controller.go | 4 ++-- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/internal/backupcontroller/mariadbstrategy_controller.go b/internal/backupcontroller/mariadbstrategy_controller.go index 9fd6780db..452fff071 100644 --- a/internal/backupcontroller/mariadbstrategy_controller.go +++ b/internal/backupcontroller/mariadbstrategy_controller.go @@ -30,8 +30,6 @@ import ( // --------------------------------------------------------------------------- const ( - mariadbFieldManager = "cozystack-mariadb-backup-driver" - // mariadb-operator's MariaDB ApplicationDefinition (release.prefix). The // cozystack mariadb-rd renders the HelmRelease with releaseName = // "mariadb-" + appName (see packages/system/mariadb-rd/cozyrds/mariadb.yaml, diff --git a/internal/backupcontroller/psmdbstrategy_controller.go b/internal/backupcontroller/psmdbstrategy_controller.go index 9caa218a7..ccf3e7735 100644 --- a/internal/backupcontroller/psmdbstrategy_controller.go +++ b/internal/backupcontroller/psmdbstrategy_controller.go @@ -528,8 +528,8 @@ func (r *BackupJobReconciler) reconcileMongoDB(ctx context.Context, j *backupsv1 } } - switch state := mdbBackup.Status.State; { - case state == psmdbtypes.StateReady: + switch state := mdbBackup.Status.State; state { + case psmdbtypes.StateReady: // Backup completed successfully. Materialise the Cozystack artifact and // finalise the BackupJob. Idempotent: reuse the existing artifact if a // previous reconcile created it and then raced on the status update. @@ -570,7 +570,7 @@ func (r *BackupJobReconciler) reconcileMongoDB(ctx context.Context, j *backupsv1 } return ctrl.Result{}, nil - case state == psmdbtypes.StateError || state == psmdbtypes.StateRejected: + case psmdbtypes.StateError, psmdbtypes.StateRejected: message := mdbBackup.Status.Error // The residual half of the injection race: on the useSystemBucket flow the // operator can latch state=error because it resolved the injected storage @@ -1740,8 +1740,8 @@ func (r *RestoreJobReconciler) reconcileMongoDBRestore(ctx context.Context, rest return r.markRestoreJobFailed(ctx, restoreJob, fmt.Sprintf("failed to ensure psmdb.percona.com/PerconaServerMongoDBRestore: %v", err)) } - switch state := mdbRestore.Status.State; { - case state == psmdbtypes.StateReady: + switch state := mdbRestore.Status.State; state { + case psmdbtypes.StateReady: now := metav1.Now() restoreJob.Status.CompletedAt = &now restoreJob.Status.Phase = backupsv1alpha1.RestoreJobPhaseSucceeded @@ -1756,7 +1756,7 @@ func (r *RestoreJobReconciler) reconcileMongoDBRestore(ctx context.Context, rest } return ctrl.Result{}, nil - case state == psmdbtypes.StateError || state == psmdbtypes.StateRejected: + case psmdbtypes.StateError, psmdbtypes.StateRejected: message := mdbRestore.Status.Error if message == "" { message = fmt.Sprintf("psmdb.percona.com/PerconaServerMongoDBRestore %s/%s reported state=%s", mdbRestore.Namespace, mdbRestore.Name, state) @@ -1855,7 +1855,7 @@ func (r *RestoreJobReconciler) resolveMongoDBBackupSource(ctx context.Context, b } if destination == "" { return nil, fmt.Errorf( - "Backup has no restorable destination (the operator PerconaServerMongoDBBackup was reaped and no snapshot destination is persisted); re-run the BackupJob") + "no restorable destination for the Backup (the operator PerconaServerMongoDBBackup was reaped and no snapshot destination is persisted); re-run the BackupJob") } src := &psmdbtypes.BackupSource{ Type: psmdbtypes.BackupTypeLogical, diff --git a/internal/controller/workloadmonitor_controller.go b/internal/controller/workloadmonitor_controller.go index 984ab7b21..217fd0bbf 100644 --- a/internal/controller/workloadmonitor_controller.go +++ b/internal/controller/workloadmonitor_controller.go @@ -528,7 +528,7 @@ func (r *WorkloadMonitorReconciler) queryAllBucketMetrics(ctx context.Context, p defer resp.Body.Close() if resp.StatusCode != http.StatusOK { - return nil, fmt.Errorf("Prometheus returned status %d", resp.StatusCode) + return nil, fmt.Errorf("unexpected status %d from Prometheus", resp.StatusCode) } body, err := io.ReadAll(io.LimitReader(resp.Body, 4<<20)) @@ -549,7 +549,7 @@ func (r *WorkloadMonitorReconciler) queryAllBucketMetrics(ctx context.Context, p return nil, fmt.Errorf("parsing Prometheus response: %w", err) } if promResp.Status != "success" { - return nil, fmt.Errorf("Prometheus query finished with status %q", promResp.Status) + return nil, fmt.Errorf("the Prometheus query finished with status %q", promResp.Status) } for _, r := range promResp.Data.Result {