mirror of
https://github.com/cozystack/cozystack.git
synced 2026-11-21 12:13:55 +09:00
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 <f@lex.la>
This commit is contained in:
3 files changed
+9
-11
No files matched your search
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in new issue
Block a user