Skip to content

Commit

Permalink
Enable linter errchkjson.
Browse files Browse the repository at this point in the history
Signed-off-by: Xun Jiang <jxun@vmware.com>
  • Loading branch information
Xun Jiang committed Nov 29, 2023
1 parent 3805a47 commit cddc11e
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 5 deletions.
1 change: 1 addition & 0 deletions golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ linters:
- usestdlibvars
- whitespace
- dupword
- errchkjson
fast: false


Expand Down
7 changes: 6 additions & 1 deletion pkg/backup/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -438,8 +438,13 @@ func (kb *kubernetesBackupper) BackupWithResolvers(log logrus.FieldLogger,
if err := kube.PatchResource(backupRequest.Backup, updated, kb.kbClient); err != nil {
log.WithError(errors.WithStack((err))).Warn("Got error trying to update backup's status.progress and hook status")
}
skippedPVSummary, _ := json.Marshal(backupRequest.SkippedPVTracker.Summary())

var skippedPVSummary []byte
if skippedPVSummary, err = json.Marshal(backupRequest.SkippedPVTracker.Summary()); err != nil {
log.WithError(errors.WithStack(err)).Warn("Fail to generate skipped PV summary.")
}
log.Infof("Summary for skipped PVs: %s", skippedPVSummary)

backupRequest.Status.Progress = &velerov1api.BackupProgress{TotalItems: len(backupRequest.BackedUpItems), ItemsBackedUp: len(backupRequest.BackedUpItems)}
log.WithField("progress", "").Infof("Backed up a total of %d items", len(backupRequest.BackedUpItems))

Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/util/output/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,6 @@ func (d *StructuredDescriber) JSONEncode() string {
encoder := json.NewEncoder(byteBuffer)
encoder.SetEscapeHTML(false)
encoder.SetIndent("", " ")
_ = encoder.Encode(d.output)
encoder.Encode(d.output)
return byteBuffer.String()
}
5 changes: 4 additions & 1 deletion pkg/controller/backup_deletion_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,10 @@ func (r *backupDeletionReconciler) deleteMovedSnapshots(ctx context.Context, bac
for i := range list.Items {
cm := list.Items[i]
snapshot := repository.SnapshotIdentifier{}
b, _ := json.Marshal(cm.Data)
b, err := json.Marshal(cm.Data)
if err != nil {
r.logger.WithError(err).Infof("Fail to encode JSON: %v", cm.Data)
}
if err := json.Unmarshal(b, &snapshot); err != nil {
errs = append(errs, errors.Wrapf(err, "failed to unmarshal snapshot info"))
continue
Expand Down
7 changes: 5 additions & 2 deletions pkg/datamover/dataupload_delete_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,12 @@ func genConfigmap(bak *velerov1.Backup, du velerov2alpha1.DataUpload) *corev1api
SnapshotID: du.Status.SnapshotID,
RepositoryType: GetUploaderType(du.Spec.DataMover),
}
b, _ := json.Marshal(snapshot)
b, err := json.Marshal(snapshot)
if err != nil {
return nil
}
data := make(map[string]string)
_ = json.Unmarshal(b, &data)
json.Unmarshal(b, &data)
return &corev1api.ConfigMap{
TypeMeta: metav1.TypeMeta{
APIVersion: corev1api.SchemeGroupVersion.String(),
Expand Down

0 comments on commit cddc11e

Please sign in to comment.