Skip to content

Commit cfb9dee

Browse files
committed
fix QF1008 rule from staticcheck
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
1 parent bda63ac commit cfb9dee

32 files changed

Lines changed: 107 additions & 108 deletions

.golangci.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,6 @@ linters:
249249
staticcheck:
250250
checks:
251251
- all
252-
- -QF1008 # Omit embedded fields from selector expression
253252

254253
testifylint:
255254
# TODO: enable them all

internal/delete/delete_item_action_handler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ func InvokeDeleteActions(ctx *Context) error {
120120
continue
121121
}
122122

123-
err = action.DeleteItemAction.Execute(&velero.DeleteItemActionExecuteInput{
123+
err = action.Execute(&velero.DeleteItemActionExecuteInput{
124124
Item: obj,
125125
Backup: ctx.Backup,
126126
})

internal/volume/volumes_information.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ func (v *BackupVolumesInformation) generateVolumeInfoForCSIVolumeSnapshot() {
446446

447447
var operation itemoperation.BackupOperation
448448
for _, op := range v.BackupOperations {
449-
if op.Spec.ResourceIdentifier.GroupResource.String() == kuberesource.VolumeSnapshots.String() &&
449+
if op.Spec.ResourceIdentifier.String() == kuberesource.VolumeSnapshots.String() &&
450450
op.Spec.ResourceIdentifier.Name == volumeSnapshot.Name &&
451451
op.Spec.ResourceIdentifier.Namespace == volumeSnapshot.Namespace {
452452
operation = *op
@@ -567,9 +567,9 @@ func (v *BackupVolumesInformation) generateVolumeInfoFromDataUpload() {
567567
// Retrieve the operations containing DataUpload.
568568
duOperationMap := make(map[kbclient.ObjectKey]*itemoperation.BackupOperation)
569569
for _, operation := range v.BackupOperations {
570-
if operation.Spec.ResourceIdentifier.GroupResource.String() == kuberesource.PersistentVolumeClaims.String() {
570+
if operation.Spec.ResourceIdentifier.String() == kuberesource.PersistentVolumeClaims.String() {
571571
for _, identifier := range operation.Spec.PostOperationItems {
572-
if identifier.GroupResource.String() == "datauploads.velero.io" {
572+
if identifier.String() == "datauploads.velero.io" {
573573
duOperationMap[kbclient.ObjectKey{
574574
Namespace: identifier.Namespace,
575575
Name: identifier.Name,

internal/volumehelper/volume_policy_helper.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ func (v volumeHelperImpl) ShouldPerformFSBackup(volume corev1api.Volume, pod cor
148148
var err error
149149
resource = &volume
150150
var pvc = &corev1api.PersistentVolumeClaim{}
151-
if volume.VolumeSource.PersistentVolumeClaim != nil {
151+
if volume.PersistentVolumeClaim != nil {
152152
pvc, err = kubeutil.GetPVCForPodVolume(&volume, &pod, v.client)
153153
if err != nil {
154154
v.logger.WithError(err).Errorf("fail to get PVC for pod %s", pod.Namespace+"/"+pod.Name)

pkg/backup/actions/csi/pvc_action.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ func (p *pvcBackupItemAction) validatePVCandPV(
109109
return false, updateItem, errors.WithStack(err)
110110
}
111111

112-
if pv.Spec.PersistentVolumeSource.CSI == nil {
112+
if pv.Spec.CSI == nil {
113113
p.log.Infof(
114114
"Skipping PVC %s/%s, associated PV %s is not a CSI volume",
115115
pvc.Namespace, pvc.Name, pv.Name)
@@ -160,7 +160,7 @@ func (p *pvcBackupItemAction) createVolumeSnapshot(
160160
p.log.Infof("VolumeSnapshotClass=%s", vsClass.Name)
161161

162162
vsLabels := map[string]string{}
163-
for k, v := range pvc.ObjectMeta.Labels {
163+
for k, v := range pvc.Labels {
164164
vsLabels[k] = v
165165
}
166166
vsLabels[velerov1api.BackupNameLabel] = label.GetValidName(backup.Name)
@@ -355,7 +355,7 @@ func (p *pvcBackupItemAction) Execute(
355355
p.log.Infof("Returning from PVCBackupItemAction with %d additionalItems to backup",
356356
len(additionalItems))
357357
for _, ai := range additionalItems {
358-
p.log.Debugf("%s: %s", ai.GroupResource.String(), ai.Name)
358+
p.log.Debugf("%s: %s", ai.String(), ai.Name)
359359
}
360360

361361
pvcMap, err := runtime.DefaultUnstructuredConverter.ToUnstructured(&pvc)

pkg/backup/actions/csi/volumesnapshot_action.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ func (p *volumeSnapshotBackupItemAction) Execute(
237237
p.log.Infof("Returning from VolumeSnapshotBackupItemAction with %d additionalItems to backup",
238238
len(additionalItems))
239239
for _, ai := range additionalItems {
240-
p.log.Debugf("%s: %s", ai.GroupResource.String(), ai.Name)
240+
p.log.Debugf("%s: %s", ai.String(), ai.Name)
241241
}
242242

243243
operationID := ""

pkg/backup/backup.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ func (kb *kubernetesBackupper) BackupWithResolvers(
279279
)
280280
}
281281

282-
log.Infof("Backing up all volumes using pod volume backup: %t", boolptr.IsSetToTrue(backupRequest.Backup.Spec.DefaultVolumesToFsBackup))
282+
log.Infof("Backing up all volumes using pod volume backup: %t", boolptr.IsSetToTrue(backupRequest.Spec.DefaultVolumesToFsBackup))
283283

284284
var err error
285285
backupRequest.ResourceHooks, err = getResourceHooks(backupRequest.Spec.Hooks.Resources, kb.discoveryHelper)
@@ -344,7 +344,7 @@ func (kb *kubernetesBackupper) BackupWithResolvers(
344344
items := collector.getAllItems()
345345
log.WithField("progress", "").Infof("Collected %d items matching the backup spec from the Kubernetes API (actual number of items backed up may be more or less depending on velero.io/exclude-from-backup annotation, plugins returning additional related items to back up, etc.)", len(items))
346346

347-
updated := backupRequest.Backup.DeepCopy()
347+
updated := backupRequest.DeepCopy()
348348
if updated.Status.Progress == nil {
349349
updated.Status.Progress = &velerov1api.BackupProgress{}
350350
}
@@ -417,7 +417,7 @@ func (kb *kubernetesBackupper) BackupWithResolvers(
417417
lastUpdate = &val
418418
case <-ticker.C:
419419
if lastUpdate != nil {
420-
updated := backupRequest.Backup.DeepCopy()
420+
updated := backupRequest.DeepCopy()
421421
if updated.Status.Progress == nil {
422422
updated.Status.Progress = &velerov1api.BackupProgress{}
423423
}
@@ -591,7 +591,7 @@ func (kb *kubernetesBackupper) BackupWithResolvers(
591591

592592
// do a final update on progress since we may have just added some CRDs and may not have updated
593593
// for the last few processed items.
594-
updated = backupRequest.Backup.DeepCopy()
594+
updated = backupRequest.DeepCopy()
595595
if updated.Status.Progress == nil {
596596
updated.Status.Progress = &velerov1api.BackupProgress{}
597597
}
@@ -668,9 +668,9 @@ func (kb *kubernetesBackupper) executeItemBlockActions(
668668
continue
669669
}
670670
// Item wasn't found in item collector list, get from cluster
671-
gvr, resource, err := itemBlock.itemBackupper.discoveryHelper.ResourceFor(relatedItem.GroupResource.WithVersion(""))
671+
gvr, resource, err := itemBlock.itemBackupper.discoveryHelper.ResourceFor(relatedItem.WithVersion(""))
672672
if err != nil {
673-
log.Error(errors.Wrapf(err, "Unable to obtain gvr and resource for related item %s %s/%s", relatedItem.GroupResource.String(), relatedItem.Namespace, relatedItem.Name))
673+
log.Error(errors.Wrapf(err, "Unable to obtain gvr and resource for related item %s %s/%s", relatedItem.String(), relatedItem.Namespace, relatedItem.Name))
674674
continue
675675
}
676676

@@ -690,7 +690,7 @@ func (kb *kubernetesBackupper) executeItemBlockActions(
690690
continue
691691
}
692692
if err != nil {
693-
log.Error(errors.Wrapf(err, "Error while trying to get related item %s %s/%s from cluster", relatedItem.GroupResource.String(), relatedItem.Namespace, relatedItem.Name))
693+
log.Error(errors.Wrapf(err, "Error while trying to get related item %s %s/%s from cluster", relatedItem.String(), relatedItem.Namespace, relatedItem.Name))
694694
continue
695695
}
696696
itemsMap[relatedItem] = append(itemsMap[relatedItem], &kubernetesResource{
@@ -1080,7 +1080,7 @@ func (kb *kubernetesBackupper) FinalizeBackup(
10801080
}).Infof("Updated %d items out of an estimated total of %d (estimate will change throughout the backup finalizer)", backedUpItems, totalItems)
10811081
}
10821082

1083-
volumeInfos, err := backupStore.GetBackupVolumeInfos(backupRequest.Backup.Name)
1083+
volumeInfos, err := backupStore.GetBackupVolumeInfos(backupRequest.Name)
10841084
if err != nil {
10851085
log.WithError(err).Errorf("fail to get the backup VolumeInfos for backup %s", backupRequest.Name)
10861086
return err

pkg/backup/item_backupper.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -432,8 +432,8 @@ func (ib *itemBackupper) executeActions(
432432
now := metav1.Now()
433433
newOperation := itemoperation.BackupOperation{
434434
Spec: itemoperation.BackupOperationSpec{
435-
BackupName: ib.backupRequest.Backup.Name,
436-
BackupUID: string(ib.backupRequest.Backup.UID),
435+
BackupName: ib.backupRequest.Name,
436+
BackupUID: string(ib.backupRequest.UID),
437437
BackupItemAction: action.Name(),
438438
ResourceIdentifier: resourceIdentifier,
439439
OperationID: operationID,
@@ -460,7 +460,7 @@ func (ib *itemBackupper) executeActions(
460460
if len(itemList) == 0 {
461461
log.Infof("Additional Item %s %s/%s not found in ItemBlock, getting from cluster", additionalItem.GroupResource, additionalItem.Namespace, additionalItem.Name)
462462

463-
gvr, resource, err := ib.discoveryHelper.ResourceFor(additionalItem.GroupResource.WithVersion(""))
463+
gvr, resource, err := ib.discoveryHelper.ResourceFor(additionalItem.WithVersion(""))
464464
if err != nil {
465465
return nil, itemFiles, err
466466
}

pkg/backup/item_collector.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ func (r *itemCollector) getResourceItems(
369369
)
370370

371371
orders := getOrderedResourcesForType(
372-
r.backupRequest.Backup.Spec.OrderedResources,
372+
r.backupRequest.Spec.OrderedResources,
373373
resource.Name,
374374
)
375375
// Getting the preferred group version of this resource
@@ -758,7 +758,7 @@ func (r *itemCollector) collectNamespaces(
758758
return nil, errors.WithStack(err)
759759
}
760760

761-
for _, includedNSName := range r.backupRequest.Backup.Spec.IncludedNamespaces {
761+
for _, includedNSName := range r.backupRequest.Spec.IncludedNamespaces {
762762
nsExists := false
763763
// Skip checking the namespace existing when it's "*".
764764
if includedNSName == "*" {
@@ -778,17 +778,17 @@ func (r *itemCollector) collectNamespaces(
778778
var singleSelector labels.Selector
779779
var orSelectors []labels.Selector
780780

781-
if r.backupRequest.Backup.Spec.LabelSelector != nil {
781+
if r.backupRequest.Spec.LabelSelector != nil {
782782
var err error
783783
singleSelector, err = metav1.LabelSelectorAsSelector(
784-
r.backupRequest.Backup.Spec.LabelSelector)
784+
r.backupRequest.Spec.LabelSelector)
785785
if err != nil {
786786
log.WithError(err).Errorf("Fail to convert backup LabelSelector %s into selector.",
787-
metav1.FormatLabelSelector(r.backupRequest.Backup.Spec.LabelSelector))
787+
metav1.FormatLabelSelector(r.backupRequest.Spec.LabelSelector))
788788
}
789789
}
790-
if r.backupRequest.Backup.Spec.OrLabelSelectors != nil {
791-
for _, ls := range r.backupRequest.Backup.Spec.OrLabelSelectors {
790+
if r.backupRequest.Spec.OrLabelSelectors != nil {
791+
for _, ls := range r.backupRequest.Spec.OrLabelSelectors {
792792
orSelector, err := metav1.LabelSelectorAsSelector(ls)
793793
if err != nil {
794794
log.WithError(err).Errorf("Fail to convert backup OrLabelSelector %s into selector.",

pkg/backup/request.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,5 +83,5 @@ func (r *Request) FillVolumesInformation() {
8383
r.VolumesInformation.NativeSnapshots = r.VolumeSnapshots
8484
r.VolumesInformation.PodVolumeBackups = r.PodVolumeBackups
8585
r.VolumesInformation.BackupOperations = *r.GetItemOperationsList()
86-
r.VolumesInformation.BackupName = r.Backup.Name
86+
r.VolumesInformation.BackupName = r.Name
8787
}

0 commit comments

Comments
 (0)